Skip to content

fix: req.subdomains splitting bracketed IPv6 host with IPv4 part - #7545

Closed
princejain756 wants to merge 1 commit into
expressjs:masterfrom
princejain756:fix-subdomains-ipv6-mapped
Closed

princejain756 wants to merge 1 commit into
expressjs:masterfrom
princejain756:fix-subdomains-ipv6-mapped

Conversation

@princejain756

Copy link
Copy Markdown

Fixes #7532

req.hostname keeps the brackets on an IPv6 literal, and net.isIP returns 0 for a bracketed string, so req.subdomains treats [::ffff:127.0.0.1] as a domain and splits on the dots in the IPv4-mapped tail. The result is ['0', '[::ffff:127'] instead of [].

Bracketed hosts are now treated as IP literals and never split, matching what already happens accidentally for [::1] (no dots to split on).

Validation: added a regression test that returns ['0', '[::ffff:127'] without the fix and [] with it; npm test passes 1262 tests and eslint is clean.

req.hostname keeps the brackets on an IPv6 literal, so isIP() reports 0 and the hostname gets split on dots. That only works out for addresses without dots; an IPv4-mapped IPv6 host like [::ffff:127.0.0.1] is split into bogus subdomains.

Treat bracketed hosts as IP literals so they are never split.

Fixes expressjs#7532
@krzysdz

krzysdz commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Could you please stop creating duplicate PRs? You have already submitted #7536, which I've closed as a duplicate of #7533. You have also opened 2 other duplicate PRs (#7535, #7537) related to other issues.

Duplicate of #7533

@princejain756

Copy link
Copy Markdown
Author

You are right, sorry about that. I checked the issue for assignees but did not look for already-linked PRs before filing. I will close this one and check the PR list on the issue before filing in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

req.subdomains splits an IPv6 host that contains dots

2 participants