-
Notifications
You must be signed in to change notification settings - Fork 30.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
url: avoid hostname spoofing w/ javascript protocol
CVE-2018-12123 Fixes: nodejs-private/security#205 PR-URL: nodejs-private/node-private#145 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
- Loading branch information
Showing
2 changed files
with
57 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -890,6 +890,39 @@ const parseTests = { | |
pathname: '/*', | ||
path: '/*', | ||
href: 'https:///*' | ||
}, | ||
|
||
// The following two URLs are the same, but they differ for | ||
// a capital A: it is important that we verify that the protocol | ||
// is checked in a case-insensitive manner. | ||
'javascript:alert(1);a=\[email protected]\x27': { | ||
protocol: 'javascript:', | ||
slashes: null, | ||
auth: null, | ||
host: null, | ||
port: null, | ||
hostname: null, | ||
hash: null, | ||
search: null, | ||
query: null, | ||
pathname: "alert(1);a='@white-listed.com'", | ||
path: "alert(1);a='@white-listed.com'", | ||
href: "javascript:alert(1);a='@white-listed.com'" | ||
}, | ||
|
||
'javAscript:alert(1);a=\[email protected]\x27': { | ||
protocol: 'javascript:', | ||
slashes: null, | ||
auth: null, | ||
host: null, | ||
port: null, | ||
hostname: null, | ||
hash: null, | ||
search: null, | ||
query: null, | ||
pathname: "alert(1);a='@white-listed.com'", | ||
path: "alert(1);a='@white-listed.com'", | ||
href: "javascript:alert(1);a='@white-listed.com'" | ||
} | ||
}; | ||
|
||
|
@@ -921,3 +954,25 @@ for (const u in parseTests) { | |
assert.strictEqual(actual, expected, | ||
`format(${u}) == ${u}\nactual:${actual}`); | ||
} | ||
|
||
{ | ||
const parsed = url.parse('http://nodejs.org/') | ||
.resolveObject('jAvascript:alert(1);a=\[email protected]\x27'); | ||
|
||
const expected = Object.assign(new url.Url(), { | ||
protocol: 'javascript:', | ||
slashes: null, | ||
auth: null, | ||
host: null, | ||
port: null, | ||
hostname: null, | ||
hash: null, | ||
search: null, | ||
query: null, | ||
pathname: "alert(1);a='@white-listed.com'", | ||
path: "alert(1);a='@white-listed.com'", | ||
href: "javascript:alert(1);a='@white-listed.com'" | ||
}); | ||
|
||
assert.deepStrictEqual(parsed, expected); | ||
} |