Skip to content

fix: keep wildcards out of repeated extglobs (CVE-2026-112366) - #264

Open
jibsta210 wants to merge 1 commit into
micromatch:masterfrom
jibsta210:fix/repeated-wildcard-extglob-redos
Open

jibsta210 wants to merge 1 commit into
micromatch:masterfrom
jibsta210:fix/repeated-wildcard-extglob-redos

Conversation

@jibsta210

@jibsta210 jibsta210 commented Nov 17, 2026 •

Copy link
Copy Markdown

Problem

GHSA-fc5q-39xc-vjpf / CVE-2026-112366: a repeated extglob whose body contains a wildcard compiles to
one unbounded quantifier nested inside another, which backtracks exponentially on short input that
almost matches:

pm.makeRe('+(*a)').source                    //=> ^(?:(?=.)(?:[^/]*?a)+)$
pm.isMatch('a'.repeat(48) + '/', '+(*a)')     // does not return

analyzeRepeatedExtglob only examines multi-branch bodies, so single-branch forms (+(*), +(*a),
*(*a), +(a*b)) are never checked. The same nesting also comes from several branches (+(a*|b)),
a star inside a nested @(...), a negation (+(!(a)), which compiles to a lookahead plus a star),
and a regex + after a group (@(*a)+, (*a)+, {*a,b}+).

