Repository navigation
fix: handle bracketed IPv6 hosts in req.subdomains - #7566
Closed
DipanshuAmbilkar03 wants to merge 1 commit into
Closed
DipanshuAmbilkar03 wants to merge 1 commit into
DipanshuAmbilkar03 wants to merge 1 commit into
Conversation
IPv6 literals in the Host header are bracketed (e.g. `[::ffff:127.0.0.1]`), which `node:net`'s `isIP()` does not accept. The `subdomains` getter therefore treated such hosts as domain names and split them on the dots, returning `["0", "[::ffff:127"]` instead of `[]`. Strip the brackets before the IP check while keeping the original bracketed host in the returned array, so `subdomain offset` of 0 still yields `["[::ffff:127.0.0.1]"]`. Adds regression tests for both the default and the zero offset.
Contributor
|
Duplicate of #7533 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #7532
The bug
req.subdomainsreturns["0", "[::ffff:127"]for a request whoseHostheader is[::ffff:127.0.0.1]. Withsubdomain offsetset to0it returns["1]", "0", "0", "[::ffff:127"].Root cause
req.hostnamekeeps the brackets around IPv6 literals (host[0] === '['path), butnode:net'sisIP()does not accept a bracketed address:Because the IP check failed, the getter fell through to
hostname.split('.').reverse()and split the IPv6 literal on its embedded IPv4 dots.[::1]only appeared to work by accident, since it contains no dots and was dropped byslice(offset).Fix
Strip the brackets before the
isIP()check, while keeping the original bracketed host in the returned array. This preserves the documented behaviour that an offset of0returns the whole host (["[::ffff:127.0.0.1]"]), matching the existing[::1]case.Tests
Added two regression tests in
test/req.subdomains.js:[::ffff:127.0.0.1]with the default offset returns[][::ffff:127.0.0.1]withsubdomain offsetof0returns["[::ffff:127.0.0.1]"]Both fail before the change and pass after it. Full suite:
1292 passing, ESLint clean.