Skip to content

Commit bd960bf

Browse files
Trottmarco-ippolito
authored andcommitted
Revert "url: improve port validation"
This reverts commit 5f7730e. This change broke too many edge cases in the ecosystem. Reverting it re-introduces some host-spoofing possibilities, so we won't want to revert forever, but the issue is long-lived enough and not sufficiently critical that we can't wait for a major release to introduce it as a breaking change. After this lands, I plan to re-introduce this as a change that throws a warning rather than an error, after which we can land a semver-major that re-introduces the error and try to get the word out to maintainers of likely-affected packages. Closes: nodejs#45514 Refs: nodejs#45012 PR-URL: nodejs#45517 Fixes: nodejs#45514 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent 9ae2a5f commit bd960bf

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

lib/url.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) {
387387

388388
// validate a little.
389389
if (!ipv6Hostname) {
390-
rest = getHostname(this, rest, hostname, url);
390+
rest = getHostname(this, rest, hostname);
391391
}
392392

393393
if (this.hostname.length > hostnameMaxLen) {
@@ -506,7 +506,7 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) {
506506
return this;
507507
};
508508

509-
function getHostname(self, rest, hostname, url) {
509+
function getHostname(self, rest, hostname) {
510510
for (let i = 0; i < hostname.length; ++i) {
511511
const code = hostname.charCodeAt(i);
512512
const isValid = (code !== CHAR_FORWARD_SLASH &&
@@ -516,10 +516,6 @@ function getHostname(self, rest, hostname, url) {
516516
code !== CHAR_COLON);
517517

518518
if (!isValid) {
519-
// If leftover starts with :, then it represents an invalid port.
520-
if (hostname.charCodeAt(i) === 58) {
521-
throw new ERR_INVALID_URL(url);
522-
}
523519
self.hostname = hostname.slice(0, i);
524520
return `/${hostname.slice(i)}${rest}`;
525521
}

test/parallel/test-url-parse-format.js

+16
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,22 @@ const parseTests = {
865865
href: 'http://a%22%20%3C\'b:b@cd/e?f'
866866
},
867867

868+
// Git urls used by npm
869+
'git+ssh://[email protected]:npm/npm': {
870+
protocol: 'git+ssh:',
871+
slashes: true,
872+
auth: 'git',
873+
host: 'github.com',
874+
port: null,
875+
hostname: 'github.com',
876+
hash: null,
877+
search: null,
878+
query: null,
879+
pathname: '/:npm/npm',
880+
path: '/:npm/npm',
881+
href: 'git+ssh://[email protected]/:npm/npm'
882+
},
883+
868884
'https://*': {
869885
protocol: 'https:',
870886
slashes: true,

test/parallel/test-url-parse-invalid-input.js

-12
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,3 @@ if (common.hasIntl) {
7474
(e) => e.code === 'ERR_INVALID_URL',
7575
'parsing http://\u00AD/bad.com/');
7676
}
77-
78-
{
79-
const badURLs = [
80-
'https://evil.com:.example.com',
81-
'git+ssh://[email protected]:npm/npm',
82-
];
83-
badURLs.forEach((badURL) => {
84-
assert.throws(() => { url.parse(badURL); },
85-
(e) => e.code === 'ERR_INVALID_URL',
86-
`parsing ${badURL}`);
87-
});
88-
}

0 commit comments

Comments
 (0)