You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
req.subdomains splits an IPv6 host that contains dots #7532
Hi! 🙂 req.subdomains splits an IPv6 host that contains dots.
Environment information
Version: express 5.3.0 (4.22.3 gives the same result)
Platform: Darwin 27.0.0
Node.js version: v24.21.0
Any other relevant information: None.
What steps will reproduce the bug?
req.subdomains does not split a host that is an IP address. This works for [::1]. An IPv6 address can also contain dots, for example the IPv4-mapped address [::ffff:127.0.0.1]. req.subdomains splits that host on the dots:
Note: fetch() rewrites the host to [::ffff:7f00:1], so it does not show the bug. curl, http.get() and X-Forwarded-Host (with trust proxy) send the host as written.
What is the expected behavior?
[] for [::ffff:127.0.0.1], the same as for [::1]. With subdomain offset set to 0, the expected value is ["[::ffff:127.0.0.1]"].
What do you see instead?
["0","[::ffff:127"]. With subdomain offset set to 0: ["1]","0","0","[::ffff:127"].
Additional information
req.hostname keeps the brackets of an IPv6 literal. req.subdomains passes that value to net.isIP() in lib/request.js, and isIP('[::ffff:127.0.0.1]') returns 0. The existing [::1] test passes only because that address has no dots.
Confirmed on current master — Host: [::ffff:127.0.0.1] makes req.subdomains return ["0","[::ffff:127"] instead of [].
Root cause:req.hostname keeps the brackets for IPv6 literals, and net.isIP() returns 0 for bracketed forms. The dotted IPv4-mapped address then goes through hostname.split('.') like a DNS name. Bare ::ffff:127.0.0.1 is fine with isIP; [::1] happens to survive because slice(offset) empties a one-segment split.
Fix in lib/request.js — strip [] before the IP check (still return the original hostname string for IP hosts):
Thanks for confirming, @hamarshehmhmd. A fix is already open in #7533. It strips the brackets before the isIP check, the same approach you describe, and adds tests for [::ffff:127.0.0.1]. It is waiting for maintainer review, so another PR should not be needed. Reviews or testing on #7533 are very welcome.
Activity
docs: link subdomains-ipv6-dotted-host to expressjs/express#7532
hamarshehmhmd commentedon Nov 7, 2026
Confirmed on current master —
Host: [::ffff:127.0.0.1]makesreq.subdomainsreturn["0","[::ffff:127"]instead of[].Root cause:
req.hostnamekeeps the brackets for IPv6 literals, andnet.isIP()returns0for bracketed forms. The dotted IPv4-mapped address then goes throughhostname.split('.')like a DNS name. Bare::ffff:127.0.0.1is fine withisIP;[::1]happens to survive becauseslice(offset)empties a one-segment split.Fix in
lib/request.js— strip[]before the IP check (still return the original hostname string for IP hosts):Verified (Node 20, mocha):
should work with IPv4-mapped IPv6 addressexpecting[]for[::ffff:127.0.0.1][::1]/ DNS cases unchangednpx mocha --exit test/req.subdomains.js→ 12 passingHappy to open a PR.
johnnyhuirilef commentedon Nov 11, 2026
Thanks for confirming, @hamarshehmhmd. A fix is already open in #7533. It strips the brackets before the
isIPcheck, the same approach you describe, and adds tests for[::ffff:127.0.0.1]. It is waiting for maintainer review, so another PR should not be needed. Reviews or testing on #7533 are very welcome.