Skip to content

net/http: Client dials an IDNA-mapped host differing from url.Hostname() and Host header #80417

Description

@rolandshoemaker

When net/http.Client processes a URL with internationalized domain names (IDN) or Unicode characters, it uses different IDNA profiles for resolving the connection target and generating the Host header. This discrepancy can lead to SSRF-filter bypasses when applications rely on url.Hostname() for validation.

Specifically:

• The TCP dial target is computed using idna.Lookup.ToASCII (UTS #46 with mapping), which rewrites Unicode characters to ASCII.
• The Host header is computed using idna.ToASCII (Punycode only, no mapping).
• url.Hostname() returns the raw, unmapped Unicode host.

This allows a client to connect to an IP address (like loopback or metadata endpoint) while announcing a different Host header, bypassing guards that inspect url.Hostname() . For example, a guard that checks url.Hostname() using net.ParseIP() will not recognize fullwidth digits as an IP address, but the dialer will map them to ASCII digits and connect to the IP.

Expected Behavior

The dial target and the Host header should be consistent. Following browser behavior and the WHATWG URL standard, the Host header should contain the case-folded result of UTS #46 compatibility processing.

Actual Behavior

• The request http://127.0.0.1/ dials 127.0.0.1 .
• The sent Host header is xn--5g7caagbcfc9b .
• url.Hostname() returns 127.0.0.1 (which net.ParseIP() does not recognize as a loopback IP).

Examples

The following URLs map to loopback or metadata endpoints upon dialing:

http://127.0.0.1/ dials 127.0.0.1
http://169.254.169.254/ dials 169.254.169.254
http://169。254。169。254/ dials 169.254.169.254
http://l<U+200B>ocalhost/ dials localhost
http://ⓛⓞⓒⓐⓛⓗⓞⓢⓣ/ dials localhost

This was originally reported by Daniele Ballarini.

cc @neild

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions