Repository navigation
Conversation
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]>
|
Downstream compatibility results for
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. |
|
I would be very happy with this fix, thanks! |
|
Independent comparison of the open fixes for GHSA-fc5q-39xc-vjpf, at Method
Results
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 Caveats for #264
On these checks #264 has the widest coverage and no regressions in master's suite. +1 to landing it. |
|
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. |
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. |
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:
analyzeRepeatedExtglobonly 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
Exact rewrite in
extglobClose. When a+(...)/*(...)body holds a wildcard, the repeat isrewritten only where it provably matches the same strings, because a star can absorb neighbouring
repeats:
+(*a)(?:[^/]*?a)+(a*|b)(?:b)*(?:a[^/]*?|b)+(*.js|*.ts)(?:[^/]*?\.js|[^/]*?\.ts)!(...),*(!(f))Pieces may be literal text,
?, brackets and star-free groups ({js,ts},@(js|ts)); everycharacter a piece can match must be matched by every star (
/is excluded, so is\withwindows, and line terminators for bash's.*?).*(...)rewrites are made optional. Theproof 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
maxExtglobRecursionliteral safeguard,as
+(a|aa)already does. Repeats without wildcards (*(f*(o)),+(foo|bar)) are untouched, sothe bash extglob tests pass unchanged.
A regex
+after a group that holds a wildcard is read literally, as bash does (@(*a)+matches
xa+). Withregex: true, a*there is a wildcard instead of a quantifier.A final check in
parse: if the finished regex still repeats a group that holds a repeatedwildcard (a negated class,
.,\S,\W,\D, or[\s\S], under*,+,{n,}or a countabove 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 whoseparentheses are repaired after the extglob checks ran, for example
(*|+(("")).maxExtglobRecursion: falsedisables 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 intoearlier 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:what the unprotected regex matches on every input up to length 4 over
a b . / \ \n x;**just before the extglob and a lazy
?after it are covered;child-process deadline;
+(*a)repeated, deep@(/)+nesting,{a,*b}+,)+repeated) parse in lineartime.
Full suite on
master: 2013 passing, lint clean; onv2: 1988 passing (its lint already fails onthree 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:
+(a?|a),+([a]|a)or+(a|[ab]);+(a*(a))or raw regex(a+)+, which the existing tests requireto 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
v2is in #265.🤖 Generated with Claude Code