Skip to content

Commit a62ead2

Browse files
author
Tamas Perger
committed
fix(issue-275): coalesce 2 or more asterisks into 2
Eliminating ReDoS risk: #275
1 parent 3e216b9 commit a62ead2

3 files changed

Lines changed: 33 additions & 19 deletions

File tree

minimatch.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ class Minimatch {
165165
constructor (pattern, options) {
166166
assertValidPattern(pattern)
167167

168+
pattern = pattern.replace(new RegExp("\\*\\*+", "g"), "**")
169+
168170
if (!options) options = {}
169171

170172
this.options = options

tap-snapshots/test/basic.js.test.cjs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ exports[`test/basic.js TAP basic tests > makeRe ** 3`] = `
7474
`
7575

7676
exports[`test/basic.js TAP basic tests > makeRe *******? 1`] = `
77-
/^(?:(?!\\.)(?=.)[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/])$/
77+
/^(?:(?!\\.)(?=.)[^/]*?[^/]*?[^/])$/
7878
`
7979

8080
exports[`test/basic.js TAP basic tests > makeRe *******c 1`] = `
81-
/^(?:(?!\\.)(?=.)[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?c)$/
81+
/^(?:(?!\\.)(?=.)[^/]*?[^/]*?c)$/
8282
`
8383

8484
exports[`test/basic.js TAP basic tests > makeRe *****?? 1`] = `
85-
/^(?:(?!\\.)(?=.)[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/][^/])$/
85+
/^(?:(?!\\.)(?=.)[^/]*?[^/]*?[^/][^/])$/
8686
`
8787

8888
exports[`test/basic.js TAP basic tests > makeRe **/.x/** 1`] = `
@@ -138,35 +138,35 @@ exports[`test/basic.js TAP basic tests > makeRe /^root:/{s/^[^:]*:[^:]*:([^:]*).
138138
`
139139

140140
exports[`test/basic.js TAP basic tests > makeRe ?************c****?**** 1`] = `
141-
/^(?:(?!\\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?c[^/]*?[^/]*?[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/]*?[^/]*?)$/
141+
/^(?:(?!\\.)(?=.)[^/][^/]*?[^/]*?c[^/]*?[^/]*?[^/][^/]*?[^/]*?)$/
142142
`
143143

144144
exports[`test/basic.js TAP basic tests > makeRe ?*****?? 1`] = `
145-
/^(?:(?!\\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/][^/])$/
145+
/^(?:(?!\\.)(?=.)[^/][^/]*?[^/]*?[^/][^/])$/
146146
`
147147

148148
exports[`test/basic.js TAP basic tests > makeRe ?*****?c 1`] = `
149-
/^(?:(?!\\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]c)$/
149+
/^(?:(?!\\.)(?=.)[^/][^/]*?[^/]*?[^/]c)$/
150150
`
151151

152152
exports[`test/basic.js TAP basic tests > makeRe ?***?**** 1`] = `
153-
/^(?:(?!\\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/]*?[^/]*?)$/
153+
/^(?:(?!\\.)(?=.)[^/][^/]*?[^/]*?[^/][^/]*?[^/]*?)$/
154154
`
155155

156156
exports[`test/basic.js TAP basic tests > makeRe ?***?****? 1`] = `
157-
/^(?:(?!\\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/]*?[^/]*?[^/])$/
157+
/^(?:(?!\\.)(?=.)[^/][^/]*?[^/]*?[^/][^/]*?[^/]*?[^/])$/
158158
`
159159

160160
exports[`test/basic.js TAP basic tests > makeRe ?***?****c 1`] = `
161-
/^(?:(?!\\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/]*?[^/]*?c)$/
161+
/^(?:(?!\\.)(?=.)[^/][^/]*?[^/]*?[^/][^/]*?[^/]*?c)$/
162162
`
163163

164164
exports[`test/basic.js TAP basic tests > makeRe ??**********?****? 1`] = `
165-
/^(?:(?!\\.)(?=.)[^/][^/][^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/]*?[^/]*?[^/])$/
165+
/^(?:(?!\\.)(?=.)[^/][^/][^/]*?[^/]*?[^/][^/]*?[^/]*?[^/])$/
166166
`
167167

168168
exports[`test/basic.js TAP basic tests > makeRe ??**********?****c 1`] = `
169-
/^(?:(?!\\.)(?=.)[^/][^/][^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/]*?[^/]*?c)$/
169+
/^(?:(?!\\.)(?=.)[^/][^/][^/]*?[^/]*?[^/][^/]*?[^/]*?c)$/
170170
`
171171

172172
exports[`test/basic.js TAP basic tests > makeRe @(*|.*) 1`] = `
@@ -342,39 +342,39 @@ exports[`test/basic.js TAP basic tests > makeRe a* 1`] = `
342342
`
343343

344344
exports[`test/basic.js TAP basic tests > makeRe a********???******* 1`] = `
345-
/^(?:(?=.)a[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/][^/][^/][^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?)$/
345+
/^(?:(?=.)a[^/]*?[^/]*?[^/][^/][^/][^/]*?[^/]*?)$/
346346
`
347347

348348
exports[`test/basic.js TAP basic tests > makeRe a*****?c 1`] = `
349-
/^(?:(?=.)a[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]c)$/
349+
/^(?:(?=.)a[^/]*?[^/]*?[^/]c)$/
350350
`
351351

352352
exports[`test/basic.js TAP basic tests > makeRe a*****c*?** 1`] = `
353-
/^(?:(?=.)a[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?c[^/]*?[^/][^/]*?[^/]*?)$/
353+
/^(?:(?=.)a[^/]*?[^/]*?c[^/]*?[^/][^/]*?[^/]*?)$/
354354
`
355355

356356
exports[`test/basic.js TAP basic tests > makeRe a****c**?**??***** 1`] = `
357-
/^(?:(?=.)a[^/]*?[^/]*?[^/]*?[^/]*?c[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/][^/]*?[^/]*?[^/]*?[^/]*?[^/]*?)$/
357+
/^(?:(?=.)a[^/]*?[^/]*?c[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/][^/]*?[^/]*?)$/
358358
`
359359

360360
exports[`test/basic.js TAP basic tests > makeRe a***c 1`] = `
361-
/^(?:(?=.)a[^/]*?[^/]*?[^/]*?c)$/
361+
/^(?:(?=.)a[^/]*?[^/]*?c)$/
362362
`
363363

364364
exports[`test/basic.js TAP basic tests > makeRe a**?**cd**?**??***k 1`] = `
365-
/^(?:(?=.)a[^/]*?[^/]*?[^/][^/]*?[^/]*?cd[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/][^/]*?[^/]*?[^/]*?k)$/
365+
/^(?:(?=.)a[^/]*?[^/]*?[^/][^/]*?[^/]*?cd[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/][^/]*?[^/]*?k)$/
366366
`
367367

368368
exports[`test/basic.js TAP basic tests > makeRe a**?**cd**?**??***k** 1`] = `
369-
/^(?:(?=.)a[^/]*?[^/]*?[^/][^/]*?[^/]*?cd[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/][^/]*?[^/]*?[^/]*?k[^/]*?[^/]*?)$/
369+
/^(?:(?=.)a[^/]*?[^/]*?[^/][^/]*?[^/]*?cd[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/][^/]*?[^/]*?k[^/]*?[^/]*?)$/
370370
`
371371

372372
exports[`test/basic.js TAP basic tests > makeRe a**?**cd**?**??k 1`] = `
373373
/^(?:(?=.)a[^/]*?[^/]*?[^/][^/]*?[^/]*?cd[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/]k)$/
374374
`
375375

376376
exports[`test/basic.js TAP basic tests > makeRe a**?**cd**?**??k*** 1`] = `
377-
/^(?:(?=.)a[^/]*?[^/]*?[^/][^/]*?[^/]*?cd[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/]k[^/]*?[^/]*?[^/]*?)$/
377+
/^(?:(?=.)a[^/]*?[^/]*?[^/][^/]*?[^/]*?cd[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/]k[^/]*?[^/]*?)$/
378378
`
379379

380380
exports[`test/basic.js TAP basic tests > makeRe a*[^c] 1`] = `

test/redos2.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var t = require('tap')
2+
3+
var minimatch = require('../')
4+
5+
// Fixing https://github.com/isaacs/minimatch/issues/275
6+
var exploit = '***************X***************************************'
7+
8+
// Valid match, no timeout
9+
t.ok(minimatch('___________________________________X___', exploit))
10+
11+
// No match, no timeout
12+
t.notOk(minimatch('___________________________________z___', exploit))

0 commit comments

Comments
 (0)