Skip to content

fix: mitigate repeated extglob ReDoS patterns (CVE-2026-112366) - #260

Open
mmatteuus wants to merge 3 commits into
micromatch:masterfrom
mmatteuus:fix/cve-2026-112366-repeated-extglob
Open

mmatteuus wants to merge 3 commits into
micromatch:masterfrom
mmatteuus:fix/cve-2026-112366-repeated-extglob

Conversation

@mmatteuus

@mmatteuus mmatteuus commented Nov 17, 2026 •

Copy link
Copy Markdown

Summary

Targeted mitigations for repeated extglob ReDoS patterns related to CVE-2026-112366 / GHSA-fc5q-39xc-vjpf. This is not a claim that arbitrary user-controlled globs are safe from catastrophic backtracking.

  • Collapse selected repeated single-branch extglobs with an ordinary * when the outer repetition is redundant.
  • Handle simple repeated-star alternatives and bracket classes through constrained rewrites, retaining a conservative fallback when safe equivalence is not established.
  • Detect nested quantified extglobs after literal text.
  • Remove redundant repeated alternatives for recognized cases such as *(a*(ba)|a), *(ab*(a)|ab), and *(a*(ba)|A) with nocase: true.
  • Preserve the explicit maxExtglobRecursion: false safeguard opt-out.

Latest contribution: d10c0e5003aabed2d81427dd6c125af50bf920ab. Only lib/parse.js and test/options.maxExtglobRecursion.js are changed.

Local reproduction and tests

Potentially pathological inputs were exercised in timeout-bounded subprocesses; regression tests reproduced the problems before the corresponding local fixes.

On Node 24.22.1, in the isolated VPS checkout:

  • npm test: 2,023 passing (includes ESLint); git diff --check: PASS.
  • 1,467,144 differential matching comparisons across the tested patterns, strings, and non-capture options without observed divergences.
  • 25/25 bounded long-input adversarial scenarios completed without timeouts in that environment.

These are scoped local results, not universal security proof or upstream maintainer approval. GitHub-hosted CI was not used as the validation basis.

Known limitations / review required

  1. More complex or attacker-controlled glob patterns may still trigger excessive backtracking. This patch is a partial mitigation, not complete ReDoS prevention.
  2. capture: true and conservative literal fallback can change matching or capture semantics in certain cases; please review and explicitly decide whether these tradeoffs are acceptable.
  3. maxExtglobRecursion: false intentionally disables the safeguard. The affected v2.x line requires separate assessment.
  4. Merging this PR, publishing a patched npm release, and updating the advisory are separate maintainer actions. No official patched version is implied by this PR.

Related: #237, #238, #246 and #247.

@mmatteuus

Copy link
Copy Markdown
Author

Technical follow-up review of #260 (author-side validation; not maintainer approval):

Targeted mitigation: PASS. Local npm run mocha 2,001 passing, npm run lint and git diff --check passed. Differential testing exercised 3,549,910 pattern/input/option combinations without detected changes to matching results in the tested non-capture configurations. On Node 24.22.1, +(*), +(*a) and +(a*) now complete in ~6-7ms for crafted nonmatching n=24 inputs.

Two limitations still require review:

  1. HIGH — Multi-branch ReDoS remains. The guard at lib/parse.js:309 requires branches.length === 1. After this patch, +(*a|b), +(a*|b) and *(a*|b) still take approximately 898ms / 671ms / 692ms on 'a'.repeat(24)+'/' (versus ~10ms at n=16). This patch alone is not a complete remediation of CVE-2026-112366. We need a separate reviewed fix or explicit maintainer/advisory decision before saying the CVE is resolved.
  2. Compatibility — capture: true intentionally literalizes some expressions. For example, isMatch('aaa','+(*a)',{capture:true}) changes from true to false. This is a conservative safety tradeoff, but merits explicit maintainer acceptance and prominent documentation.

The PR is intentionally scoped to single-branch forms. This review is provided to make its limits clear, not to self-approve it or claim the official npm release is patched. No GitHub CI or deploy was run.

@DaleMckeown

Copy link
Copy Markdown

See #235 (comment).

@mmatteuus

Copy link
Copy Markdown
Author

Follow-up to the earlier security review: the PR head has been updated to f22674d. The previously reported HIGH multi-branch ReDoS cases +(a|b), +(a|b), and (a|b) are now handled with bounded, semantics-preserving rewrites for simple alternatives. The additional single-branch bracket-class bypasses +([ab]) and +(a[ab]) are also covered. Complex patterns that cannot be rewritten safely use the existing conservative literal fallback. Local isolated QA: npm test 2,006/2,006 PASS, lint PASS, git diff --check PASS; differential matching 843,696 alternative cases, 374,976 bracket-class cases, and 326,585 bracket-literal cases without mismatches in the tested configurations. This does not prove all arbitrary glob patterns are ReDoS-free. capture: true and conservative fallback can intentionally change matches; maintainer review and documentation of that tradeoff remain necessary. No upstream merge, npm release or CONSUBOV dependency update was performed.

@mmatteuus

Copy link
Copy Markdown
Author

Additional author-side review of the current PR head f22674d found two remaining performance failures. This is a technical report, not an upstream security approval or claim about fixed/trusted glob patterns.

  1. Nested extglob bypass: hasUnescapedStar in lib/parse.js:287-304 deliberately skips *(...), but repetitions prefixed by text escape the later recursion test. In isolated Node 24.22.1 subprocesses, +(a*(a)) took ~168ms at n=22 on nonmatching 'a'.repeat(n)+'/'. +(a*(ab)|b) and +(a?(ab)|b) timed out after 440ms at n=22 on 'aab'.repeat(n)+'/'.
  2. Superlinear output from a "safe" rewrite: safeStarAlternation in lib/parse.js:309-356 turns +(a*[ab]|a) into a regex with overlapping quantifiers. On 'a'.repeat(n)+'/', it took ~9ms at n=128, ~171ms at n=512, and timed out after 1,100ms at n=2048. Same for +(a*[a-z]|a).

npm test still passes 2,006/2,006 and lint passes, but those tests do not cover these inputs. Test runs were timeout-bounded and the reported timing is environment-specific. The availability risk arises when untrusted actors can influence glob expressions and triggering inputs; this does not establish an issue for every application using trusted patterns.

My recommendation is to keep this PR scoped as an incomplete mitigation, add failing regression tests for these cases, and avoid calling CVE-2026-112366 fully addressed by the current commit. The capture:true literal-fallback compatibility change also still requires maintainer consideration.

@msalaheldincontractor-wsl

Copy link
Copy Markdown

Reviewed from the diff; I did not run this branch. For reference, on master (9fab7bf, Node 22) each of +(*), +(*a), *(*), *(*a), +(*)a and the two-branch +(*a|*b) takes more than 3 s for isMatch('a'.repeat(28) + '/', pattern).

  • The single-branch collapse covers +(*), +(*a), *(*), *(*a) and +(*)a.

  • Several paths end in { risky: true } without a safeOutput, and extglobClose then emits the extglob as literal text, which changes what matches:

    • any multi-branch body with a star, unless safeStarAlternation handles it. It only builds output for one starred branch with alphanumeric parts plus single-character literals, so for example +(*a|*b) and +(*.js|*.ts) would match only their own literal strings, no longer xa or a.js;
    • with capture: true, the collapsible single-branch case as well (+(*a) → literal).

    A rewrite that keeps the meaning for those cases (for multi-branch, collapsing when every branch is star-led, as in fix: drop redundant repetition from star-led repeated extglobs #257) would avoid the behaviour change.

@VlaSou VlaSou left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this. This addresses GHSA-fc5q-39xc-vjpf, which currently affects our development toolchain through [email protected]. We can test against this branch, but an official patched release would be preferable to carrying a Git-based override. Could you confirm whether you expect to publish a patched 4.x release after merge, and whether the 2.x line will receive a separate fix?

@nexis-agent

Copy link
Copy Markdown

Downstream validation report: Node.js v24.14.1, picomatch 4.0.7. I applied this fix from commit f22674d using pnpm patchedDependencies. With input made from 128 repeated a characters followed by a slash, these non-matching patterns all returned false in a child process with a 2-second timeout: +(*), (), +(*a), (a), +(a), (a), +(a?), x+(*a)y, +(a|b), +(a|b). Selected short-input matching checks also matched the maxExtglobRecursion:false baseline. The package-manager audit still reports GHSA-fc5q-39xc-vjpf for version 4.0.7 because no patched release is published yet. This patch is a useful temporary mitigation, but an official patched 4.x release is needed for downstream consumers to clear the advisory cleanly. Thanks for the fix.

@mmatteuus mmatteuus changed the title fix: collapse repeated single-branch star extglobs (CVE-2026-112366) fix: mitigate repeated extglob ReDoS patterns (CVE-2026-112366) Nov 17, 2026
@nexis-agent

Copy link
Copy Markdown

Scope clarification for my downstream report above: the checks covered only the listed patterns and are not a comprehensive ReDoS assessment. They do not cover the nested-extglob and overlapping-quantifier counterexamples reported elsewhere in this PR. I am not treating the advisory as resolved; our audit still reports the vulnerable 4.0.7 version.

@safwanhakim-iconix

Copy link
Copy Markdown

any eta to fix ? my cto dont want to approve my PR because of this :'(

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

@safwanhakim-iconix

Copy link
Copy Markdown

any eta to fix ? my cto dont want to approve my PR because of this :'(

thank you guys, appreciate it <3

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.

7 participants