fix(proxy): handle IPv6 literals in NO_PROXY host parsing#2976
Open
Tatlatat wants to merge 1 commit into
Open
Conversation
buildPattern stripped an optional :port with raw.lastIndexOf(":") + a
numeric-suffix check. For the IPv6 loopback "::1" the last colon is at
index 2 and the suffix "1" is numeric, so the host was truncated to "::"
and "::1" never matched NO_PROXY — IPv6 loopback got routed through the
proxy despite the comment promising IP-literal support.
Parse the host port-aware of IPv6: bracketed forms ("[::1]:8080") take the
text between [ and ]; a bare host with exactly one colon and a numeric
suffix keeps its :port stripped ("host:8080" -> "host"); anything else
(bare IPv6 like "::1" or "2001:db8::1") is left intact. Add NO_PROXY tests
for bare and bracketed IPv6 and the existing host:port case.
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
buildPatternstrips an optional:portfrom aNO_PROXYsegment withraw.lastIndexOf(":")plus a numeric-suffix check. That breaks IPv6 literals.For the loopback
::1, the last colon is at index 2 and the suffix"1"isnumeric, so the host is truncated to
"::".::1then never matchesNO_PROXYand IPv6 loopback is routed through the proxy — even though the function
comment lists "IP literals" as supported.
Fix
Parse the host port-aware of IPv6:
::1::1(was::)2001:db8::12001:db8::1[::1]:8080::1[2001:db8::1]2001:db8::1host:8080host192.168.0.1:443192.168.0.1[and].:portstripped.
Test
Added
NO_PROXYcases for bare IPv6, bracketed IPv6 with a port, and theexisting
host:portcase. Verified the IPv6 case fails on the old code andpasses on the fix (53 proxy tests pass).
Verification
npx vitest run tests/proxy.test.ts(53 passed);biome checkclean on thechanged files.