Skip to content

Commit b0c9796

Browse files
committed
fix(parse): handle CR,LF,TAB
reported by @Haxatron via huntr.dev
1 parent 88805fd commit b0c9796

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ The release notes tracked in this document are also made available on the [relea
55
### master ###
66

77
* **SECURITY** fixing [`URI.parse()`](http://medialize.github.io/URI.js/docs.html#static-parse) handle excessive slashes in scheme-relative URLs - disclosed by [zeyu2001](https://github.com/zeyu2001) via https://huntr.dev/
8+
* **SECURITY** fixing [`URI.parse()`](http://medialize.github.io/URI.js/docs.html#static-parse) remove `\r` (CR), `\n`, (LF) `\t` (TAB) - disclosed by [haxatron](https://github.com/haxatron) via https://huntr.dev/
89

910
### 1.19.10 (March 5th 2022) ###
1011

src/URI.js

+4
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@
240240
parens: /(\([^\)]*\)|\[[^\]]*\]|\{[^}]*\}|<[^>]*>)/g,
241241
};
242242
URI.leading_whitespace_expression = /^[\x00-\x20\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+/
243+
// https://infra.spec.whatwg.org/#ascii-tab-or-newline
244+
URI.ascii_tab_whitespace = /[\u0009\u000A\u000D]+/g
243245
// http://www.iana.org/assignments/uri-schemes.html
244246
// http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers#Well-known_ports
245247
URI.defaultPorts = {
@@ -497,6 +499,8 @@
497499
}
498500

499501
string = string.replace(URI.leading_whitespace_expression, '')
502+
// https://infra.spec.whatwg.org/#ascii-tab-or-newline
503+
string = string.replace(URI.ascii_tab_whitespace, '')
500504

501505
// [protocol"://"[username[":"password]"@"]hostname[":"port]"/"?][path]["?"querystring]["#"fragment]
502506

test/urls.js

+49
Original file line numberDiff line numberDiff line change
@@ -2718,6 +2718,55 @@ var urls = [{
27182718
idn: false,
27192719
punycode: false
27202720
}
2721+
}, {
2722+
name: 'ASCII tab or newline',
2723+
url: 'ja\r\nva\tscript:alert(1)',
2724+
_url: 'javascript:alert(1)',
2725+
parts: {
2726+
protocol: 'javascript',
2727+
username: null,
2728+
password: null,
2729+
hostname: null,
2730+
port: null,
2731+
path: 'alert(1)',
2732+
query: null,
2733+
fragment: null
2734+
},
2735+
accessors: {
2736+
protocol: 'javascript',
2737+
username: '',
2738+
password: '',
2739+
port: '',
2740+
path: 'alert(1)',
2741+
query: '',
2742+
fragment: '',
2743+
resource: 'alert(1)',
2744+
authority: '',
2745+
origin: '',
2746+
userinfo: '',
2747+
subdomain: '',
2748+
domain: '',
2749+
tld: '',
2750+
directory: '',
2751+
filename: '',
2752+
suffix: '',
2753+
hash: '',
2754+
search: '',
2755+
host: '',
2756+
hostname: ''
2757+
},
2758+
is: {
2759+
urn: true,
2760+
url: false,
2761+
relative: false,
2762+
name: false,
2763+
sld: false,
2764+
ip: false,
2765+
ip4: false,
2766+
ip6: false,
2767+
idn: false,
2768+
punycode: false
2769+
}
27212770
}, {
27222771
name: 'excessive colon in protocol delimiter',
27232772
url: 'http:://www.example.org:8080/hello:world',

0 commit comments

Comments
 (0)