Skip to content

Commit 46fe687

Browse files
committed
coalesce consecutive non-globstar * characters
Fix: GHSA-3ppc-4f35-3m26 Backport-Of: 2e111f3
1 parent 5a9ccbd commit 46fe687

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

minimatch.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,9 @@ function parse (pattern, isSub) {
390390
continue
391391
}
392392

393+
// coalesce consecutive non-globstar * characters
394+
if (c === '*' && stateChar === '*') continue
395+
393396
// if we already have a stateChar, then it means
394397
// that there was something like ** or +? in there.
395398
// Handle the stateChar, then proceed with this one.

test/consecutive-stars-redos.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
var tap = require('tap')
2+
var minimatch = require('../')
3+
var Minimatch = minimatch.Minimatch
4+
5+
tap.test('consecutive stars are coalesced', function (t) {
6+
var re1 = new Minimatch('a*b').makeRe()
7+
var re3 = new Minimatch('a***b').makeRe()
8+
t.equal(re3.toString(), re1.toString(), 'a***b same regex as a*b')
9+
t.end()
10+
})
11+
12+
tap.test('100+ consecutive stars do not cause ReDoS', function (t) {
13+
var stars = new Array(101).join('*')
14+
var pattern = 'a' + stars + 'b'
15+
var start = Date.now()
16+
var mm = new Minimatch(pattern)
17+
var re = mm.makeRe()
18+
re.test('a' + new Array(26).join('c'))
19+
var elapsed = Date.now() - start
20+
t.ok(elapsed < 1000, 'completed in ' + elapsed + 'ms (< 1s)')
21+
t.end()
22+
})

0 commit comments

Comments
 (0)