Skip to content

fix: compile a repeated extglob whose single branch absorbs its repetition once (GHSA-fc5q-39xc-vjpf) - #270

Open
vinay-keerthipati-keo wants to merge 1 commit into
micromatch:masterfrom
vinay-keerthipati-keo:fix/repeated-star-extglob-redos
Open

vinay-keerthipati-keo wants to merge 1 commit into
micromatch:masterfrom
vinay-keerthipati-keo:fix/repeated-star-extglob-redos

Conversation

@vinay-keerthipati-keo

@vinay-keerthipati-keo vinay-keerthipati-keo commented Nov 18, 2026 •

Copy link
Copy Markdown

What: Single-branch repeated extglobs containing *, such as +(*), +(*a), *(*a), +(*a*) and +(a*b), compile to a nested quantifier (e.g. (?:[^/]*?a)+). They skip analyzeRepeatedExtglob's checks, so a near-miss input backtracks exponentially. On current master, 28 characters take 3.5–6 s, and +(*a*) takes 2.7 s at 20 characters. This is GHSA-fc5q-39xc-vjpf, related to #175.

Why the fix is safe: such a branch absorbs its own repetition. * matches any run of non-slash characters, so any run of one or more matches of the branch is itself one match. So +(X) ≡ @(X) and *(X) ≡ ?(X). These branches are now marked collapse and closed with ) / )? instead of )+ / )*. Only branches made of literal characters, ? and single *s with no / qualify; **, /, brackets, braces, nested extglobs and alternation keep today's handling. Unlike literalizing, the pattern keeps its meaning.

Verified:

  • Every string up to 6 characters over a b . x / * ?, for 29 patterns and 5 option sets: 19,902,265 cases, identical results to the unmodified parser.
  • All 2,002 existing tests and lint pass.
  • The new tests (test/extglobs-repeated-star.js) cover the compiled source, 64-character near-misses (each under 100 ms), matching, and the shapes left alone.

Related: #175 (general issue), #194 and #191 (touch nearby extglob parsing; this PR doesn't overlap their ? handling).

…ition once

A repeated extglob with one branch containing `*`, such as `+(*)`, `+(*a)`,
`*(*a)`, `+(*a*)` or `+(a*b)`, compiled to a nested quantifier like
`(?:[^/]*?a)+`. On a near-miss input that backtracks exponentially: on the
current master, 28 characters took 3.5 to 6 seconds (`+(*a*)`: 2.7 s at 20),
roughly 15 times longer for every 4 more. This is GHSA-fc5q-39xc-vjpf
(single-branch repeated extglobs skip analyzeRepeatedExtglob's checks).

Such a branch absorbs its own repetition: `*` matches any run of non-slash
characters, so any run of one or more matches of the branch is itself one
match (it starts like the first, ends like the last, and the `*` covers
everything between). So `+(X)` matches exactly what `@(X)` matches, and
`*(X)` what `?(X)` matches. analyzeRepeatedExtglob now marks these branches
(`collapse`), and extglobClose closes them with `)` and `)?` instead of `)+`
and `)*`. Only a branch of literal characters, `?` and single `*`s with no
`/` qualifies; `**`, `/`, brackets, braces, nested extglobs and alternation
keep today's handling, so nothing else changes.

Unlike literalizing the pattern, this keeps its meaning. Checked against the
unmodified parser on every string up to 6 characters over a/b/./x///*/?, for
29 patterns and 5 option sets (19,902,265 cases): identical results. All
2,002 tests pass, and the new tests cover the compiled source, near-misses of
64 characters (each under 100 ms), matching, and the shapes left alone.
@vinay-keerthipati-keo

Copy link
Copy Markdown
Author

@jonschlinkert @mrmlnc this addresses GHSA-fc5q-39xc-vjpf (published Oct 19, updated Nov 17), which currently has no patched version and is failing dependency audits for downstream projects (it reaches us through vitest/vite). The change is small (one helper + one close-token switch in lib/parse.js) and keeps pattern meaning — verified identical against the current parser on ~19.9M cases. Happy to adjust anything. Thanks for maintaining picomatch!

@nl

nl commented Nov 18, 2026

Copy link
Copy Markdown

I tested this PR at 614ef37229ceea362ccbc729fb64e98a7e327dc8 on Node 24.9.0. The simple +(*a) case improves, but these related single-branch patterns still retain expensive repetition:

  • +([a]*)b against 'a'.repeat(40)
  • +(@(*a)) against 'a'.repeat(40) + '/'

Both should return false; each instead exceeds a 2-second child-process deadline (ETIMEDOUT). I see that the PR intentionally leaves bracket and nested extglob branches unchanged, so these are remaining coverage limits, not regressions introduced by the collapse optimization. They seem useful as explicit tests when assessing the scope of the advisory fix.

Save as repro.cjs in a checkout at the revision above and run node repro.cjs ./index.js:

const cases = [
  ['+([a]*)b', 'a'.repeat(40)],
  ['+(@(*a))', 'a'.repeat(40) + '/'],
];
const { spawnSync } = require('node:child_process');
const modulePath = require.resolve(process.argv[2]);
for (const [pattern, input] of cases) {
  const r = spawnSync(process.execPath, ['-e',
    'console.log(require(process.argv[1])(process.argv[2])(process.argv[3]))',
    modulePath, pattern, input], { timeout: 2000, encoding: 'utf8' });
  console.log({ pattern, result: r.error?.code ?? r.stdout.trim(), status: r.status });
}

@G-Rath

G-Rath commented Nov 18, 2026

Copy link
Copy Markdown

Both GitHub and VulnCheck have withdrawn this advisory, as it is not a security issue.

If a tool is still reporting you're "vulnerable", then you need to contact the tool author about getting their source updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants