Packages / minimatch / Security
minimatch has a ReDoS via repeated wildcards with non-matching literal in pattern
Affected releases · minimatch
- 10.x10.0.0 – 10.2.0Fixed in 10.2.1
- 9.x9.0.0 – 9.0.5Fixed in 9.0.6
- 8.x8.0.0 – 8.0.4Fixed in 8.0.5
- 7.x7.0.0 – 7.4.6Fixed in 7.4.7
- 6.x6.0.0 – 6.2.0Fixed in 6.2.1
- 5.x5.0.0 – 5.1.6Fixed in 5.1.7
- 4.x4.0.0 – 4.2.3Fixed in 4.2.4
- 3.x3.0.0 – 3.1.2Fixed in 3.1.3
- 2.x and older0.0.1 – 2.0.10No fix, no longer updated
On 10.x, the newest line:
npm install minimatch@10.2.1Every release on a timeline
Not affected
11.0.0 – 11.0.9
10 releases, latest
Affected
10.0.0 – 10.2.0
9 releases
Fixed
10.2.1 – 10.2.6
6 releases
Affected
9.0.0 – 9.0.5
6 releases
Fixed
9.0.6 – 9.0.9
4 releases
Affected
8.0.0 – 8.0.4
5 releases
Fixed
8.0.5 – 8.0.7
3 releases
Affected
7.0.0 – 7.4.6
16 releases
Fixed
7.4.7 – 7.4.9
3 releases
Affected
6.0.0 – 6.2.0
17 releases
Fixed
6.2.1 – 6.2.3
3 releases
Affected
5.0.0 – 5.1.6
9 releases
Fixed
5.1.7 – 5.1.9
3 releases
Affected
4.0.0 – 4.2.3
7 releases
Fixed
4.2.4 – 4.2.6
3 releases
Affected
3.0.0 – 3.1.2
11 releases
Fixed
3.1.3 – 3.1.5
3 releases
Affected
2.0.0 – 2.0.10
11 releases
Affected
1.0.0
1 release
Affected
0.0.1 – 0.4.0
25 releases
What happens
Summary
minimatch is vulnerable to Regular Expression Denial of Service (ReDoS) when a glob pattern contains many consecutive * wildcards followed by a literal character that doesn't appear in the test string. Each * compiles to a separate [^/]*? regex group, and when the match fails, V8's regex engine backtracks exponentially across all possible splits.
The time complexity is O(4^N) where N is the number of * characters. With N=15, a single minimatch() call takes ~2 seconds. With N=34, it hangs effectively forever.
Details
Give all details on the vulnerability. Pointing to the incriminated source code is very helpful for the maintainer.
PoC
When minimatch compiles a glob pattern, each * becomes [^/]*? in the generated regex. For a pattern like ***************X***:
/^(?!\.)[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?X[^/]*?[^/]*?[^/]*?$/
When the test string doesn't contain X, the regex engine must try every possible way to distribute the characters across all the [^/]*? groups before concluding no match exists. With N groups and M characters, this is O(C(N+M, N)) — exponential.
Impact
Any application that passes user-controlled strings to minimatch() as the pattern argument is vulnerable to DoS. This includes:
File search/filter UIs that accept glob patterns
.gitignore-style filtering with user-defined rulesBuild tools that accept glob configuration
Any API that exposes glob matching to untrusted input
Thanks to @ljharb for back-porting the fix to legacy versions of minimatch.
A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.