| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2589fb1 commit 3bed5f1
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3302,13 +3302,17 @@ issued for `url.parse()` vulnerabilities. | |||
| 3302 | 3302 | ||
| 3303 | 3303 | <!-- YAML | |
| 3304 | 3304 | changes: | |
| 3305 | + - version: | ||
| 3306 | + - REPLACEME | ||
| 3307 | + pr-url: https://github.com/nodejs/node/pull/45526 | ||
| 3308 | + description: Runtime deprecation. | ||
| 3305 | 3309 | - version: | |
| 3306 | 3310 | - v19.2.0 | |
| 3307 | 3311 | pr-url: https://github.com/nodejs/node/pull/45576 | |
| 3308 | 3312 | description: Documentation-only deprecation. | |
| 3309 | 3313 | --> | |
| 3310 | 3314 | ||
| 3311 | - Type: Documentation-only | ||
| 3315 | + Type: Runtime | ||
| 3312 | 3316 | ||
| 3313 | 3317 | [`url.parse()`][] accepts URLs with ports that are not numbers. This behavior | |
| 3314 | 3318 | might result in host name spoofing with unexpected input. These URLs will throw | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -387,7 +387,7 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) { | |||
| 387 | 387 | ||
| 388 | 388 | // validate a little. | |
| 389 | 389 | if (!ipv6Hostname) { | |
| 390 | - rest = getHostname(this, rest, hostname); | ||
| 390 | + rest = getHostname(this, rest, hostname, url); | ||
| 391 | 391 | } | |
| 392 | 392 | ||
| 393 | 393 | if (this.hostname.length > hostnameMaxLen) { | |
@@ -506,7 +506,8 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) { | |||
| 506 | 506 | return this; | |
| 507 | 507 | }; | |
| 508 | 508 | ||
| 509 | - function getHostname(self, rest, hostname) { | ||
| 509 | + let warnInvalidPort = true; | ||
| 510 | + function getHostname(self, rest, hostname, url) { | ||
| 510 | 511 | for (let i = 0; i < hostname.length; ++i) { | |
| 511 | 512 | const code = hostname.charCodeAt(i); | |
| 512 | 513 | const isValid = (code !== CHAR_FORWARD_SLASH && | |
@@ -516,6 +517,14 @@ function getHostname(self, rest, hostname) { | |||
| 516 | 517 | code !== CHAR_COLON); | |
| 517 | 518 | ||
| 518 | 519 | if (!isValid) { | |
| 520 | + // If leftover starts with :, then it represents an invalid port. | ||
| 521 | + // But url.parse() is lenient about it for now. | ||
| 522 | + // Issue a warning and continue. | ||
| 523 | + if (warnInvalidPort && code === CHAR_COLON) { | ||
| 524 | + const detail = `The URL ${url} is invalid. Future versions of Node.js will throw an error.`; | ||
| 525 | + process.emitWarning(detail, 'DeprecationWarning', 'DEP0170'); | ||
| 526 | + warnInvalidPort = false; | ||
| 527 | + } | ||
| 519 | 528 | self.hostname = hostname.slice(0, i); | |
| 520 | 529 | return `/${hostname.slice(i)}${rest}`; | |
| 521 | 530 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,7 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | const common = require('../common'); | |
| 3 | 3 | const assert = require('assert'); | |
| 4 | + const childProcess = require('child_process'); | ||
| 4 | 5 | const url = require('url'); | |
| 5 | 6 | ||
| 6 | 7 | // https://github.com/joyent/node/issues/568 | |
@@ -74,3 +75,31 @@ if (common.hasIntl) { | |||
| 74 | 75 | (e) => e.code === 'ERR_INVALID_URL', | |
| 75 | 76 | 'parsing http://\u00AD/bad.com/'); | |
| 76 | 77 | } | |
| 78 | + | ||
| 79 | + { | ||
| 80 | + const badURLs = [ | ||
| 81 | + 'https://evil.com:.example.com', | ||
| 82 | + 'git+ssh://git@github.com:npm/npm', | ||
| 83 | + ]; | ||
| 84 | + badURLs.forEach((badURL) => { | ||
| 85 | + childProcess.exec(`${process.execPath} -e "url.parse('${badURL}')"`, | ||
| 86 | + common.mustCall((err, stdout, stderr) => { | ||
| 87 | + assert.strictEqual(err, null); | ||
| 88 | + assert.strictEqual(stdout, ''); | ||
| 89 | + assert.match(stderr, /\[DEP0170\] DeprecationWarning:/); | ||
| 90 | + }) | ||
| 91 | + ); | ||
| 92 | + }); | ||
| 93 | + | ||
| 94 | + // Warning should only happen once per process. | ||
| 95 | + const expectedWarning = [ | ||
| 96 | + `The URL ${badURLs[0]} is invalid. Future versions of Node.js will throw an error.`, | ||
| 97 | + 'DEP0170', | ||
| 98 | + ]; | ||
| 99 | + common.expectWarning({ | ||
| 100 | + DeprecationWarning: expectedWarning, | ||
| 101 | + }); | ||
| 102 | + badURLs.forEach((badURL) => { | ||
| 103 | + url.parse(badURL); | ||
| 104 | + }); | ||
| 105 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments