Skip to content

fix: collapse single-branch wildcard extglobs (GHSA-fc5q-39xc-vjpf) - #267

Open
Arulraj-a2b wants to merge 1 commit into
micromatch:masterfrom
Arulraj-a2b:fix/redos-single-branch-wildcard
Open

Arulraj-a2b wants to merge 1 commit into
micromatch:masterfrom
Arulraj-a2b:fix/redos-single-branch-wildcard

Conversation

@Arulraj-a2b

Copy link
Copy Markdown

Fixes GHSA-fc5q-39xc-vjpf (CVE-2026-112366).

Problem

A repeated extglob with a single branch that holds a wildcard, such as +(*a), *(*a), +(*)b or +(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. analyzeRepeatedExtglob skipped 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:

  1. Collapse. If the branch P is built only from single-character matchers (literal characters, ?, plain bracket classes that cannot match /) and *, with no slash, then +(P) matches exactly what P matches. 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 matches aaa, +(a*b) still matches abab, +(*)c still matches abc.
  2. Leave as is. Outside bash mode, if the branch has a literal /, each repeat has to start after a slash that * cannot cross, so the repeat cannot backtrack. For example, +(src/*/) is unchanged.
  3. Risky. Any other shape, for example +(@(*a)), or bash mode where * crosses /, is literalized like the existing risky patterns +(a|aa) and +(+(a)). maxExtglobRecursion: false still opts out.

Tests

test/redos-single-branch-wildcard.js:

  • Runs 13 attack patterns × 6 option sets against 50,000-character inputs in a child process with a deadline, so a hang fails the test instead of freezing mocha.
  • Checks the collapsed regex output.
  • Checks that matching is unchanged across dot, windows, bash and nocase, that * still does not cross / outside bash mode, and that escaped, quoted and bracketed stars and slash-delimited repeats behave as before.

npm test passes: lint plus 2004 tests on master. The same change is in a separate PR against v2, where 1978 tests pass; v2's lint already fails on master in test/dotfiles.js and test/special-characters.js.

Before → after on 'a'.repeat(28) + '/': +(*a) 21.7 s → 1 ms, *(*a) 27.0 s → 0 ms, +(a*)b 11.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.

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.
BYK added a commit to getsentry/craft that referenced this pull request Nov 18, 2026
Fixes the two high advisories in the root and `docs/` lockfiles.


**[GHSA-mrhx-c7xc-m3w5](GHSA-mrhx-c7xc-m3w5)
(zod < 4.6.6), root.** zod 3 came only from `@vercel/client >
@vercel/build-utils@14 > @vercel/python-analysis`.
`@vercel/client@^18.12.3` uses `@vercel/[email protected]`, which no
longer depends on python-analysis, so zod drops out of the tree. A zod
override would force zod 4 onto zod 3 code. The `createDeployment` API
that the vercel target uses has not changed.


**[GHSA-fc5q-39xc-vjpf](GHSA-fc5q-39xc-vjpf)
(picomatch ReDoS), root and docs.** There is no fixed release. Following
the `braces` precedent, this adds local pnpm patches for both installed
versions, 4.0.7 and 2.3.2. 2.3.2 has the same bug. The advisory links
micromatch/picomatch#194, but that PR covers `?`-leading extglobs and
does not fix `+(*a)`. The patches backport micromatch/picomatch#267
(#268 for 2.x):
- A single wildcard branch made of literals, `?`, `*`, and bracket
classes that cannot match `/` absorbs its own repetition. `+(P)`
compiles as `(P)` and `*(P)` as `(P)?`, and the matches stay the same.
- Other single-branch wildcard bodies are literalized, like the existing
risky-extglob guard.

The patch differs from upstream in one place. Upstream would collapse a
bracket range like `[+-0]`, which includes `/`, and that changes what it
matches. The patch checks each compiled bracket class first. Details are
in `patches/README.md`.

**After merge:** Dependabot matches on version, so it will keep flagging
the patched picomatch 4.0.7 and 2.3.2, as it already does for braces.
Dismiss those alerts by hand.

**Not covered:** repeated extglobs with several branches that contain
`*`, such as `+(*a|b)`. That is the general upstream issue
micromatch/picomatch#175. Literalizing them would break globs like
`+(*.js|*.ts)`.

<!-- junior-request-attribution:start -->
via @BYK.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:agent%3Aa3f271eaa645c4e79ce41158088ba41e -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/agent%3Aa3f271eaa645c4e79ce41158088ba41e)
[[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3Aa3f271eaa645c4e79ce41158088ba41e/?project=4510944073809921)

<!-- junior-session-footer:end -->

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: BYK <[email protected]>
Co-authored-by: Burak Yigit Kaya <[email protected]>
@matthewrball

Copy link
Copy Markdown

Downstream compatibility check for this change and #268: I tested the parser at d9a3f12 on the published 4.0.7 package and at e2e3342 on 2.3.2, using Deno 2.9.6 in Node compatibility mode. The standard oclif command discovery and exclusion globs still included .js and .tsx commands, skipped .md, and excluded .test.tsx, .spec.js, and .d.cts files. All seven ordinary filename checks passed on each major. This checks CLI compatibility only, not security coverage or the full test suite.

@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