forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
url: runtime-deprecate url.parse() with invalid ports
These URLs throw with WHATWG URL. They are permitted with url.parse() but that allows potential host spoofing by sending a domain name as the port. PR-URL: nodejs#45526 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: James M Snell <[email protected]>
- Loading branch information
Showing
3 changed files
with
45 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const childProcess = require('child_process'); | ||
const url = require('url'); | ||
|
||
// https://github.com/joyent/node/issues/568 | ||
|
@@ -74,3 +75,31 @@ if (common.hasIntl) { | |
(e) => e.code === 'ERR_INVALID_URL', | ||
'parsing http://\u00AD/bad.com/'); | ||
} | ||
|
||
{ | ||
const badURLs = [ | ||
'https://evil.com:.example.com', | ||
'git+ssh://[email protected]:npm/npm', | ||
]; | ||
badURLs.forEach((badURL) => { | ||
childProcess.exec(`${process.execPath} -e "url.parse('${badURL}')"`, | ||
common.mustCall((err, stdout, stderr) => { | ||
assert.strictEqual(err, null); | ||
assert.strictEqual(stdout, ''); | ||
assert.match(stderr, /\[DEP0170\] DeprecationWarning:/); | ||
}) | ||
); | ||
}); | ||
|
||
// Warning should only happen once per process. | ||
const expectedWarning = [ | ||
`The URL ${badURLs[0]} is invalid. Future versions of Node.js will throw an error.`, | ||
'DEP0170', | ||
]; | ||
common.expectWarning({ | ||
DeprecationWarning: expectedWarning, | ||
}); | ||
badURLs.forEach((badURL) => { | ||
url.parse(badURL); | ||
}); | ||
} |