Skip to content

fix(proxy): reject unsupported proxy protocols with a descriptive error - #6083

Open
petrroll wants to merge 1 commit into
nodejs:mainfrom
petrroll:fix-proxy-scheme-validation
Open

petrroll wants to merge 1 commit into
nodejs:mainfrom
petrroll:fix-proxy-scheme-validation

Conversation

@petrroll

@petrroll petrroll commented Oct 23, 2026 •

Copy link
Copy Markdown

This relates to...

Closes #6082

Rationale

ProxyAgent only special-cases socks5: and socks:. Any other scheme falls through to the HTTP proxy path, where clientFactory(url) -> new Client(url) -> parseOrigin throws:

InvalidArgumentError: Invalid URL protocol: the URL must start with `http:` or `https:`.

That message is wrong for proxy URIs (SOCKS is supported) and does not name the rejected scheme. The common trigger is socks5h:// in HTTP_PROXY/HTTPS_PROXY, which makes EnvHttpProxyAgent throw at construction.

Changes

Features

N/A

Bug Fixes

  • ProxyAgent validates the proxy protocol before building any dispatcher and throws InvalidArgumentError: Unsupported proxy protocol 'socks5h:'. Supported protocols: http:, https:, socks5:, socks:. EnvHttpProxyAgent inherits this.
  • Added test/issue-6082.js (string, URL, and { uri } inputs; clientFactory is not called; supported schemes still accepted, including uppercase input normalized by WHATWG URL; EnvHttpProxyAgent with httpProxy/httpsProxy).
  • Documented the accepted protocols for uri in docs/docs/api/ProxyAgent.md.

Breaking Changes and Deprecations

Unsupported schemes already threw at construction with the default clientFactory, so default usage only gets a better message. The one behavior change: a custom clientFactory (plus a custom factory for plain-HTTP forwarding) could previously accept an arbitrary scheme, since tunneling goes through that client. Such URIs are now rejected. I don't know of real usage of this, but flagging it in case maintainers prefer to validate only when the default factories are in use.

Status

ProxyAgent only special-cased socks5: and socks:, so any other scheme
(e.g. socks5h:, socks4:) fell through to the HTTP proxy path and failed
in parseOrigin with "the URL must start with `http:` or `https:`". That
message is misleading because SOCKS proxies are supported, and it does
not name the rejected scheme.

Validate the proxy protocol up front and report the rejected and the
supported protocols. EnvHttpProxyAgent inherits the improved error.

Closes nodejs#6082.

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.

ProxyAgent: unsupported proxy scheme (e.g. socks5h:) reports "URL must start with http: or https:" even though socks5:/socks: are supported

1 participant