Skip to content

fix: CVE-2026-112366 prevent ReDoS in single-branch repeated extglobs - #237

Open
seeibt wants to merge 1 commit into
micromatch:masterfrom
seeibt:fix/redos-single-branch-extglob
Open

seeibt wants to merge 1 commit into
micromatch:masterfrom
seeibt:fix/redos-single-branch-extglob

Conversation

@seeibt

@seeibt seeibt commented Oct 22, 2026 •

Copy link
Copy Markdown

Summary

Fixes GHSA-fc5q-39xc-vjpf / CVE-2026-112366.

analyzeRepeatedExtglob skipped single-branch repeated extglobs such as +(*) or +(*a), so they compiled to nested unbounded quantifiers (e.g. (?:[^/]*?a)+), causing exponential backtracking on short inputs.

Fix

A single branch containing a top-level * (with no /, groups, alternation, nested extglobs or globstar) absorbs its own repetition, so:

  • +(P) → (?:P)
  • *(P) → (?:P)?

These are semantically equivalent and remove the nested quantifier. Other cases keep the existing risky-extglob handling. The rewrite is skipped when maxExtglobRecursion: false.

Pattern Before After
+(*a) (?:[^/]*?a)+ (?:[^/]*?a)
*(*a) (?:[^/]*?a)* (?:[^/]*?a)?

Before the fix, matching 'a'.repeat(24) + 'b' against +(*a) took ~107ms and doubled with each extra char. With the fix it takes ~0ms.

Tests

Added cases in test/options.maxExtglobRecursion.js covering:

  • no nested quantifiers in the generated regex
  • a timing bound on malicious input
  • matching semantics preserved (+(*)c, +(*a), +(a*b), *(*.js))

All 1999 tests pass.

@lppedd

lppedd commented Oct 22, 2026

Copy link
Copy Markdown

See #235 (comment).

@jlopez2-atl

Copy link
Copy Markdown

Hi, thanks for working on this fix for CVE-2026-112366.

Is there a rough timeline for merging this and cutting a release? Every published version up to 4.0.7 is still flagged, so for now we’re applying this change as a local patch.

Could the fix also be released for the 2.x line? anymatch, micromatch, and readdirp still depend on picomatch@^2, so a 4.x release alone won’t reach most installs.

CuiGuidong pushed a commit to CuiGuidong/peach that referenced this pull request Nov 18, 2026
在 npm 原版 4.0.7 上回移 Eduardo Seibt 的解析器变更。将修复包、MIT 许可证、来源补丁与完整性摘要固定在前端开发依赖中。Vite、Vitest、tinyglobby 和 fdir 均解析到同一修复包。

Source-PR: micromatch/picomatch#237
Original-Commit: 1bf0d04563cb9ce568cf36efc5f6b7187d9911d5
Co-Authored-By: Codex (GPT-6.2 Sol) <[email protected]>
ry-morris added a commit to Moonaan/picomatch that referenced this pull request Nov 18, 2026
Upstream micromatch#237 collapses +(P) to (P) for any single star branch. That changes
results when P can match a slash or is not a glob star (Devin Review on #1):
+(*\/) on a/b/, +("*") on **, +([ab]*c) with regex:true on acbc, and
+(*[/]) / +(*[[:punct:]]) / +(*[.-0]) on x//. Skip the collapse in exactly
those cases (escaped slash, quotes, regex mode, a bracket that can match /),
keeping 4.0.7's output for them. Generated differential against 4.0.7: 0
mismatches.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ry-morris added a commit to Moonaan/picomatch that referenced this pull request Nov 18, 2026
fix: CVE-2026-112366, publish @moonaan/picomatch 4.0.8-moonaan.1 (4.0.7 + upstream micromatch#237)
@Kanevry

Kanevry commented Nov 18, 2026

Copy link
Copy Markdown

Disclosure: this analysis was prepared with an AI assistant (Claude). Every measurement below was actually run and can be reproduced with the snippets given. Setup: PR head 1bf0d04 checked out detached, base master 9fab7bf, Node 24.22.3 on macOS arm64. The timing input is 'a'.repeat(n) + '!'.

A run confirms the single-branch collapse from the comment above. With n=200, +(*a), *(*a), +(*)c and +(*[ab]) each return in about 1 ms on this branch. On master, +(*a) takes 5.5 s at n=28. +(*)c takes 11 s at n=26 (cut off at 12 s).

Two inputs change their result relative to master:

const pm = require('picomatch');

// 1. A quoted star is literal, but the branch is still collapsed:
pm.makeRe('+("*a")').source;                                   // '^(?:(?=.)(?:\\*a))$'
pm.isMatch('*a*a', '+("*a")');                                 // false on this branch, true on master
pm.isMatch('*a*a', '+("*a")', { maxExtglobRecursion: false }); // true

// 2. [[:punct:]] contains "/", so the star can no longer absorb the repetition:
pm.isMatch('a/b/', '+(*[[:punct:]])');                                 // false on this branch, true on master
pm.isMatch('a/b/', '+(*[[:punct:]])', { maxExtglobRecursion: false }); // true

pm.isMatch('a/b/', '+(*[.-0])') behaves the same way, since the range .-0 includes /.

The collapse is only equivalent when every * is a real glob star and no token in the branch can match a slash. isSelfRepeatingStarBranch does not track quotes. It also skips every bracket expression. Negated brackets are not affected: +(*[^a]) gives the same result with and without the guard, because it already compiles to [^a/]. Possible fixes:

  • Treat " like the other excluded characters.
  • Skip brackets that contain a POSIX class or a range, or skip brackets entirely.

Equivalence check. I compared .test() on the default regex and on the maxExtglobRecursion: false regex.

  • Inputs: every string up to length 5 over a . / b (1,365 strings).
  • Patterns: 14 star-shaped single-branch patterns, including x+(*a)y, a/+(*a), .+(*a) and +(*)c.
  • Options: bash, bash+dot and capture.

That is 57,330 comparisons, with no differences. The two cases above are not in this set, because it has no quotes and no brackets.

With capture: true, exec() does differ. The inner star group now holds the whole match instead of the last repetition. For +(*) on aa the result is ['aa', 'aa', 'aa'], against ['aa', 'aa', 'a'] unguarded. That may deserve a line in the changelog.

Still exponential on this branch at n=28: +(*a|b) takes 6.0 s and +(*(a)a) takes 6.3 s. At n=24 and n=26 each takes about 0.4 s and 1.5 s. The review comment above already covers multi-branch patterns with +(*a|*b). +(*a|b) differs in that not every branch starts with a star. +(*(a)a) is a single branch whose star is an extglob, not a plain *.

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

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