Skip to content

fix(socks5): do not send an IP address as the TLS servername - #6160

Open
b84330808 wants to merge 1 commit into
nodejs:mainfrom
b84330808:fix/socks5-ip-servername
Open

b84330808 wants to merge 1 commit into
nodejs:mainfrom
b84330808:fix/socks5-ip-servername

Conversation

@b84330808

Copy link
Copy Markdown

This relates to...

#6144 (the SOCKS5 part; the ProxyAgent part is covered by #6148)

Rationale

Node.js 25 moved DEP0123 to end-of-life, so tls.connect() throws ERR_INVALID_ARG_VALUE when the servername is an IP address. Socks5ProxyAgent passes the target host as the servername when it upgrades the tunnel to TLS, so every request to an https://<ip>/ target through a SOCKS5 proxy fails there. On Node.js 24 it only warned, and sent the IP as SNI.

Changes

In lib/dispatcher/socks5-proxy-agent.js, the TLS upgrade now drops the servername when it is an IP literal (whether it came from the target host or from the request TLS options), and passes host: targetHost so the certificate is checked against the target and not against the proxy socket's host. Passing no host would make Node verify against the proxy's host instead. IPv6 targets are unaffected because the address is already bracket/colon handled upstream and net.isIP covers both families.

Two tests are added to test/socks5-proxy-agent.js: an HTTPS target addressed by IPv4 completes the request and sends no SNI, and a hostname target still sends SNI as before.

Features

N/A

Bug Fixes

  • Socks5ProxyAgent requests to https://<ip>/ targets throwing ERR_INVALID_ARG_VALUE on Node.js 25+

Breaking Changes and Deprecations

None

Status

I ran test/socks5-proxy-agent.js myself on Linux with Node v24.22.1: with the old code the new no-SNI test fails (1 failure), with this change the file passes (22 pass, 1 skipped).

Node.js 25 moved DEP0123 to end-of-life, so tls.connect() throws
ERR_INVALID_ARG_VALUE when servername is an IP address. Socks5ProxyAgent
uses the target host as servername when it upgrades the tunnel to TLS, so
every request to an https://<ip>/ target through a SOCKS5 proxy fails.
Node.js 24 only warned and sent the IP as SNI.

Drop a servername that is an IP literal, and pass host: targetHost so the
certificate is checked against the target and not against the SOCKS5
proxy socket's host.

Signed-off-by: Wei-Lun Li <b84330808@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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.

1 participant