Skip to content

fix(api): ignore SSH proxy variables in the env proxy fallback - #1163

Open
EhabY wants to merge 2 commits into
mainfrom
fix/issue-1162-ssh-proxy-env
Open

EhabY wants to merge 2 commits into
mainfrom
fix/issue-1162-ssh-proxy-env

Conversation

@EhabY

@EhabY EhabY commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

To pass the proxy to coder ssh, applySshEnvironment writes HTTP_PROXY, HTTPS_PROXY and NO_PROXY into the extension host's process.env (#1012). When http.proxy is unset, the HTTP agent falls back to proxy environment variables. So after you remove http.proxy during a session, API requests and WebSockets read those values back and keep using the old proxy until you reload.

Fix

  • pinProxyEnv(key) in src/api/proxy.ts records a variable's inherited value, and the env fallback reads that value instead of the live one. If the key is already pinned, the first pin wins.
  • applySshEnvironment pins each variable before writing it to process.env and unpins it on dispose. The SSH process still gets the proxy, and the API only sees the inherited environment.

Sync proxy.ts with proxy-from-env 2.1.0

src/api/proxy.ts started as a copy of proxy-from-env 1.x and has since diverged, so its header now says it is based on upstream. To bring it closer to upstream 2.1.0:

  • Parse URLs with the WHATWG URL API instead of the deprecated url.parse. This also removes the DEP0169 warning.
  • Stop reading npm_config_proxy, npm_config_http_proxy, npm_config_https_proxy and npm_config_no_proxy, as upstream did in 2.0. Users can set http.proxy, http.noProxy or the standard variables instead. This is noted under "Changed" in the changelog.

Testing

  • Unit tests share a clearProxyEnv helper, so they no longer depend on proxy variables set on the host.
  • A new integration test (test/integration/proxy.test.ts) runs the API requests use the SSH proxy environment after http.proxy is removed #1162 scenario in real VS Code: set http.proxy, apply the SSH environment, remove http.proxy, and check that the API agent no longer uses the proxy. It passes on VS Code 1.105.0 (Electron 37, Node 22.19) and stable 1.143.0 (Electron 43, Node 24.21), and fails on both when pinning is turned off.

Fixes #1162

🤖 Generated with Claude Code

@EhabY
EhabY marked this pull request as ready for review October 22, 2026 09:57
EhabY added 2 commits October 22, 2026 15:11
To pass the proxy to `coder ssh`, `applySshEnvironment` writes `HTTP_PROXY`,
`HTTPS_PROXY` and `NO_PROXY` into the extension host's `process.env`. When
`http.proxy` is unset, the HTTP agent falls back to proxy environment
variables, so after you removed `http.proxy` it read those values back and
kept using the old proxy until reload.

Pin each variable's inherited value before writing it, and have the env
fallback read the pinned value until the SSH environment is disposed.

Fixes #1162
Parse URLs with the WHATWG `URL` API instead of the deprecated `url.parse`,
and stop reading the `npm_config_*` proxy variables, as upstream did in 2.0.
The header now says the file is based on upstream rather than copied.

Rename `pinEnv` to `pinProxyEnv` and document that the first pin wins.

Share `clearProxyEnv` between the proxy, HTTP agent and SSH environment
tests so they no longer depend on proxy variables set on the host. Add an
integration test that removes `http.proxy` mid-session in a real VS Code.
@EhabY
EhabY force-pushed the fix/issue-1162-ssh-proxy-env branch from f5d20c3 to a4eb358 Compare October 22, 2026 12:16

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.

API requests use the SSH proxy environment after http.proxy is removed

1 participant