runtime: IPv6 addresses not correctly formatted in Host headers
The new SocketsHttpHandler does not correctly format IPv6 addresses in host headers.
Repro:
var client = new HttpClient();
var response = await client.GetAsync("http://[::1]:5001");
Actual output:
GET / HTTP/1.1
Host: ::1:5001
Expected output: Host: [::1]:5001
Always include the brackets, even if there isn’t a port.
Code: https://github.com/dotnet/corefx/blob/f14366baaa80a893e53934b98e9786dac54c136f/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs#L124 https://github.com/dotnet/corefx/blob/f14366baaa80a893e53934b98e9786dac54c136f/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPoolManager.cs#L191-L195
Found by ASP.NET Core Kestrel functional tests. https://github.com/aspnet/KestrelHttpServer/issues/2406
Priority: Not preview blocking, but RTM blocking.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 15 (15 by maintainers)
From MSDN: https://msdn.microsoft.com/en-us/library/system.uri.dnssafehost(v=vs.110).aspx
Probably we cannot fix it in the Uri level.
Actually, that is a bug. Passing in Uri.Host will potentially pass in Unicode host names to the WinHTTP API. And that API can’t accept that. Unfortunately, we have no tests around this.
We should use Uri.IdnHost for passing into WinHTTP.
See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa384091(v=vs.85).aspx
The help for Uri class says: The RFC 3490 compliant International Domain Name of the host, using Punycode as appropriate. This string, after being unescaped if necessary, is safe to use for DNS resolution.
I think that should not include [] as they are not legal in DNS.
According to https://tools.ietf.org/html/rfc7230#section-5.4 https://tools.ietf.org/html/rfc3986#section-3.2.2
IPv6 addresses in Host header should be enclosed in square brackets.
I will fix it.