GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — http: redact proxy credentials in invalid proxy URL errors · nodejs/node@cd18f6b

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal
    • http.js
  • test/client-proxy
    • test-http-proxy-redact-credentials.mjs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/http.js‎

Copy file name to clipboardExpand all lines: lib/internal/http.js
+29-2Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,40 @@ function ipToInt(ip) {
107107
* @property {Array<string>} bypassList - List of hosts to bypass the proxy.
108108
* @property {object} proxyConnectionOptions - Options for connecting to the proxy server.
109109
*/
110+
111+
/**
112+
* Redacts the userinfo (username/password) from a proxy URL so that credentials
113+
* never surface in error messages, which can end up in logs and crash reports.
114+
* This must not depend on parsing succeeding: it is used precisely when the URL
115+
* failed to parse.
116+
* @param {string} proxyUrl - The proxy URL to redact.
117+
* @returns {string} The proxy URL with any userinfo removed.
118+
*/
119+
function redactProxyUrl(proxyUrl) {
120+
const raw = `${proxyUrl}`;
121+
try {
122+
const parsedURL = new URL(raw);
123+
if (parsedURL.username || parsedURL.password) {
124+
parsedURL.username = '';
125+
parsedURL.password = '';
126+
return parsedURL.href;
127+
}
128+
return raw;
129+
} catch {
130+
// Unparseable: strip the userinfo textually. Greedy up to the last '@' in the
131+
// authority so a password containing '@' is redacted whole rather than
132+
// leaving a trailing fragment.
133+
return raw.replace(/\/\/[^/]*@/, '//[redacted]@');
134+
}
135+
}
136+
110137
class ProxyConfig {
111138
constructor(proxyUrl, keepAlive, noProxyList) {
112139
let parsedUrl;
113140
try {
114141
parsedUrl = new URL(proxyUrl);
115142
} catch {
116-
throw new ERR_PROXY_INVALID_CONFIG(`Invalid proxy URL: ${proxyUrl}`);
143+
throw new ERR_PROXY_INVALID_CONFIG(`Invalid proxy URL: ${redactProxyUrl(proxyUrl)}`);
117144
}
118145
const { host, hostname, port, protocol, username, password } = parsedUrl;
119146
this.href = proxyUrl; // Full URL of the proxy server.
@@ -209,7 +236,7 @@ function parseProxyConfigFromEnv(env, protocol, keepAlive) {
209236
}
210237

211238
if (proxyUrl.includes('\r') || proxyUrl.includes('\n')) {
212-
throw new ERR_PROXY_INVALID_CONFIG(`Invalid proxy URL: ${proxyUrl}`);
239+
throw new ERR_PROXY_INVALID_CONFIG(`Invalid proxy URL: ${redactProxyUrl(proxyUrl)}`);
213240
}
214241

215242
// Only http:// and https:// proxies are supported.
Collapse file

‎test/client-proxy/test-http-proxy-redact-credentials.mjs‎

Copy file name to clipboard
+97Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// Regression test for the incomplete CVE-2026-48615 fix: proxy credentials must
2+
// never appear in ERR_PROXY_INVALID_CONFIG messages. Two error paths interpolate
3+
// the raw proxy URL (userinfo included):
4+
// 1. lib/internal/http.js - new URL() fails in the ProxyConfig constructor.
5+
// 2. lib/internal/http.js - proxy URL contains CR or LF.
6+
//
7+
// The well-formed credential control confirms redaction on the normal path is
8+
// preserved.
9+
10+
import '../common/index.mjs';
11+
import assert from 'node:assert';
12+
import { spawnSync } from 'node:child_process';
13+
14+
// A proxy credential that both contains '@' and yields substrings in every
15+
// meaningful piece that must not survive in any error message.
16+
const SECRET = 'S3cr3t-Pr0xy-P@ssw0rd';
17+
18+
function assertNoLeak(message, label) {
19+
assert.doesNotMatch(message, /S3cr3t/, `${label}: leaked username`);
20+
assert.doesNotMatch(message, /Pr0xy/, `${label}: leaked password fragment`);
21+
assert.doesNotMatch(message, /ssw0rd/, `${label}: leaked password fragment`);
22+
assert.doesNotMatch(message, /P@ssw0rd/, `${label}: leaked password`);
23+
}
24+
25+
function runNode(code, env = {}) {
26+
const res = spawnSync(process.execPath, ['-e', code], {
27+
env: { ...process.env, ...env },
28+
encoding: 'utf8',
29+
});
30+
return res;
31+
}
32+
33+
function agentWithProxyEnv(proxyEnv) {
34+
return `try {
35+
new (require('http').Agent)({ proxyEnv: ${JSON.stringify(proxyEnv)} });
36+
console.log('ok');
37+
} catch (e) {
38+
console.log(e.message);
39+
}`;
40+
}
41+
42+
// --- Site 1: ProxyConfig constructor, new URL() throws ---
43+
44+
{
45+
const { stdout, stderr } = runNode(agentWithProxyEnv({
46+
HTTP_PROXY: `http://alice:${SECRET}@::bad`,
47+
}));
48+
assertNoLeak(stdout, 'site 1');
49+
assertNoLeak(stderr, 'site 1 stderr');
50+
assert.match(stdout, /Invalid proxy URL: http:\/\/\[redacted\]@/);
51+
}
52+
53+
// --- Site 2: proxy URL containing CR or LF ---
54+
55+
{
56+
const { stdout, stderr } = runNode(agentWithProxyEnv({
57+
HTTP_PROXY: `http://alice:${SECRET}@\nhost`,
58+
}));
59+
assertNoLeak(stdout, 'site 2');
60+
assertNoLeak(stderr, 'site 2 stderr');
61+
assert.match(stdout, /Invalid proxy URL: /);
62+
}
63+
64+
// --- Sites 1 & 2 via the environment-driven, opt-in path (NODE_USE_ENV_PROXY) ---
65+
66+
{
67+
const code = `require('http').request('http://example.com/').on('error', () => {}).end()`;
68+
const { stdout, stderr, status } = runNode(code, {
69+
NODE_USE_ENV_PROXY: '1',
70+
http_proxy: `http://alice:${SECRET}@:::bad`,
71+
});
72+
// The error is thrown while the global agent is created, so stderr carries
73+
// the message and the process exits non-zero.
74+
assertNoLeak(stdout, 'env-driven stdout');
75+
assertNoLeak(stderr, 'env-driven stderr');
76+
assert.notStrictEqual(status, 0);
77+
}
78+
79+
// --- Control: well-formed URL with credentials does not throw ---
80+
81+
{
82+
const { stdout, status } = runNode(agentWithProxyEnv({
83+
HTTP_PROXY: `http://alice:${SECRET}@localhost:8080`,
84+
}));
85+
assert.strictEqual(status, 0);
86+
assert.strictEqual(stdout.trim(), 'ok');
87+
}
88+
89+
// --- Control: an unparseable URL with no credentials is left untouched ---
90+
91+
{
92+
const { stdout } = runNode(agentWithProxyEnv({
93+
HTTP_PROXY: 'http://host:port',
94+
}));
95+
assert.strictEqual(stdout.trim(), 'Invalid proxy URL: http://host:port');
96+
assert.doesNotMatch(stdout, /\[redacted\]/);
97+
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.