Skip to content

fix(tools): make js_execution fetch honor proxy env vars (#3273) - #3577

Merged
Hmbown merged 1 commit into
Hmbown:mainfrom
LeoLin990405:fix/issue-3273-js-execution-env-proxy
Jun 25, 2026
Merged

Hmbown merged 1 commit into
Hmbown:mainfrom
LeoLin990405:fix/issue-3273-js-execution-env-proxy

Conversation

@LeoLin990405

Copy link
Copy Markdown
Contributor

Problem

Fixes #3273 — on a host with a local proxy/VPN, js_execution can't reach the network even though CodeWhale config and the shell both have HTTP_PROXY/HTTPS_PROXY set. fetch() times out with an Undici connect error, while the shell tools reach the same URL fine.

Root cause

Node's built-in fetch (undici) ignores HTTP_PROXY/HTTPS_PROXY environment variables by default. It only honors them when NODE_USE_ENV_PROXY is set (equivalent to --use-env-proxy, Node ≥ 24). js_execution spawns node script.js inheriting CodeWhale's environment — so the proxy variables are present in the child, but Node's fetch never consults them.

Verified locally (Node 26):

# proxy env honored only with the flag → connection goes to the (dead) proxy port
$ HTTPS_PROXY=http://127.0.0.1:9 NODE_USE_ENV_PROXY=1 node -e "fetch('https://example.com').catch(e=>console.log(e.cause.code, e.cause.port))"
ECONNREFUSED 9
# without it → fetch ignores the proxy and connects directly
$ HTTPS_PROXY=http://127.0.0.1:9 node -e "fetch('https://example.com').then(r=>console.log(r.status))"
200

Fix

Default NODE_USE_ENV_PROXY=1 on the js_execution Node child so its fetch() uses the same HTTP(S)_PROXY (and honors NO_PROXY) as the rest of CodeWhale. Only defaulted when the variable is unset, so an explicit NODE_USE_ENV_PROXY=0 opt-out still wins. It's a no-op on Node < 24 (the variable is simply ignored), so it's safe across versions — the proper fix for the reporter's Node 22 would be upgrading to Node ≥ 24, but this removes the CodeWhale-side gap for every Node that supports it.

Testing

  • New test execute_js_enables_env_proxy_so_fetch_honors_proxy_vars spawns the Node child and asserts it sees NODE_USE_ENV_PROXY=1 (skipped when Node is absent or the caller already set the variable).
  • cargo clippy -p codewhale-tui --all-features clean; cargo test -p codewhale-tui --all-features js_execution green.

Node's built-in fetch (undici) ignores HTTP_PROXY/HTTPS_PROXY env vars
unless NODE_USE_ENV_PROXY is set (Node >= 24), so js_execution could not
reach the network through a local proxy/VPN even though CodeWhale and the
shell had the proxy variables set — fetch() timed out with an Undici
connect error.

The js_execution child already inherits CodeWhale's environment, so
default NODE_USE_ENV_PROXY=1 to switch Node's built-in proxy handling on;
this makes fetch() use the same HTTP(S)_PROXY and honor NO_PROXY as the
rest of the app. Only defaulted when unset so an explicit
NODE_USE_ENV_PROXY=0 opt-out still wins; no-op on Node < 24.
@LeoLin990405
LeoLin990405 requested a review from Hmbown as a code owner June 25, 2026 07:38
@github-actions

Copy link
Copy Markdown
Contributor

Thanks @LeoLin990405 for taking the time to contribute.

This repository is observing a maintainer-managed PR intake gate in dry-run mode, so this pull request is staying open. This note helps maintainers prepare the allowlist before any enforcement is considered.

Please read CONTRIBUTING.md for the expected contribution shape. A maintainer can grant recurring PR access by commenting /lgtm on a pull request.

@Hmbown
Hmbown merged commit 173d0bf into Hmbown:main Jun 25, 2026
12 checks passed
@Hmbown

Hmbown commented Jun 25, 2026

Copy link
Copy Markdown
Owner

Problem

Fixes #3273 — on a host with a local proxy/VPN, js_execution can't reach the network even though CodeWhale config and the shell both have HTTP_PROXY/HTTPS_PROXY set. fetch() times out with an Undici connect error, while the shell tools reach the same URL fine.

Root cause

Node's built-in fetch (undici) ignores HTTP_PROXY/HTTPS_PROXY environment variables by default. It only honors them when NODE_USE_ENV_PROXY is set (equivalent to --use-env-proxy, Node ≥ 24). js_execution spawns node script.js inheriting CodeWhale's environment — so the proxy variables are present in the child, but Node's fetch never consults them.

Verified locally (Node 26):

# proxy env honored only with the flag → connection goes to the (dead) proxy port
$ HTTPS_PROXY=http://127.0.0.1:9 NODE_USE_ENV_PROXY=1 node -e "fetch('https://example.com').catch(e=>console.log(e.cause.code, e.cause.port))"
ECONNREFUSED 9
# without it → fetch ignores the proxy and connects directly
$ HTTPS_PROXY=http://127.0.0.1:9 node -e "fetch('https://example.com').then(r=>console.log(r.status))"
200

Fix

Default NODE_USE_ENV_PROXY=1 on the js_execution Node child so its fetch() uses the same HTTP(S)_PROXY (and honors NO_PROXY) as the rest of CodeWhale. Only defaulted when the variable is unset, so an explicit NODE_USE_ENV_PROXY=0 opt-out still wins. It's a no-op on Node < 24 (the variable is simply ignored), so it's safe across versions — the proper fix for the reporter's Node 22 would be upgrading to Node ≥ 24, but this removes the CodeWhale-side gap for every Node that supports it.

Testing

  • New test execute_js_enables_env_proxy_so_fetch_honors_proxy_vars spawns the Node child and asserts it sees NODE_USE_ENV_PROXY=1 (skipped when Node is absent or the caller already set the variable).
  • cargo clippy -p codewhale-tui --all-features clean; cargo test -p codewhale-tui --all-features js_execution green.

This is awesome - thank you so much. I'm working on adding Tailscale comparability so things like this are increasing in value for the project in real time!!

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.

js_execution Node fetch does not honor proxy config/env on Windows

2 participants