Skip to content

fix: literalize single-branch extglobs with a leading bare quantifier (CVE-2026-112366) - #238

Open
rborlone wants to merge 1 commit into
micromatch:masterfrom
rborlone:fix/redos-leading-extglob-quantifier-cve-2026-112366
Open

rborlone wants to merge 1 commit into
micromatch:masterfrom
rborlone:fix/redos-leading-extglob-quantifier-cve-2026-112366

Conversation

@rborlone

Copy link
Copy Markdown

Summary

Fixes CVE-2026-112366: a ReDoS vulnerability in repeated extglob parsing.

analyzeRepeatedExtglob (the function that decides whether a +(...)/*(...) extglob is safe to compile as-is, or must be literalized) only flagged a pattern as risky when:

  • the body had multiple branches (branches.length > 1), or
  • a branch was itself a fully parenthesized nested extglob (*(...)) that it could reduce or whose recursion depth it could count.

A single-branch body that starts with a bare (non-parenthesized) * or ? followed by more content — e.g. the *a in +(*a) — fell through both checks. It compiled straight through to a nested-quantifier regex ((?:[^/]*?a)+), which is prone to catastrophic backtracking: matching it against a short crafted string (e.g. many as with no trailing a) blocks the event loop.

makeRe('+(*a)').source
// before: ^(?:(?=.)(?:[^/]*?a)+)$   <- catastrophic backtracking
// after:  ^(?:\+\(\*a\))$           <- literalized, same as other risky extglobs

Fix

Adds hasUnsafeLeadingQuantifier in lib/parse.js, called alongside the existing recursion-depth check inside analyzeRepeatedExtglob's per-branch loop. It flags a branch as risky when it starts with a run of bare */? quantifier characters that is followed by further content, since there's no fixed prefix anchoring where the quantifier ends.

The check is intentionally scoped narrowly, to avoid regressing existing, already-tested behavior:

  • A bare quantifier with nothing after it (+(*)) is left alone — it's not ambiguous in the same way, and is already covered by an existing test (should preserve non-risky extglobs by default).
  • A quantifier anchored by a literal prefix (+(a*), or a quantifier appearing later in the branch behind other content, as in the existing *(W*, *) test in test/special-characters.js) is left alone — the literal prefix removes the ambiguity, and this shape was already relied upon by existing tests.
  • A *(...)/?(...) nested extglob group opener is not treated as a bare quantifier; its own contents continue to be analyzed separately by the existing recursion/char-class-reduction logic above.

Testing

  • Added two test cases to test/options.maxExtglobRecursion.js:
    • +(*a), *(*a), and +(a|*a) are literalized and no longer match a long crafted string that would trigger backtracking.
    • +(*) and +(a*) continue to work as normal globs (no regression).
  • Ran the full existing test suite (npm run mocha) — all 1998 pre-existing tests pass, plus the 2 new ones (2000 total).

Known limitation

A non-reducible nested extglob group followed by trailing content in the same branch (e.g. +(*(ab)c)) is a structurally similar shape that is not covered by this patch, since it wasn't part of the originally reported CVE and widening the check further risked more false positives without being able to verify the exact backtracking behavior empirically. Flagging it, if desired, would need a separate, carefully-scoped follow-up.

…CVE-2026-112366)

