Skip to content

fix(socks5): handle bracketed IPv6 literals for proxy and target hosts - #6243

Open
hoanle0126 wants to merge 1 commit into
nodejs:mainfrom
hoanle0126:fix/socks5-ipv6-bracketed-hosts
Open

hoanle0126 wants to merge 1 commit into
nodejs:mainfrom
hoanle0126:fix/socks5-ipv6-bracketed-hosts

Conversation

@hoanle0126

Copy link
Copy Markdown

This relates to...

N/A

Rationale

URL.prototype.hostname returns IPv6 literals wrapped in square brackets (such as [::1]). Socks5ProxyAgent forwarded those bracketed strings directly to the proxy connector and to SOCKS5 CONNECT, and parseAddress checked net.isIPv6 without stripping the brackets. Connecting to an IPv6 SOCKS5 proxy failed with ENOTFOUND, and IPv6 target origins were encoded as domain names (ATYP 0x03) instead of 16-byte IPv6 addresses (ATYP 0x04) per RFC 1928.

Changes

Strip surrounding brackets from valid IPv6 literals in socks5-utils (parseAddress and parseIPv6) and normalize proxy and target hostnames in Socks5ProxyAgent before connecting or sending the SOCKS5 CONNECT request. Use getServerName for the default proxy TLS servername so IP-literal proxy URLs do not pass an IP or bracketed host as SNI.

Features

N/A

Bug Fixes

  • Support bracketed IPv6 proxy and target hosts in Socks5ProxyAgent and socks5-utils, encoding IPv6 target addresses with ATYP 0x04 per RFC 1928.

Breaking Changes and Deprecations

N/A

Status

Signed-off-by: Nacy Dev <hoanle0126@gmail.com>

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgym

@codecov-commenter

codecov-commenter commented Nov 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.77%. Comparing base (5d7f657) to head (1acbf20).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6243      +/-   ##
==========================================
+ Coverage   91.74%   91.77%   +0.03%     
==========================================
  Files         113      113              
  Lines       44849    44873      +24     
==========================================
+ Hits        41147    41184      +37     
+ Misses       3702     3689      -13     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants