Repository navigation
fix: compile a repeated extglob whose single branch absorbs its repetition once (GHSA-fc5q-39xc-vjpf) - #270
Conversation
…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.
|
@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 |
|
I tested this PR at
Both should return Save as 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 });
} |
|
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. |
What: Single-branch repeated extglobs containing
*, such as+(*),+(*a),*(*a),+(*a*)and+(a*b), compile to a nested quantifier (e.g.(?:[^/]*?a)+). They skipanalyzeRepeatedExtglob's checks, so a near-miss input backtracks exponentially. On currentmaster, 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 markedcollapseand 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:
a b . x / * ?, for 29 patterns and 5 option sets: 19,902,265 cases, identical results to the unmodified parser.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).