Skip to content

Commit fcbb73d

Browse files
authored
Merge pull request #3 from Trott/patch-1
fix for CVE-2021-23425
2 parents 3a728c9 + 6d89476 commit fcbb73d

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
var regex = /^(?:\r\n|\n|\r)+|(?:\r\n|\n|\r)+$/g;
3+
var regex = /^(?:\r|\n)+|(?:\r|\n)+$/g;
44

55
module.exports = function (str) {
66
return str.replace(regex, '');

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@
3434
"remove",
3535
"delete"
3636
],
37-
"dependencies": {},
3837
"devDependencies": {
3938
"mocha": "*",
40-
"xo": "*"
39+
"xo": "^0.17.1"
4140
},
4241
"xo": {
4342
"envs": [

test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,10 @@ it('should trim off \\r\\n', function () {
1919
assert.strictEqual(trimOffNewlines('\r\nunicorns\r\n'), 'unicorns');
2020
assert.strictEqual(trimOffNewlines('unicorns\r\n\r\n\r\n\r\n\r\n\r\n'), 'unicorns');
2121
});
22+
23+
it('should not be susceptible to exponential backtracking', function () {
24+
var start = Date.now();
25+
trimOffNewlines('a' + '\r\n'.repeat(1000) + 'a');
26+
var end = Date.now();
27+
assert.ok(end - start < 1000, 'took too long, probably susceptible to ReDOS');
28+
});

0 commit comments

Comments
 (0)