Skip to content

fix(env-http-proxy-agent): assume http for schema-less proxy env vars#4860

Open
nthbotast wants to merge 2 commits intonodejs:mainfrom
nthbotast:fix-4736-schemaless-proxy
Open

fix(env-http-proxy-agent): assume http for schema-less proxy env vars#4860
nthbotast wants to merge 2 commits intonodejs:mainfrom
nthbotast:fix-4736-schemaless-proxy

Conversation

@nthbotast
Copy link
Contributor

Summary

  • assume an http:// scheme when HTTP_PROXY / HTTPS_PROXY values are provided without a URL scheme
  • keep existing behavior unchanged for already well-formed proxy URLs
  • add coverage for schema-less proxy environment variables in EnvHttpProxyAgent tests

Testing

  • node --test test/env-http-proxy-agent.js

Closes #4736

const HTTPS_PROXY = httpsProxy ?? process.env.https_proxy ?? process.env.HTTPS_PROXY
if (HTTPS_PROXY) {
this[kHttpsProxyAgent] = new ProxyAgent({ ...agentOpts, uri: HTTPS_PROXY })
this[kHttpsProxyAgent] = new ProxyAgent({ ...agentOpts, uri: normalizeProxyURI(HTTPS_PROXY) })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the rationale of normalizing https to http?
unless tunneling, that can cause connect rejection from proxy.

@nthbotast
Copy link
Contributor Author

Good question. The intent here is only to handle scheme-less values (e.g. localhost:8080) that currently throw on URL parsing. We are not rewriting explicit https://... proxies.

I defaulted to http:// because for HTTP_PROXY/HTTPS_PROXY, the variable name usually indicates the target traffic, while the proxy transport is commonly plain HTTP (CONNECT for TLS upstream), and this is what many existing env setups rely on.

That said, I agree ambiguity exists for scheme-less HTTPS_PROXY. If you prefer, I can change this to default HTTPS_PROXY to https:// (or split behavior by variable) and update tests accordingly.

@metcoder95
Copy link
Member

Let's do that.

I can see a bit of ambiguity if I try to set a schema less origin proxy.example that I know only accepts TLS traffic and starts attempting plain text connection.
On top, it seems is what also curl does.

@nthbotast
Copy link
Contributor Author

Done 👍\n\nI pushed commit d023525 to apply the requested split behavior:\n- schemaless => \n- schemaless => \n\nI also updated the corresponding env-proxy test expectation to match.\n\nI couldn't run in this ephemeral checkout because test deps are not installed yet ( missing).

@nthbotast
Copy link
Contributor Author

Follow-up (my previous comment was mangled by shell escaping):

I pushed commit d023525 to apply the requested split behavior:

  • schemaless HTTP_PROXY => http://...
  • schemaless HTTPS_PROXY => https://...

I also updated the matching env-proxy test expectation.

I couldn't run node --test test/env-http-proxy-agent.js in this ephemeral checkout because test deps are not installed yet (@matteo.collina/tspl missing).

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.14%. Comparing base (f734c87) to head (d023525).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4860   +/-   ##
=======================================
  Coverage   93.13%   93.14%           
=======================================
  Files         109      109           
  Lines       34243    34258   +15     
=======================================
+ Hits        31893    31909   +16     
+ Misses       2350     2349    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

Schema-less HTTP_PROXY and HTTPS_PROXY env vars should maybe assume http

3 participants