Fixed JSON parsing preamble regression.

This commit is contained in:
hackademix 2019-05-28 00:48:00 +02:00
parent c2f0ce0dfc
commit 37d148e3af
2 changed files with 41 additions and 1 deletions

39
src/lib/Timing.js Normal file
View File

@ -0,0 +1,39 @@
class Timing {
constructor(workSlot = 4, longTime = 20000, pauseTime = 20) {
this.workSlot = workSlot;
this.longTime = longTime;
this.pauseTime = pauseTime;
this.interrupted = false;
this.fatalTimeout = false;
this.reset();
}
static sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async pause() {
if (this.interrupted) throw new TimingException("Interrupted");
let now = Date.now();
this.elapsed = now - this.timeOrigin;
if (now - this.lastPause > this.workSlot) {
this.tooLong = this.elapsed >= this.longTime;
if (this.tooLong && this.fatalTimeout) {
throw new TimingException(`Exceeded ${this.longTime}ms timeout`);
}
await Timing.sleep(this.pauseTime);
this.lastPause = Date.now();
return true;
}
return false;
}
reset() {
this.elapsed = 0;
this.timeOrigin = this.lastPause = Date.now();
this.tooLong = false;
}
}
class TimingException extends Error {};

View File

@ -172,7 +172,8 @@ XSS.InjectionChecker = (async () => {
const toStringRx = /^function\s*toString\(\)\s*{\s*\[native code\]\s*\}$/; const toStringRx = /^function\s*toString\(\)\s*{\s*\[native code\]\s*\}$/;
// optimistic case first, one big JSON block // optimistic case first, one big JSON block
let m = s.match(/{[^]+}|\[\s*{[^]+}\s*\]/); s = s.replace(/[^{"]+=/, "")
let m = s.match(/{[^]+}|\[[^]*{[^]*}[^]*\]/);
if (!m) return s; if (!m) return s;
// semicolon-separated JSON chunks, like on syndication.twitter.com // semicolon-separated JSON chunks, like on syndication.twitter.com