Skip to content

Commit 9c268d0

Browse files
mcollinarvagg
authored andcommittedNov 27, 2018
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 <info@bnoordhuis.nl> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 618eebd commit 9c268d0

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed
 

‎lib/url.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,13 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
202202
if (slashesDenoteHost || proto || hostPattern.test(rest)) {
203203
var slashes = rest.charCodeAt(0) === 47/*/*/ &&
204204
rest.charCodeAt(1) === 47/*/*/;
205-
if (slashes && !(proto && hostlessProtocol[proto])) {
205+
if (slashes && !(proto && hostlessProtocol[lowerProto])) {
206206
rest = rest.slice(2);
207207
this.slashes = true;
208208
}
209209
}
210210

211-
if (!hostlessProtocol[proto] &&
211+
if (!hostlessProtocol[lowerProto] &&
212212
(slashes || (proto && !slashedProtocol[proto]))) {
213213

214214
// there's a hostname.

‎test/parallel/test-url.js

+33
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,39 @@ const parseTests = {
903903
hostname: 'www.example.com',
904904
pathname: '/',
905905
path: '/'
906+
},
907+
908+
// The following two URLs are the same, but they differ for
909+
// a capital A: it is important that we verify that the protocol
910+
// is checked in a case-insensitive manner.
911+
'javascript:alert(1);a=\x27@white-listed.com\x27': {
912+
protocol: 'javascript:',
913+
slashes: null,
914+
auth: null,
915+
host: null,
916+
port: null,
917+
hostname: null,
918+
hash: null,
919+
search: null,
920+
query: null,
921+
pathname: "alert(1);a='@white-listed.com'",
922+
path: "alert(1);a='@white-listed.com'",
923+
href: "javascript:alert(1);a='@white-listed.com'"
924+
},
925+
926+
'javAscript:alert(1);a=\x27@white-listed.com\x27': {
927+
protocol: 'javascript:',
928+
slashes: null,
929+
auth: null,
930+
host: null,
931+
port: null,
932+
hostname: null,
933+
hash: null,
934+
search: null,
935+
query: null,
936+
pathname: "alert(1);a='@white-listed.com'",
937+
path: "alert(1);a='@white-listed.com'",
938+
href: "javascript:alert(1);a='@white-listed.com'"
906939
}
907940
};
908941

0 commit comments

Comments
 (0)
Please sign in to comment.