Skip to content

Commit febe85d

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

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

minimatch.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,9 @@ class Minimatch {
533533
continue
534534
}
535535

536+
// coalesce consecutive non-globstar * characters
537+
if (c === '*' && stateChar === '*') continue
538+
536539
// if we already have a stateChar, then it means
537540
// that there was something like ** or +? in there.
538541
// Handle the stateChar, then proceed with this one.

test/consecutive-stars-redos.js

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

0 commit comments

Comments
 (0)