Skip to content

feat(proxy): accept socks5h: proxy URLs - #6085

Open
petrroll wants to merge 2 commits into
nodejs:mainfrom
petrroll:feat-socks5h-proxy
Open

petrroll wants to merge 2 commits into
nodejs:mainfrom
petrroll:feat-socks5h-proxy

Conversation

@petrroll

@petrroll petrroll commented Oct 23, 2026 •

Copy link
Copy Markdown

This relates to...

Refs #6082. Optional follow-up to #6083 (independent of it, can be merged on its own or not at all).

Rationale

socks5h:// is the conventional scheme for a SOCKS5 proxy that resolves target host names (curl, socks-proxy-agent, most proxy tooling). Users commonly have it in HTTP_PROXY/HTTPS_PROXY/ALL_PROXY, and ProxyAgent/EnvHttpProxyAgent/Socks5ProxyAgent currently reject it.

Undici already implements socks5h semantics for every SOCKS URL: target host names are never resolved locally. parseAddress in lib/core/socks5-utils.js sends IP literals as ATYP 0x01/0x04 and everything else as ATYP 0x03 (domain name), so the proxy does the DNS lookup. socks5: and socks: therefore already behave like socks5h:, and accepting socks5h: as an alias changes nothing on the wire.

Changes

Features

  • Accept socks5h: proxy URLs in ProxyAgent, EnvHttpProxyAgent (via ProxyAgent) and Socks5ProxyAgent.
  • Centralize the SOCKS scheme check in an internal isSocks5Protocol() helper in lib/core/socks5-utils.js, with a comment explaining that all three schemes behave like socks5h:.
  • Docs for ProxyAgent and Socks5ProxyAgent list socks5h: and state that host names are always resolved by the proxy.
  • Tests: Socks5ProxyAgent constructor accepts socks5h://; end-to-end requests through Socks5ProxyAgent, ProxyAgent and EnvHttpProxyAgent with a socks5h:// proxy, asserting the proxy receives the target as a domain name (localhost).

Bug Fixes

N/A

Breaking Changes and Deprecations

None.

If #6083 lands first, socks5h: also needs adding to its supportedProxyProtocols list; I will rebase this PR accordingly.

Status

@metcoder95

Copy link
Copy Markdown
Member

can you solve the conflicts?

socks5h: is the conventional scheme for a SOCKS5 proxy that resolves
target host names (curl, socks-proxy-agent). It is common in
HTTP_PROXY/HTTPS_PROXY/ALL_PROXY, but ProxyAgent, EnvHttpProxyAgent and
Socks5ProxyAgent rejected it.

Undici never resolves target host names locally: they are always sent
to the proxy as domain names (ATYP 0x03). So socks5: and socks: already
have socks5h: semantics, and socks5h: can be accepted as an alias with
no behavior difference.

Refs nodejs#6082.
@petrroll

petrroll commented Dec 1, 2026

Copy link
Copy Markdown
Author

@metcoder95 rebased

@mcollina
mcollina requested a balanced review from Copilot December 1, 2026 21:20

@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.

Lgtm

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new test can fail when NO_PROXY includes localhost because its dispatcher does not explicitly set noProxy: '', allowing the request to bypass the SOCKS proxy and leave targets empty.

1 open issue
What changed in this PR

Adds socks5h: as an alias for Undici’s existing SOCKS5 proxy support, preserving its current proxy-side hostname resolution behavior.

Changes:

  • Centralizes SOCKS protocol checks and accepts socks5h: across all three proxy agents.
  • Documents the alias and hostname-resolution behavior.
  • Adds constructor and end-to-end tests that verify hostnames reach the SOCKS proxy.
File Description
test/​socks5-proxy-agent.js Tests alias acceptance and hostname forwarding across three agents.
lib/​dispatcher/​socks5-proxy-agent.js Accepts the alias and updates the validation error.
lib/​dispatcher/​proxy-agent.js Uses the shared helper to select SOCKS handling.
lib/​core/​socks5-utils.js Adds the shared protocol helper and explains resolution semantics.
docs/​docs/​api/​Socks5ProxyAgent.md Documents accepted schemes and proxy-side hostname resolution.
docs/​docs/​api/​ProxyAgent.md Lists socks5h: among supported SOCKS schemes.

Review effort: Balanced

Comment thread test/socks5-proxy-agent.js Resolved
@codecov-commenter

codecov-commenter commented Dec 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.81%. Comparing base (e626fdd) to head (d8fbd08).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6085   +/-   ##
=======================================
  Coverage   91.80%   91.81%           
=======================================
  Files         113      113           
  Lines       44961    44978   +17     
=======================================
+ Hits        41278    41295   +17     
  Misses       3683     3683           

☔ 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.

Update EnvHttpProxyAgent instantiation to include noProxy option.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@petrroll

petrroll commented Dec 1, 2026

Copy link
Copy Markdown
Author

@mcollina applies copilot suggestion for test stability

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.

5 participants