Repository navigation
[v2] fix: collapse single-branch wildcard extglobs (GHSA-fc5q-39xc-vjpf) - #268
Arulraj-a2b wants to merge 1 commit into
Conversation
A repeated extglob whose single branch holds a wildcard, such as +(*a) or +(a*)b, nested an unbounded quantifier and backtracked exponentially. A branch made of single-character matchers and * now collapses (+(P) -> (P), *(P) -> (P)?), slash-delimited repeats are left alone, and other wildcard shapes are literalized like the existing risky patterns.
|
I tested this PR at
The rationale that a slash fixes each repetition boundary does not hold when the branch contains a globstar that can cross slashes. Could this shape be covered before treating the single-branch wildcard cases as addressed? Save as const cases = [['+(**/a)b', 'a/'.repeat(40) + 'a']];
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 });
} |
|
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. |
Back-port of #267 to the 2.x line (2.3.2 is still widely resolved, for example via micromatch 4).
Fixes GHSA-fc5q-39xc-vjpf (CVE-2026-112366).
Problem
A repeated extglob with a single branch that holds a wildcard, such as
+(*a),*(*a),+(*)bor+(a*)b, compiles to a nested unbounded quantifier like(?:[^/]*?a)+. Matching it against a short non-matching string backtracks exponentially. On 4.0.7,+(*a)takes about 20 s on 28 characters.analyzeRepeatedExtglobskipped these bodies because it only looked at multi-branch alternations and nested*(...)sequences.Fix
In
analyzeRepeatedExtglob, a single branch with a wildcard (found from the parser's own tokens, so escaped\*, quoted"*", bracketed[*]and the*of a nested*(...)do not count) is handled in one of three ways:?, plain bracket classes that cannot match/) and*, with no slash, then+(P)matches exactly whatPmatches. The first*absorbs every later repeat. So+(P)becomes(P)and*(P)becomes(P)?, and no nested quantifier is left. Matching is unchanged:+(*a)still matchesaaa,+(a*b)still matchesabab,+(*)cstill matchesabc./, each repeat has to start after a slash that*cannot cross, so the repeat cannot backtrack. For example,+(src/*/)is unchanged.+(@(*a)), or bash mode where*crosses/, is literalized like the existing risky patterns+(a|aa)and+(+(a)).maxExtglobRecursion: falsestill opts out.Tests
test/redos-single-branch-wildcard.js:dot,windows,bashandnocase, that*still does not cross/outside bash mode, and that escaped, quoted and bracketed stars and slash-delimited repeats behave as before.npm testpasses: lint plus 2004 tests onmaster. The same change is in a separate PR againstv2, where 1978 tests pass;v2's lint already fails on master intest/dotfiles.jsandtest/special-characters.js.Before → after on
'a'.repeat(28) + '/':+(*a)21.7 s → 1 ms,*(*a)27.0 s → 0 ms,+(a*)b11.9 s → 0 ms.Related open PRs for the same advisory: #257–#266. This one keeps the change small (one function plus the close quantifier) and changes matching only for the risky shapes. Happy to fold it into whichever one you prefer.