Skip to content

Fix TLS negotiation for plain SOCKS proxies - #118

Open
gilnatab (gilnatab) wants to merge 2 commits into
microsoft:mainfrom
gilnatab:fix/plain-socks-proxy-tls
Open

Fix TLS negotiation for plain SOCKS proxies#118
gilnatab (gilnatab) wants to merge 2 commits into
microsoft:mainfrom
gilnatab:fix/plain-socks-proxy-tls

Conversation

@gilnatab

@gilnatab gilnatab (gilnatab) commented Sep 5, 2026

Copy link
Copy Markdown

With Undici 7.29.0, patched fetch can't connect through plain SOCKS5 proxies. createProxyAgent always passes proxyTls, which tells Undici to use TLS for the proxy connection. It then sends a TLS handshake where the proxy expects a SOCKS5 handshake.

This PR passes proxyTls only for HTTPS proxies. It parses the URL first, so both https:// and HTTPS:// keep the proxy's CA settings. requestTls still handles TLS to the target server.

This also breaks SOCKS5 over TLS connections that worked before. Local tests of patched fetch with @vscode/proxy-agent 0.44.0 and Undici 7.29.0 gave these results for both HTTP and HTTPS targets:

Proxy endpoint Version 0.44.0 This PR
Plain SOCKS5 Fails Works
SOCKS5 over TLS with a trusted certificate Works Fails

If anyone relies on SOCKS5 over TLS through patched fetch, their requests would stop working after this change. We don't know whether anyone currently uses this setup.

Before merging, please decide whether we need to add a library option and a VS Code setting for SOCKS5 over TLS now, or whether they can come later. This PR doesn't add them. Users would need both to turn TLS back on through VS Code settings.

The tests cover plain SOCKS5 handshakes and lowercase/uppercase HTTPS proxy URLs. The code compiles, and unit tests pass on Node 22.22.2.

Related issue: openai/codex#35924. Local tests also reproduced this connection problem.

@gilnatab
gilnatab (gilnatab) marked this pull request as ready for review September 5, 2026 09:44
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