Skip to content

Commit 88805fd

Browse files
committed
fix(parse): handle excessive slashes in scheme-relative URLs
reported by @zeyu2001 via huntr.dev
1 parent 926b2aa commit 88805fd

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
The release notes tracked in this document are also made available on the [releases page](https://github.com/medialize/URI.js/releases)
44

5+
### master ###
6+
7+
* **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+
59
### 1.19.10 (March 5th 2022) ###
610

711
* **SECURITY** fixing [`URI.parse()`](http://medialize.github.io/URI.js/docs.html#static-parse) handle excessive colons in protocol delimiter - disclosed by [huydoppa](https://github.com/huydoppa) via https://huntr.dev/

src/URI.js

+2
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,8 @@
518518

519519
// slashes and backslashes have lost all meaning for the web protocols (https, http, wss, ws)
520520
string = string.replace(/^(https?|ftp|wss?)?:+[/\\]*/i, '$1://');
521+
// slashes and backslashes have lost all meaning for scheme relative URLs
522+
string = string.replace(/^[/\\]{2,}/i, '//');
521523

522524
// extract protocol
523525
if (string.substring(0, 2) === '//') {

test/urls.js

+98
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,55 @@ var urls = [{
581581
idn: false,
582582
punycode: false
583583
}
584+
}, {
585+
name: 'ignoring scheme excessive slashes',
586+
url: ':/\\//user:[email protected]:123/some/directory/file.html?query=string#fragment',
587+
_url: '//user:[email protected]:123/some/directory/file.html?query=string#fragment',
588+
parts: {
589+
protocol: null,
590+
username: 'user',
591+
password: 'pass',
592+
hostname: 'example.org',
593+
port: '123',
594+
path: '/some/directory/file.html',
595+
query: 'query=string',
596+
fragment: 'fragment'
597+
},
598+
accessors: {
599+
protocol: '',
600+
username: 'user',
601+
password: 'pass',
602+
port: '123',
603+
path: '/some/directory/file.html',
604+
query: 'query=string',
605+
fragment: 'fragment',
606+
resource: '/some/directory/file.html?query=string#fragment',
607+
authority: 'user:[email protected]:123',
608+
origin: 'user:[email protected]:123',
609+
userinfo: 'user:pass',
610+
subdomain: '',
611+
domain: 'example.org',
612+
tld: 'org',
613+
directory: '/some/directory',
614+
filename: 'file.html',
615+
suffix: 'html',
616+
hash: '#fragment',
617+
search: '?query=string',
618+
host: 'example.org:123',
619+
hostname: 'example.org'
620+
},
621+
is: {
622+
urn: false,
623+
url: true,
624+
relative: false,
625+
name: true,
626+
sld: false,
627+
ip: false,
628+
ip4: false,
629+
ip6: false,
630+
idn: false,
631+
punycode: false
632+
}
584633
}, {
585634
name: 'scheme-relative URL',
586635
url: '//www.example.org/',
@@ -629,6 +678,55 @@ var urls = [{
629678
idn: false,
630679
punycode: false
631680
}
681+
}, {
682+
name: 'scheme-relative URL excessive slashes',
683+
url: '//\\/www.example.org/',
684+
_url: '//www.example.org/',
685+
parts: {
686+
protocol: null,
687+
username: null,
688+
password: null,
689+
hostname: 'www.example.org',
690+
port: null,
691+
path: '/',
692+
query: null,
693+
fragment: null
694+
},
695+
accessors: {
696+
protocol: '',
697+
username: '',
698+
password: '',
699+
port: '',
700+
path: '/',
701+
query: '',
702+
fragment: '',
703+
resource: '/',
704+
authority: 'www.example.org',
705+
origin: 'www.example.org',
706+
userinfo: '',
707+
subdomain: 'www',
708+
domain: 'example.org',
709+
tld: 'org',
710+
directory: '/',
711+
filename: '',
712+
suffix: '',
713+
hash: '',
714+
search: '',
715+
host: 'www.example.org',
716+
hostname: 'www.example.org'
717+
},
718+
is: {
719+
urn: false,
720+
url: true,
721+
relative: false,
722+
name: true,
723+
sld: false,
724+
ip: false,
725+
ip4: false,
726+
ip6: false,
727+
idn: false,
728+
punycode: false
729+
}
632730
}, {
633731
name: 'missing authority',
634732
url: 'food:///test/file.csv',

0 commit comments

Comments
 (0)