Fix

  1. Exact rewrite in extglobClose. When a +(...)/*(...) body holds a wildcard, the repeat is
    rewritten only where it provably matches the same strings, because a star can absorb neighbouring
    repeats:

    body rewrite why it is exact
    one branch with a star, +(*a) (?:[^/]*?a) the last star of one repeat absorbs the rest of it and the next repeat up to that repeat's trailing text
    starred branches all end with a star, +(a*|b) (?:b)*(?:a[^/]*?|b) a starred repeat absorbs every repeat after it
    starred branches all start with a star, +(*.js|*.ts) (?:[^/]*?\.js|[^/]*?\.ts) a starred repeat absorbs every repeat before it
    exactly one !(...), *(!(f)) one optional repeat a zero-width test plus a star

    Pieces may be literal text, ?, brackets and star-free groups ({js,ts}, @(js|ts)); every
    character a piece can match must be matched by every star (/ is excluded, so is \ with
    windows, and line terminators for bash's .*?). *(...) rewrites are made optional. The
    proof is about the compiled regex, so it holds under every option. Capture groups keep their
    count and order (the second copy of fixed branches is non-capturing); a group inside a rewritten
    repeat captures across what used to be several repeats.

    Anything else with a wildcard falls back to the existing maxExtglobRecursion literal safeguard,
    as +(a|aa) already does. Repeats without wildcards (*(f*(o)), +(foo|bar)) are untouched, so
    the bash extglob tests pass unchanged.

  2. A regex + after a group that holds a wildcard is read literally, as bash does (@(*a)+
    matches xa+). With regex: true, a * there is a wildcard instead of a quantifier.

  3. A final check in parse: if the finished regex still repeats a group that holds a repeated
    wildcard (a negated class, ., \S, \W, \D, or [\s\S], under *, +, {n,} or a count
    above 2), or a rewrite was followed by an unbalanced-paren repair or left an invalid regex, the
    pattern becomes a literal, with any leading ! kept. This covers malformed patterns whose
    parentheses are repaired after the extglob checks ran, for example (*|+(("")).

maxExtglobRecursion: false disables all of it. With it off, output is byte-identical to before.

Picomatch appends some text without updating the token (quoted text; on v2, text merged into
earlier text), so the analysis keeps that text in token fields of its own and refuses to rewrite
when it cannot tell what a token emits. Rebuild behaviour is unchanged.

Tests

test/redos-repeated-wildcard.js:

  • 54 patterns under 6 option sets compile with no wildcard inside a repeat, and match exactly
    what the unprotected regex matches on every input up to length 4 over a b . / \ \n x;
  • capture groups keep their count; quoted text, POSIX classes, literal braces, brace ranges, a **
    just before the extglob and a lazy ? after it are covered;
  • non-rewritable forms and malformed patterns become literals, and hostile input finishes within a
    child-process deadline;
  • 65 KB patterns (+(*a) repeated, deep @(/)+ nesting, {a,*b}+, )+ repeated) parse in linear
    time.

Full suite on master: 2013 passing, lint clean; on v2: 1988 passing (its lint already fails on
three untouched test files).

Outside the suite, three rounds of independent review and differential fuzzing (about 150,000
pattern and option cases per line, compared on every short input) found no wrong answer from a
rewrite. The only differences left are where the unprotected regex is itself invalid or drops quoted
or merged text and the rewrite keeps it. A static scan of about 200,000 random patterns found no
regex that still nests a wildcard in a repeat.

Not covered

Two other shapes are slow too, but they hold no wildcard, so they are not this advisory:

  • repeats of overlapping fixed-width alternatives, like +(a?|a), +([a]|a) or +(a|[ab]);
  • nested repeats of fixed text, like +(a*(a)) or raw regex (a+)+, which the existing tests require
    to keep working ((a+|b)+).

Both would need an ambiguity analysis of their own.

Related: #234, #239, #247, #246, #254.

A backport of the same change to v2 is in #265.

🤖 Generated with Claude Code

A repeated extglob whose body holds a wildcard, such as +(*a), compiled to
an unbounded quantifier nested in another and backtracked exponentially on
short input that almost matched (GHSA-fc5q-39xc-vjpf).

Rewrite such repeats exactly when a star can absorb the neighbouring
repeats, and fall back to the existing literal safeguard otherwise. Also
read a regex + after a wildcard group literally, and check the final regex
so no repaired malformed pattern keeps a wildcard inside a repeat.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@maagalhebrew

Copy link
Copy Markdown

Downstream compatibility results for 8144a1a on Windows x64 (Node 24.19.0, npm 11.19.0). I compared the published 4.0.7 npm package, the PR parent 9fab7bf, and the candidate in two cleanly installed Vite projects. I kept the downstream dependencies fixed and verified the SHA-256 of the Picomatch parser loaded by each build. Patch commit

Downstream project Result on all three revisions Candidate output compared with both baselines
React Router 8.4.0 with Vite 8.3.4 Route type generation, TypeScript checking, and production build passed All 133 client file paths and contents matched
Vite 8.3.5 workshop TypeScript checking and production build passed All 18 distribution file paths and contents matched

On all three revisions, the React Router development server served an ordinary text file (HTTP 200), refused an inert fixture covered by its file-exclusion rule (HTTP 403), and detected an edit to the ordinary file. Four standalone Node tests also passed for exclusion rules, extension matching, pattern scanning, and regular expression generation.

This checks downstream compatibility on Windows. The security effectiveness of the patch still needs independent review.

@YungTosti

Copy link
Copy Markdown

I would be very happy with this fix, thanks!

@Portll

Portll commented Nov 18, 2026 •

Copy link
Copy Markdown

Independent comparison of the open fixes for GHSA-fc5q-39xc-vjpf, at 8144a1a (macOS arm64, Node 26.7.0). I ran 17 PRs against master 9fab7bf with the same three checks. For each one, the PR's lib/ was loaded under master's unmodified test suite.

Method

  • Suite: master's test/ (1,998 tests) against each PR's lib/ and index.js.
  • ReDoS: 25 repeated-extglob attack patterns, each with 4 near-miss inputs ('a'×32 + '!', + 'b', + '/', 'ab'×16 + '!'), and a 3 s cap per pattern. The survivors were then re-run at input lengths 5,000 and 20,000, plus 13 more forms (+(!(a)), @(*a)+, (*a)+, {*a,b}+, +(@(*a)), +(*a|b), …).
  • Semantics: isMatch over 42 extglob patterns × every string of 1–4 chars from {a,b,c}, checked against bash 5.3 [[ $s == $p ]] with extglob on. Bash 3.2 gives the same results. Master already differs from bash in 336 cases, so only mismatches beyond master's count against a PR.

Results

PR master suite hangs (of 25) new mismatches vs bash
#264 1998/1998 0 0 on the base grid; 110 on the extra forms (literal fallback, below)
#259 1998/1998 0 0 on the base grid; 70 on the extra forms
#260 1998/1998 0 0 on the base grid; 270 on the extra forms
#273, #270 1998/1998 4 0
#262 1998/1998 0 312 (+(*a*) no longer matches a)
#269, #267, #266, #254, #237 1998/1998 1–2 0–225
#258 1997/1998 0 62
#257 1998/1998 4 0
#238 1998/1998 7 430
#261 1965/1998 throws on 7 480
#274, #272 1934, 1994/1998 0 883 (+(*) no longer matches a)

At input lengths of 20k, #264 is the only one of the three survivors with no hang on any single repeated-extglob form tested. #259 still hangs on (*a)+. #260 still hangs on +(!(b)a), @(*a)+, (*a)+ and {*a,b}+.

Caveats for #264

  • Literal fallback. +(@(*a)) and +(*a|a*) now compile to the escaped literal: +(@(*a)) no longer matches a, aa or aba. This is the same conservative fallback master already uses for risky multi-branch bodies, so I count it as a design choice rather than a defect. A follow-up could rewrite +(@(X)) as +(X) before analysis.

On these checks #264 has the widest coverage and no regressions in master's suite. +1 to landing it.

@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.

@Portll

Portll commented Nov 25, 2026

Copy link
Copy Markdown

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

Thanks, noted. I've seen the withdrawal and jonschlinkert's reasoning on #235.

The comparison above still holds if #264 is taken as a performance fix instead of a security one. It passes master's full suite and doesn't hang on any of the 25 repeated-extglob forms.

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.

5 participants