Skip to content

Commit 17a379e

Browse files
committed
url: Escape all unwise characters
This makes node's http URL handling logic identical to Chrome's Re nodejs#5284
1 parent 061151c commit 17a379e

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lib/url.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,12 @@ var protocolPattern = /^([a-z0-9.+-]+:)/i,
5757
unwise = ['{', '}', '|', '\\', '^', '~', '`'].concat(delims),
5858

5959
// Allowed by RFCs, but cause of XSS attacks. Always escape these.
60-
autoEscape = ['\''].concat(delims),
60+
autoEscape = ['\''].concat(unwise),
6161
// Characters that are never ever allowed in a hostname.
6262
// Note that any invalid chars are also handled, but these
6363
// are the ones that are *expected* to be seen, so we fast-path
6464
// them.
65-
nonHostChars = ['%', '/', '?', ';', '#']
66-
.concat(unwise).concat(autoEscape),
65+
nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape),
6766
nonAuthChars = ['/', '@', '?', '#'].concat(delims),
6867
hostnameMaxLen = 255,
6968
hostnamePartPattern = /^[a-z0-9A-Z_-]{0,63}$/,

test/simple/test-url.js

+11
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,17 @@ var parseTests = {
741741
'path': '/test',
742742
},
743743

744+
'http://x:1/\' <>"`/{}|\\^~`/': {
745+
protocol: 'http:',
746+
slashes: true,
747+
host: 'x:1',
748+
port: '1',
749+
hostname: 'x',
750+
pathname: '/%27%20%3C%3E%22%60/%7B%7D%7C%5C%5E%7E%60/',
751+
path: '/%27%20%3C%3E%22%60/%7B%7D%7C%5C%5E%7E%60/',
752+
href: 'http://x:1/%27%20%3C%3E%22%60/%7B%7D%7C%5C%5E%7E%60/'
753+
},
754+
744755
};
745756

746757
for (var u in parseTests) {

0 commit comments

Comments
 (0)