Skip to content

[v2] Guard single-branch repeated-star extglobs against ReDoS - #246

Open
sxnistxr wants to merge 1 commit into
micromatch:v2from
sxnistxr:fix/v2-single-branch-extglob-redos
Open

sxnistxr wants to merge 1 commit into
micromatch:v2from
sxnistxr:fix/v2-single-branch-extglob-redos

Conversation

@sxnistxr

Copy link
Copy Markdown

Repeated single-branch star extglobs such as +(*a) and *(*a) still compile to nested unbounded quantifiers on v2/2.3.2. Short non-matching inputs can block the event loop. This affects the 2.x line used by micromatch 4 and downstream file watchers.

This is a focused 2.x adaptation of the collapse approach proposed by @seeibt in #237. Existing #237 and #238 target master; this PR targets v2.

For a single branch consisting of literals and ordinary stars, the branch's star can absorb subsequent repetitions. Remove the redundant outer +, or replace the outer * with optionality. Thus +(*a) becomes one *a branch and *(*a) becomes an optional *a branch. Exclude quoting, escapes, paths, globstars and other glob/regex syntax from this rewrite. maxExtglobRecursion: false retains the existing opt-out.

Capture mode needs special treatment: collapsing changes the final repeated capture. In that mode, use the existing risky-extglob literal fallback, rather than returning a subtly different capture or retaining the expensive expression. This deliberately changes capture-mode matching for the affected patterns, consistently with the existing safeguard for other risky extglobs.

Regression coverage:

  • Generated regexes no longer contain the outer unbounded repetition for the covered shapes.
  • Long non-matching inputs run in a subprocess with a deadline, so regressions cannot hang the suite.
  • Matching results are compared with the previous behavior on short inputs under default, dot, Windows and Bash options.
  • Quoted/escaped stars and other excluded syntax retain their prior regexes; capture fallback and the explicit safeguard opt-out are checked.

Validation: all 1,976 tests pass on Node 22.16.0 and Bun 1.4.3; ESLint passes for both changed files. Full npm test stops at three pre-existing space-before-function-paren errors in untouched test/dotfiles.js (227, 294) and test/special-characters.js (235).

Related: CVE-2026-112366, #234, #239, #237. This handles the simple single-branch star forms in the public report; it is not a claim that arbitrary user-supplied glob/regex syntax is free of all ReDoS risks. No release/version bump is included.

@pday-kyc360

Copy link
Copy Markdown

Any updates on this?

@sxnistxr

sxnistxr commented Nov 5, 2026

Copy link
Copy Markdown
Author

Any updates on this?

still waiting on approval from a maintainer :(

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

3 participants