Skip to content

Commit 4b7e446

Browse files
author
Tamas Perger
committed
fix(issue-275): coalesce 2 or more asterisks into 2
Eliminating ReDoS risk: #275
1 parent 699c459 commit 4b7e446

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
@@ -136,6 +136,8 @@ function Minimatch (pattern, options) {
136136

137137
pattern = pattern.trim()
138138

139+
pattern = pattern.replace(new RegExp("\\*\\*+", "g"), "**");
140+
139141
// windows support: need to use /, not \
140142
if (!options.allowWindowsEscape && path.sep !== '/') {
141143
pattern = pattern.split(path.sep).join('/')

test/patterns.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -296,22 +296,22 @@ module.exports.regexps = [
296296
'false',
297297
'/^(?:(?!\\.)(?=.)[^/]*?\\/(?=.)man[^/]*?\\/(?=.)bash\\.[^/]*?)$/',
298298
'/^(?:man\\/man1\\/bash\\.1)$/',
299-
'/^(?:(?=.)a[^/]*?[^/]*?[^/]*?c)$/',
300-
'/^(?:(?=.)a[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]c)$/',
301-
'/^(?:(?!\\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/][^/])$/',
302-
'/^(?:(?!\\.)(?=.)[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/][^/])$/',
303-
'/^(?:(?!\\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]c)$/',
304-
'/^(?:(?!\\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/]*?[^/]*?c)$/',
305-
'/^(?:(?!\\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/]*?[^/]*?[^/])$/',
306-
'/^(?:(?!\\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/]*?[^/]*?)$/',
307-
'/^(?:(?!\\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[^/]*?k[^/]*?[^/]*?)$/',
314-
'/^(?:(?=.)a[^/]*?[^/]*?[^/]*?[^/]*?c[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/][^/]*?[^/]*?[^/]*?[^/]*?[^/]*?)$/',
311+
'/^(?:(?=.)a[^/]*?[^/]*?[^/][^/]*?[^/]*?cd[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/]k[^/]*?[^/]*?)$/',
312+
'/^(?:(?=.)a[^/]*?[^/]*?[^/][^/]*?[^/]*?cd[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/][^/]*?[^/]*?k)$/',
313+
'/^(?:(?=.)a[^/]*?[^/]*?[^/][^/]*?[^/]*?cd[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/][^/]*?[^/]*?k[^/]*?[^/]*?)$/',
314+
'/^(?:(?=.)a[^/]*?[^/]*?c[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/][^/]*?[^/]*?)$/',
315315
'/^(?:(?!\\.)(?=.)[-abc])$/',
316316
'/^(?:(?!\\.)(?=.)[abc-])$/',
317317
'/^(?:\\\\)$/',
@@ -322,12 +322,12 @@ module.exports.regexps = [
322322
'/^(?:(?!\\.)(?=.)[\\]])$/',
323323
'/^(?:(?!\\.)(?=.)[\\]-])$/',
324324
'/^(?:(?!\\.)(?=.)[a-z])$/',
325-
'/^(?:(?!\\.)(?=.)[^/][^/][^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/]*?[^/]*?[^/])$/',
326-
'/^(?:(?!\\.)(?=.)[^/][^/][^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/]*?[^/]*?c)$/',
327-
'/^(?:(?!\\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?c[^/]*?[^/]*?[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/]*?[^/]*?)$/',
325+
'/^(?:(?!\\.)(?=.)[^/][^/][^/]*?[^/]*?[^/][^/]*?[^/]*?[^/])$/',
326+
'/^(?:(?!\\.)(?=.)[^/][^/][^/]*?[^/]*?[^/][^/]*?[^/]*?c)$/',
327+
'/^(?:(?!\\.)(?=.)[^/][^/]*?[^/]*?c[^/]*?[^/]*?[^/][^/]*?[^/]*?)$/',
328328
'/^(?:(?!\\.)(?=.)[^/]*?c[^/]*?[^/][^/]*?[^/]*?)$/',
329-
'/^(?:(?=.)a[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?c[^/]*?[^/][^/]*?[^/]*?)$/',
330-
'/^(?:(?=.)a[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/][^/][^/][^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?)$/',
329+
'/^(?:(?=.)a[^/]*?[^/]*?c[^/]*?[^/][^/]*?[^/]*?)$/',
330+
'/^(?:(?=.)a[^/]*?[^/]*?[^/][^/][^/][^/]*?[^/]*?)$/',
331331
'/^(?:\\[\\])$/',
332332
'/^(?:\\[abc)$/',
333333
'/^(?:(?=.)XYZ)$/i',

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)