Repository navigation
Conversation
`convertIPv6BinaryToString(0n)` returned a single ":" instead of the
canonical "::" for the IPv6 unspecified address. The all-zero address
compresses every group, so the generic zero-run logic collapsed the
sections array down to a lone ":" placeholder, which the trailing
`/:{2,}/` replacement could not fix because it only collapses runs of
two or more colons.
This produced an invalid IPv6 string (`net.isIP(':')` is `0`) and broke
the round-trip with `convertIPv6ToBinary`, which throws on ":". It also
meant the unspecified address was canonicalized to a bogus key in the
ip-restriction middleware's string rule map, so a rule such as
`denyList: ['::']` could be registered under ":" rather than "::".
Handle the all-zero value explicitly, mirroring the existing
IPv4-mapped early return.
Member
|
@sarathfrancis90 Thank you! |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4998 +/- ##
=======================================
Coverage 78.98% 78.98%
=======================================
Files 154 154
Lines 10568 10570 +2
Branches 2212 2213 +1
=======================================
+ Hits 8347 8349 +2
Misses 2221 2221 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Member
|
@sarathfrancis90 Thanks! Merging. |
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.
What this fixes
convertIPv6BinaryToString(0n)returns a single":"instead of the canonical"::"for the IPv6 unspecified address (all-zero groups).The resulting string is not a valid IPv6 address (
net.isIP(':')is0) and it does not round-trip: feeding it back intoconvertIPv6ToBinarythrowsInvalid IPv6 address: :.Root cause
For the all-zero value every one of the 8 groups is
"0", so the longest zero-run spans the whole address. The compression logic replaces that run with a single":"placeholder viasections.splice(0, 8, ':'), leavingsections === [':']. Joining that with":"yields":", and the trailingvalue.replace(/:{2,}/, '::')cannot help because there is only one colon to collapse — the regex only matches runs of two or more colons.The existing IPv4-mapped case is already handled with an early return at the top of the function; the all-zero case has the same "every group compresses" property and needs the same treatment. The recently merged RFC 5952 work (#4971 for single zero groups, #4973 for expanding
::) guardsmaxZeroEnd - maxZeroStart > 1, which still routes the all-zero value through the broken 8-group splice.The fix
Add a 5-line early return for
0ninconvertIPv6BinaryToString, mirroring the existing IPv4-mapped early return:This also keeps the ip-restriction middleware's string rule map consistent: the unspecified address now canonicalizes to
"::"rather than the bogus key":", so a rule such asdenyList: ['::']is registered under the correct key.Tests
Added a focused regression test asserting
"::"output and a successful round-trip:Verified locally:
tsc --noEmit— exit 0vitest run src/utils/ipaddr.test.ts— 41 passedprettier --checkon the touched files — cleaneslinton the touched files — cleanThe author should do the following, if applicable
bun run format:fix && bun run lint:fixto format the code