Skip to content

Commit

Permalink
fixup! fix: remediate ReDOS further
Browse files Browse the repository at this point in the history
  • Loading branch information
Trott committed Sep 23, 2021
1 parent e3e7fa6 commit e42fd21
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions test.js
Expand Up @@ -21,9 +21,22 @@ it('should trim off \\r\\n', function () {
});

it('should not be susceptible to exponential backtracking', function () {
var redosString = 'a';
var count = 1000;
while (count) {
redosString += '\r\n';
count--;
}
redosString += 'a';
var LongerRedosString = redosString;
var count = 1000;
while (count) {
LongerRedosString += redosString;
count--;
}
var start = Date.now();
trimOffNewlines('a' + '\r\n'.repeat(1000) + 'a');
trimOffNewlines(`a${'\r\n'.repeat(1000)}a`.repeat(1000));
trimOffNewlines(redosString);
trimOffNewlines(LongerRedosString);
var end = Date.now();
assert.ok(end - start < 1000, 'took too long, probably susceptible to ReDOS');
});
Expand Down

0 comments on commit e42fd21

Please sign in to comment.