File tree 3 files changed +18
-1
lines changed
3 files changed +18
-1
lines changed Original file line number Diff line number Diff line change 1
1
# CHANGELOG
2
2
3
+ ## unreleased
4
+
5
+ - Fix issue where urls in the form ` javascript:alert('xss'); ` were not properly sanitized
6
+ - Fix issue where urls in the form ` javasc	ript:alert('XSS'); ` were not properly sanitized
7
+
3
8
## 6.0.0
4
9
5
10
** Breaking Changes**
Original file line number Diff line number Diff line change @@ -100,6 +100,7 @@ describe("sanitizeUrl", () => {
100
100
"javascript:alert('XSS')" ,
101
101
"jav	ascript:alert('XSS');" ,
102
102
"  javascript:alert('XSS');" ,
103
+ "javasc	ript: alert('XSS');" ,
103
104
] ;
104
105
105
106
attackVectors . forEach ( ( vector ) => {
@@ -136,6 +137,15 @@ describe("sanitizeUrl", () => {
136
137
) ;
137
138
} ) ;
138
139
140
+ it ( `disallows ${ protocol } urls that use : for the colon portion of the url` , ( ) => {
141
+ expect ( sanitizeUrl ( `${ protocol } :alert(document.domain)` ) ) . toBe (
142
+ "about:blank"
143
+ ) ;
144
+ expect ( sanitizeUrl ( `${ protocol } :alert(document.domain)` ) ) . toBe (
145
+ "about:blank"
146
+ ) ;
147
+ } ) ;
148
+
139
149
it ( `disregards capitalization for ${ protocol } urls` , ( ) => {
140
150
// upper case every other letter in protocol name
141
151
const mixedCapitalizationProtocol = protocol
Original file line number Diff line number Diff line change 1
1
const invalidProtocolRegex = / ^ ( [ ^ \w ] * ) ( j a v a s c r i p t | d a t a | v b s c r i p t ) / im;
2
2
const htmlEntitiesRegex = / & # ( \w + ) ( ^ \w | ; ) ? / g;
3
+ const htmlTabEntityRegex = / & t a b ; / gi;
3
4
const ctrlCharactersRegex =
4
5
/ [ \u0000 - \u001F \u007F - \u009F \u2000 - \u200D \uFEFF ] / gim;
5
- const urlSchemeRegex = / ^ ( [ ^ : ] + ) : / gm ;
6
+ const urlSchemeRegex = / ^ . + ( : | & c o l o n ; ) / gim ;
6
7
const relativeFirstCharacters = [ "." , "/" ] ;
7
8
8
9
function isRelativeUrlWithoutProtocol ( url : string ) : boolean {
@@ -11,6 +12,7 @@ function isRelativeUrlWithoutProtocol(url: string): boolean {
11
12
12
13
// adapted from https://stackoverflow.com/a/29824550/2601552
13
14
function decodeHtmlCharacters ( str : string ) {
15
+ str = str . replace ( htmlTabEntityRegex , "	" ) ;
14
16
return str . replace ( htmlEntitiesRegex , ( match , dec ) => {
15
17
return String . fromCharCode ( dec ) ;
16
18
} ) ;
You can’t perform that action at this time.
0 commit comments