Skip to content

Commit 3753e81

Browse files
committed
[XSS] Fixed memoization bug resulting in performance degradation on some payloads.
1 parent 10e02b4 commit 3753e81

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/xss/InjectionChecker.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ XSS.InjectionChecker = (async () => {
115115
// special treatment for quotes
116116
bs[c] = new RegExp("[" + def + c + "]");
117117
}
118-
delete this.breakStops;
119-
return (this.breakStops = bs);
118+
Object.defineProperty(Object.getPrototypeOf(this), 'breakStops', {value: bs});
119+
return bs;
120120
},
121121

122122
collapseChars: (s) => s.replace(/\;+/g, ';').replace(/\/{4,}/g, '////')
@@ -283,7 +283,7 @@ XSS.InjectionChecker = (async () => {
283283
+fuzzify('source|toString') + ")|\\[)|" + IC_EVENT_DOS_PATTERN
284284
),
285285
_riskyAssignmentRx: new RegExp(
286-
"\\b(?:" + fuzzify('location|innerHTML|outerHTML') + ")\\b[^]*="
286+
"(?:^|[^&])\\b(?:" + fuzzify('location|innerHTML|outerHTML') + ")\\b[^]*="
287287
),
288288
_nameRx: new RegExp(
289289
"=[^]*\\b" + fuzzify('name') + "\\b|" +
@@ -301,7 +301,7 @@ XSS.InjectionChecker = (async () => {
301301
')|(?:^|\\W)(?:' + IC_EVAL_PATTERN +
302302
')(?:\\W+[^]*|)[(`]|(?:[=(]|\\{[^]+:)[^]*(?:' + // calling eval-like functions directly or...
303303
IC_EVAL_PATTERN + // ... assigning them to another function possibly called by the victim later
304-
')[^]*[\\n,;:|]|\\b(?:' +
304+
')[^]*[\\n,;:|]|(?:^|[^&])\\b(?:' +
305305
fuzzify('setter|location|innerHTML|outerHTML') + // eval-like assignments
306306
')\\b[^]*=|' +
307307
'\\.' + IC_COMMENT_PATTERN + "src" + IC_COMMENT_PATTERN + '=' +
@@ -498,8 +498,9 @@ XSS.InjectionChecker = (async () => {
498498
},
499499

500500
get invalidCharsRx() {
501-
delete this.invalidCharsRx;
502-
return this.invalidCharsRx = new RegExp("^[^\"'`/<>]*[" + this._createInvalidRanges() + "]");
501+
let value = new RegExp("^[^\"'`/<>]*[" + this._createInvalidRanges() + "]");
502+
Object.defineProperty(Object.getPrototypeOf(this), 'invalidCharsRx', {value});
503+
return value;
503504
},
504505

505506
async checkJSBreak(s) {

0 commit comments

Comments
 (0)