Add failing test for npm installer authenticated proxy bug#2330
Add failing test for npm installer authenticated proxy bug#2330tnkuehne wants to merge 2 commits intoaxodotdev:mainfrom
Conversation
|
It also appears axios itself has builtin |
Actually, I hadn't thought of this in the first place but I tested it now and removing axios-proxy-builder and letting axios handle proxies natively does fix the auth issue. But axios sends HTTPS requests as plain HTTP through the proxy instead of using CONNECT tunneling. Some proxies reject that and require proper CONNECT for HTTPS (see axios/axios#5256). So we'd fix authenticated proxies but break strict CONNECT-only proxies. The undici approach handles both correctly. |
|
See #2350, I'm proposing |
yes perfect, thats actually the cleanest approach! Thanks |
Context
We use
@j178/prek, a Rust CLI distributed via npm through cargo-dist. The generated npm installer usesaxios+axios-proxy-builderto download binaries. We discovered that authenticated proxies don't work. When a proxy (e.g. Claude Code web sandbox) requires credentials in the URL (HTTPS_PROXY=http://user:pass@proxy:8080),axios-proxy-buildersilently drops them. It only passeshostandporttotunnel.httpsOverHttp(), ignoringproxyAuthentirely.We patched it locally:
Patching this in every project isn't sustainable.
axios-proxy-builderhasn't received an update in years, so fixing it upstream isn't realistic either. This is why I am here.What this PR does
Adds a failing regression test (
npm_installer_sends_proxy_auth) that demonstrates the bug. The test:HTTPS_PROXYwith credentialsbinary.js->install()-> HTTP request)Proxy-AuthorizationheaderThe test fails because
axios-proxy-builderdrops the credentials from the CONNECT request.Suggested fix
Replace
axios+axios-proxy-builderwith nativefetch()andundici'sEnvHttpProxyAgent, which handles authenticated proxies,NO_PROXY, and all standard proxy env vars correctly out of the box. This requires bumping the node engine minimum from>=14to>=18(for nativefetch()andReadable.fromWeb()), but Node 14 has been EOL since April 2023, so that should be safe.For reference, Node.js v22.21.0+ added native proxy support for
fetch()via--use-env-proxy/NODE_USE_ENV_PROXY, which would eliminate theundicidependency entirely. However, that requires Node 22.21+ and the end user has to opt in themselves. We can't set it from within the installer.undici'sEnvHttpProxyAgentworks on Node 18+ with no user configuration required.I have a working implementation on this branch. Happy to open a follow-up PR if this direction sounds good.