Skip to content

Commit 7ccf02c

Browse files
Co-authored-by: Ulises Gascon <[email protected]>
1 parent 640e694 commit 7ccf02c

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ function pathToRegexp(path, keys, options) {
9494
pos = offset + match.length;
9595

9696
if (match === '*') {
97+
backtrack = '';
9798
extraOffset += 3;
9899
return '(.*)';
99100
}
@@ -123,6 +124,7 @@ function pathToRegexp(path, keys, options) {
123124
+ ')'
124125
+ optional;
125126

127+
backtrack = '';
126128
extraOffset += result.length - match.length;
127129

128130
return result;

test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ describe('path-to-regexp', function () {
1212
assert.deepEqual(pathToRegExp('/:a-:b'), /^(?:\/([^/]+?))-(?:((?:(?!\/|-).)+?))\/?$/i);
1313
});
1414

15+
// See: https://github.com/pillarjs/path-to-regexp/security/advisories/GHSA-37ch-88jc-xwx2
16+
it('should generate a regex without backtracking for 3+ params', function () {
17+
var re = pathToRegExp('/:a-:b-:c-:d');
18+
var input = '/' + Array(4001).join('a-') + '/z';
19+
var start = Date.now();
20+
re.exec(input);
21+
assert.ok(Date.now() - start < 1000, 'ReDoS: regex took too long');
22+
});
23+
1524
describe('strings', function () {
1625
it('should match simple paths', function () {
1726
var params = [];

0 commit comments

Comments
 (0)