From bb97ccec077b606df5198887446e62a4e9137677 Mon Sep 17 00:00:00 2001 From: Nathanael BOT Date: Wed, 4 Mar 2026 14:01:45 +0100 Subject: [PATCH 1/2] fix(env-http-proxy-agent): assume http for schema-less proxy vars --- lib/dispatcher/env-http-proxy-agent.js | 8 ++++++-- test/env-http-proxy-agent.js | 10 ++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/dispatcher/env-http-proxy-agent.js b/lib/dispatcher/env-http-proxy-agent.js index f88437f1936..0afb8e2ab19 100644 --- a/lib/dispatcher/env-http-proxy-agent.js +++ b/lib/dispatcher/env-http-proxy-agent.js @@ -10,6 +10,10 @@ const DEFAULT_PORTS = { 'https:': 443 } +function normalizeProxyURI (proxy) { + return /^[a-zA-Z][a-zA-Z\d+.-]*:\/\//.test(proxy) ? proxy : `http://${proxy}` +} + class EnvHttpProxyAgent extends DispatcherBase { #noProxyValue = null #noProxyEntries = null @@ -25,14 +29,14 @@ class EnvHttpProxyAgent extends DispatcherBase { const HTTP_PROXY = httpProxy ?? process.env.http_proxy ?? process.env.HTTP_PROXY if (HTTP_PROXY) { - this[kHttpProxyAgent] = new ProxyAgent({ ...agentOpts, uri: HTTP_PROXY }) + this[kHttpProxyAgent] = new ProxyAgent({ ...agentOpts, uri: normalizeProxyURI(HTTP_PROXY) }) } else { this[kHttpProxyAgent] = this[kNoProxyAgent] } 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) }) } else { this[kHttpsProxyAgent] = this[kHttpProxyAgent] } diff --git a/test/env-http-proxy-agent.js b/test/env-http-proxy-agent.js index 97969cfaf20..61e1c1103dc 100644 --- a/test/env-http-proxy-agent.js +++ b/test/env-http-proxy-agent.js @@ -53,6 +53,16 @@ test('creates separate proxy agent for http and https when http_proxy and https_ return dispatcher.close() }) +test('assumes http scheme for schema-less proxy env vars', async (t) => { + t = tspl(t, { plan: 2 }) + process.env.http_proxy = 'localhost:8080' + process.env.https_proxy = 'localhost:8443' + const dispatcher = new EnvHttpProxyAgent() + t.equal(dispatcher[kHttpProxyAgent][kProxy].uri, 'http://localhost:8080/') + t.equal(dispatcher[kHttpsProxyAgent][kProxy].uri, 'http://localhost:8443/') + return dispatcher.close() +}) + test('handles uppercase HTTP_PROXY and HTTPS_PROXY', async (t) => { t = tspl(t, { plan: 6 }) process.env.HTTP_PROXY = 'http://example.com:8080' From d02352591a06dcdc304d0dcb8aeeffb1d015c2e6 Mon Sep 17 00:00:00 2001 From: Nathanael BOT Date: Thu, 5 Mar 2026 11:18:26 +0100 Subject: [PATCH 2/2] fix(env-http-proxy-agent): default schemaless HTTPS_PROXY to https --- lib/dispatcher/env-http-proxy-agent.js | 8 ++++---- test/env-http-proxy-agent.js | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/dispatcher/env-http-proxy-agent.js b/lib/dispatcher/env-http-proxy-agent.js index 0afb8e2ab19..9a602f465d4 100644 --- a/lib/dispatcher/env-http-proxy-agent.js +++ b/lib/dispatcher/env-http-proxy-agent.js @@ -10,8 +10,8 @@ const DEFAULT_PORTS = { 'https:': 443 } -function normalizeProxyURI (proxy) { - return /^[a-zA-Z][a-zA-Z\d+.-]*:\/\//.test(proxy) ? proxy : `http://${proxy}` +function normalizeProxyURI (proxy, defaultScheme = 'http://') { + return /^[a-zA-Z][a-zA-Z\d+.-]*:\/\//.test(proxy) ? proxy : `${defaultScheme}${proxy}` } class EnvHttpProxyAgent extends DispatcherBase { @@ -29,14 +29,14 @@ class EnvHttpProxyAgent extends DispatcherBase { const HTTP_PROXY = httpProxy ?? process.env.http_proxy ?? process.env.HTTP_PROXY if (HTTP_PROXY) { - this[kHttpProxyAgent] = new ProxyAgent({ ...agentOpts, uri: normalizeProxyURI(HTTP_PROXY) }) + this[kHttpProxyAgent] = new ProxyAgent({ ...agentOpts, uri: normalizeProxyURI(HTTP_PROXY, 'http://') }) } else { this[kHttpProxyAgent] = this[kNoProxyAgent] } const HTTPS_PROXY = httpsProxy ?? process.env.https_proxy ?? process.env.HTTPS_PROXY if (HTTPS_PROXY) { - this[kHttpsProxyAgent] = new ProxyAgent({ ...agentOpts, uri: normalizeProxyURI(HTTPS_PROXY) }) + this[kHttpsProxyAgent] = new ProxyAgent({ ...agentOpts, uri: normalizeProxyURI(HTTPS_PROXY, 'https://') }) } else { this[kHttpsProxyAgent] = this[kHttpProxyAgent] } diff --git a/test/env-http-proxy-agent.js b/test/env-http-proxy-agent.js index 61e1c1103dc..483a5eec886 100644 --- a/test/env-http-proxy-agent.js +++ b/test/env-http-proxy-agent.js @@ -53,13 +53,13 @@ test('creates separate proxy agent for http and https when http_proxy and https_ return dispatcher.close() }) -test('assumes http scheme for schema-less proxy env vars', async (t) => { +test('assumes protocol-specific scheme for schema-less proxy env vars', async (t) => { t = tspl(t, { plan: 2 }) process.env.http_proxy = 'localhost:8080' process.env.https_proxy = 'localhost:8443' const dispatcher = new EnvHttpProxyAgent() t.equal(dispatcher[kHttpProxyAgent][kProxy].uri, 'http://localhost:8080/') - t.equal(dispatcher[kHttpsProxyAgent][kProxy].uri, 'http://localhost:8443/') + t.equal(dispatcher[kHttpsProxyAgent][kProxy].uri, 'https://localhost:8443/') return dispatcher.close() })