Skip to content

Commit 347b9f2

Browse files
moandertargos
authored andcommitted
errors: remove input from ERR_INVALID_URL message
Avoid potentially huge messages and leaked secrets. PR-URL: #38614 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Darshan Sen <[email protected]>
1 parent 3a5856c commit 347b9f2

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

lib/internal/errors.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,9 @@ E('ERR_INVALID_TUPLE', '%s must be an iterable %s tuple', TypeError);
12651265
E('ERR_INVALID_URI', 'URI malformed', URIError);
12661266
E('ERR_INVALID_URL', function(input) {
12671267
this.input = input;
1268-
return `Invalid URL: ${input}`;
1268+
// Don't include URL in message.
1269+
// (See https://github.com/nodejs/node/pull/38614)
1270+
return 'Invalid URL';
12691271
}, TypeError);
12701272
E('ERR_INVALID_URL_SCHEME',
12711273
(expected) => {

test/es-module/test-esm-loader-invalid-url.mjs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ import { expectsError, mustCall } from '../common/index.mjs';
33
import assert from 'assert';
44

55
import('../fixtures/es-modules/test-esm-ok.mjs')
6-
.then(assert.fail, expectsError({
7-
code: 'ERR_INVALID_URL',
8-
message: 'Invalid URL: ../fixtures/es-modules/test-esm-ok.mjs'
9-
}))
6+
.then(assert.fail, (error) => {
7+
expectsError({
8+
code: 'ERR_INVALID_URL',
9+
message: 'Invalid URL'
10+
})(error);
11+
12+
assert.strictEqual(error.input, '../fixtures/es-modules/test-esm-ok.mjs');
13+
})
1014
.then(mustCall());

test/parallel/test-whatwg-url-custom-parsing.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,8 @@ for (const test of failureTests) {
5555
() => new URL(test.input, test.base),
5656
(error) => {
5757
assert.throws(() => { throw error; }, expectedError);
58-
59-
// The input could be processed, so we don't do strict matching here
60-
let match;
61-
assert(match = (`${error}`).match(/Invalid URL: (.*)$/));
62-
assert.strictEqual(error.input, match[1]);
58+
assert.strictEqual(`${error}`, 'TypeError [ERR_INVALID_URL]: Invalid URL');
59+
assert.strictEqual(error.message, 'Invalid URL');
6360
return true;
6461
});
6562
}

0 commit comments

Comments
 (0)