analyzeRepeatedExtglob only flagged a repeated extglob (+(...)/*(...)) as
risky when the body had multiple branches, or when a branch was itself a
fully parenthesized nested extglob. A single branch that starts with a bare
(non-parenthesized) * or ? followed by more content, e.g. the *a in +(*a),
slipped through both checks and compiled to a nested-quantifier regex
(e.g. (?:[^/]*?a)+) that is prone to catastrophic backtracking.

Add hasUnsafeLeadingQuantifier to catch this shape and literalize it like
the other risky cases. The check is scoped to a *leading* bare quantifier
with trailing content, so it doesn't affect patterns where the quantifier
has nothing after it (+(*)) or is anchored by a literal prefix (+(a*),
*(W*, *)), which are not ambiguous in the same way and already have test
coverage relying on them working as normal globs.
@andredel85

Copy link
Copy Markdown

Hi, thanks for the work on this fix!

Just adding some context on impact: CVE-2026-112366 (CVSS 8.7) is currently being flagged by corporate SCA scanners (Checkmarx in our case) and is blocking CI pipelines. picomatch 4.x is pulled in transitively by very common tooling like Vite and typescript-eslint, so many projects are affected and can't resolve it on their side until a patched version is on npm.

Is there an expected timeline for merging this PR and publishing a release (e.g. 4.0.8)? If there's anything blocking it, such as review, tests or edge cases, I'm happy to help test the branch against real projects.

Thanks again!

@rborlone

Copy link
Copy Markdown
Author

Hi, thanks for the work on this fix!

Just adding some context on impact: CVE-2026-112366 (CVSS 8.7) is currently being flagged by corporate SCA scanners (Checkmarx in our case) and is blocking CI pipelines. picomatch 4.x is pulled in transitively by very common tooling like Vite and typescript-eslint, so many projects are affected and can't resolve it on their side until a patched version is on npm.

Is there an expected timeline for merging this PR and publishing a release (e.g. 4.0.8)? If there's anything blocking it, such as review, tests or edge cases, I'm happy to help test the branch against real projects.

Thanks again!

Hi, thanks for the context and for offering to help test, it's much appreciated!

I'm not a maintainer, so I can't commit to a merge or release date. The PR is waiting on review from the maintainers. I'll keep it up to date and address any feedback quickly.

In the meantime, testing the branch against a real project would help. If you can try it with your Vite / typescript-eslint setup and share the results here (pass/fail and your Node version), that gives the maintainers more confidence to merge. @doowb @jonschlinkert

As a temporary workaround while waiting for a release, you could pin the transitive dependency with overrides (npm), resolutions (yarn) or pnpm.overrides, once a patched version is available.

Thanks again!

@mouhsineelachbi

Copy link
Copy Markdown

when this fix will be published ?

@franciscoflorencio

franciscoflorencio commented Oct 27, 2026 •

Copy link
Copy Markdown

Hi, thanks for the work on this fix!
Just adding some context on impact: CVE-2026-112366 (CVSS 8.7) is currently being flagged by corporate SCA scanners (Checkmarx in our case) and is blocking CI pipelines. picomatch 4.x is pulled in transitively by very common tooling like Vite and typescript-eslint, so many projects are affected and can't resolve it on their side until a patched version is on npm.
Is there an expected timeline for merging this PR and publishing a release (e.g. 4.0.8)? If there's anything blocking it, such as review, tests or edge cases, I'm happy to help test the branch against real projects.
Thanks again!

Hi, thanks for the context and for offering to help test, it's much appreciated!

I'm not a maintainer, so I can't commit to a merge or release date. The PR is waiting on review from the maintainers. I'll keep it up to date and address any feedback quickly.

In the meantime, testing the branch against a real project would help. If you can try it with your Vite / typescript-eslint setup and share the results here (pass/fail and your Node version), that gives the maintainers more confidence to merge. @doowb @jonschlinkert

As a temporary workaround while waiting for a release, you could pin the transitive dependency with overrides (npm), resolutions (yarn) or pnpm.overrides, once a patched version is available.

Thanks again!

Hey, have you seen "235 (comment)"? I think this PR might not be accepted, do you agree with the comment from the maintainer?

@rborlone

Copy link
Copy Markdown
Author

Hi, thanks for the work on this fix!
Just adding some context on impact: CVE-2026-112366 (CVSS 8.7) is currently being flagged by corporate SCA scanners (Checkmarx in our case) and is blocking CI pipelines. picomatch 4.x is pulled in transitively by very common tooling like Vite and typescript-eslint, so many projects are affected and can't resolve it on their side until a patched version is on npm.
Is there an expected timeline for merging this PR and publishing a release (e.g. 4.0.8)? If there's anything blocking it, such as review, tests or edge cases, I'm happy to help test the branch against real projects.
Thanks again!

Hi, thanks for the context and for offering to help test, it's much appreciated!
I'm not a maintainer, so I can't commit to a merge or release date. The PR is waiting on review from the maintainers. I'll keep it up to date and address any feedback quickly.
In the meantime, testing the branch against a real project would help. If you can try it with your Vite / typescript-eslint setup and share the results here (pass/fail and your Node version), that gives the maintainers more confidence to merge. @doowb @jonschlinkert
As a temporary workaround while waiting for a release, you could pin the transitive dependency with overrides (npm), resolutions (yarn) or pnpm.overrides, once a patched version is available.
Thanks again!

Hey, have you seen "235 (comment)"? I think this PR might not be accepted, do you agree with the comment from the maintainer?

I understand the concern, but this is a real problem for downstream users: SCA tools like Checkmarx flag picomatch 4.x because of this CVE, and that blocks CI pipelines in many projects, since it's pulled in transitively by Vite, typescript-eslint, etc.

If the maintainers believe the CVE doesn't apply (e.g. it's a false positive or the impact is overstated), could that be stated officially? For example, by disputing the advisory on GitHub/NVD so scanners stop flagging it. If it is valid, then a patched release would be the fix.

Either way, some clarity from the maintainers would really help. Thanks!

@rborlone

rborlone commented Nov 4, 2026

Copy link
Copy Markdown
Author

Since the maintainer hasn't responded, I came up with a workaround (not the most elegant): I published the library to our private npm registry and pinned it via a forced override. With this, the Checkmarx scan now passes with no findings.

@ajkessel

Copy link
Copy Markdown

Just chiming in -- this is breaking our CI as well. If this PR isn't the solution, is another patch in the works?

@bradleyseanf

bradleyseanf commented Nov 17, 2026 •

Copy link
Copy Markdown

Tons of CIs failing downstream because of this - Github still stating it's necessary at GHSA-fc5q-39xc-vjpf

@0x00-sys @fal3n-4ngel you are both listed as Credits on this one. Can you help out? They are saying this advisory as revoked as per https://security.snyk.io/vuln/SNYK-JS-PICOMATCH-21248802

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

Tested this locally against master (Node 26, isMatch timing on inputs like 'a'.repeat(n) + '/').

Fixed by this PR: +(*a), *(*a), +(**a), +(*[ab]), +(*a)x and +(a|*a) are now literalized and return instantly (+(a|*a) took ~60 s at n=24 on master). Full suite passes (2000 tests).

Still exponential with this PR:

pattern n=24 n=26 n=28
+(*) 203 ms 782 ms 3063 ms
*(*) 75 ms 309 ms 1216 ms
+(a*) — ~1970 ms —

+(*) is one of the two examples in the advisory text (GHSA-fc5q-39xc-vjpf), so I don't think this closes CVE-2026-112366 on its own. They compile to (?:[^/]*?)+ and (?:a[^/]*?)+, which are the same nested-quantifier shape as (?:[^/]*?a)+. The new test should preserve non-risky leading/trailing quantifiers by default currently asserts the vulnerable behaviour for +(*) and +(a*).

A suggestion: treat any single branch that contains an unanchored bare */? (leading or trailing) as risky. Alternatively, collapse +(*)/*(*) to plain *, since they are semantically equivalent within a segment.

Repro script:

const pm = require('picomatch');
for (const p of ['+(*)', '*(*)', '+(a*)'])
  for (const n of [24, 26, 28]) {
    const t = Date.now(); pm.isMatch('a'.repeat(n) + '/', p);
    console.log(p, n, Date.now() - t, 'ms');
  }

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

We are blocked by this too. Would be great to prioritize this because it seems like there's no version we can fall back to.

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

  • hasUnsafeLeadingQuantifier returns false when the branch is only * (i < branch.length fails), so +(*), the advisory's first example, is left as is. On master that pattern is one of the slow ones above.
  • For +(*a) the branch is marked risky, and with no safeOutput the extglob is emitted as literal text. The new test pins makeRe('+(*a)').source to ^(?:\+\(\*a\))$, so +(*a) would match only the string +(*a), no longer xa. That removes the backtracking by changing what the pattern means. The collapse other PRs use (+(*a) → @(*a)) keeps the meaning.

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

Independent confirmation of the remaining ReDoS case reported in this PR.

In an isolated local test of [email protected] against PR #238 head 44f19226, with an 8-second timeout per subprocess, we observed:

Pattern | Input | Original 4.0.7 | PR #238 -- | -- | -- | -- +(*a) | 40 × a + ! | Timeout | ~2 ms +(*) | 40 × a + / | Timeout | Timeout

The patch addresses +(*a), but +(*) remains vulnerable. Since +(*) is explicitly mentioned in GHSA-fc5q-39xc-vjpf, the current patch does not appear to fully resolve the advisory.

Thank you for working on this fix.

@0x00-sys

Copy link
Copy Markdown

hey, just to clear this up: i didn't find or report this one. my credit on the advisory is only for adding the npm package name + affected range to the github entry (github/advisory-database#10475), so i can't withdraw it or change the score myself, that's up to github and the CNA (VulnCheck).

fwiw the slowdown does reproduce on 4.0.7, but only if someone untrusted controls the glob pattern itself, not the path being matched. if your globs come from your own config you're not really exposed, so ignoring GHSA-fc5q-39xc-vjpf in your scanner is reasonable until this gets sorted. snyk already revoked theirs, the CVE itself is still published.

i've also suggested lowering the severity to moderate on the github advisory since it needs a user-controlled pattern: github/advisory-database#11397. no guarantee they take it, but that's where it is now.

@fal3n-4ngel

fal3n-4ngel commented Nov 18, 2026 •

Copy link
Copy Markdown

Tons of CIs failing downstream because of this - Github still stating it's necessary at GHSA-fc5q-39xc-vjpf

@0x00-sys @fal3n-4ngel you are both listed as Credits on this one. Can you help out? They are saying this advisory as revoked as per https://security.snyk.io/vuln/SNYK-JS-PICOMATCH-21248802

Hey @bradleyseanf,

From my side, I only added the missing npm package to the advisory. I wasn't the one who originally reported it, nor do I have the ability to remove or revoke it. I was facing the same issue with Fortify reporting this vulnerability across our apps as well. However, it looks like it was removed from Fortify few weeks ago.
Maybe the maintainer have reached out to get it revoked.

Hopefully, the other channels will do the same when the source National Vulnerability Database updates / revokes it

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

@yaoweiprc

Copy link
Copy Markdown

Friendly ping for the maintainers: this PR has been open since 2026-10-22 and is mergeable, and the advisory (GHSA-fc5q-39xc-vjpf / CVE-2026-112366) is still unpatched in the latest release (4.0.7, published 2026-08-24).

The impact reaches beyond direct users, because picomatch is also pulled in transitively (e.g. via tinyglobby/node-gyp bundled with npm), so downstream projects and container images keep getting flagged by scanners and can't fix it on their side without a release.

Could someone take a look at this PR (or one of the other open fixes, e.g. #237 / #246) and cut a patched release? Thanks for maintaining the project.

@G-Rath

G-Rath commented Nov 26, 2026

Copy link
Copy Markdown

@yaoweiprc the advisory has been withdrawn

@ajkessel

Copy link
Copy Markdown

Even if this is no longer a CVE, is the fix still a good idea?

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.