Skip to content

fix: bound repeated wildcard extglobs - #262

Open
jscraik wants to merge 1 commit into
micromatch:masterfrom
jscraik:codex/fix-repeated-wildcard-redos
Open

jscraik wants to merge 1 commit into
micromatch:masterfrom
jscraik:codex/fix-repeated-wildcard-redos

Conversation

@jscraik

@jscraik jscraik commented Nov 17, 2026

Copy link
Copy Markdown

Summary

Fix repeated wildcard extglobs that still emit nested unbounded quantifiers, including the public CVE-2026-112366 examples and alternative-branch/parser-option bypasses. Classify wildcard tokens from the actual parser so unmatched brackets and nobracket agree with compilation.

Remove redundant repetition for a restricted ordinary single-star branch. Preserve the existing *(a*|b) and */*(W*, *)* matches with restricted, unambiguous normalisations: disjoint trailing-star alternatives and a two-star branch whose first middle literal terminates a tempered character loop. Honour effective case-insensitive flags when proving alternatives disjoint. Complex unsupported shapes continue through the existing literal fallback; maxExtglobRecursion: false remains an explicit opt-out. No package version or unrelated matcher code changes.

Testing

  • Command: npm test -> pass (ESLint and 2,001 tests, including three new regression cases).
  • Command: npm run test:ci -> pass (full suite with coverage).
  • Command: git diff --check -> pass.
  • New regression tests run matching in a child process with a two-second kill deadline, including direct repeated stars, alternatives, nested wildcards, unmatched brackets, nobracket, case folding and multiple-star regression cases.
  • Independent read-only review of the shared v2/v4 algorithm passed 3,657,752 boolean comparisons and 16 bounded adversarial subprocesses; no remaining actionable findings after correcting the reported parser and case-folding issues. These are finite tests, not a formal ReDoS proof.

Compatibility and scope

The existing upstream tests are unchanged, including the two matching cases that a broader literalisation approach broke. Unsafe capture or unsupported wildcard alternatives intentionally retain the existing safeguard's literal-fallback semantics; this does not claim arbitrary glob/regex syntax or the explicit opt-out is safe. This PR does not publish a fixed version or claim advisory-database clearance.

AI assistance: Codex authored this patch at the rSearch maintainer's request; a separate read-only Codex reviewer inspected it.

Use actual parser tokens to detect wildcard branches and prevent nested
unbounded repetition, including alternative and bracket-option bypasses.
Preserve existing ordinary matching with restricted safe normalisations.

Behavior Proof: regression matching runs in a child with a two-second kill
limit. Direct, nested, alternative, bracket and case-folding cases complete;
existing compatibility tests remain unchanged. npm test -> pass (lint and
2001 tests). git diff --check -> pass. Independent algorithm review found
no remaining actionable issues after 3657752 comparisons and 16 bounded
subprocesses. Finite testing does not prove arbitrary regexp syntax safe.
Explicit opt-out and unsupported-pattern literal fallback are retained.
No release version or advisory metadata is changed.

Co-authored-by: Codex <[email protected]>
@DaleMckeown

Copy link
Copy Markdown

Man this is relentless. See #235 (comment).

@tsctupper tsctupper 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 validation of head 3222059ac27492d9c0147fee5c65f751bbd851ab against master 9fab7bf61913ea334c4203ed321c426cfde44a42 on macOS arm64, Node v22.23.4:

  • npm test passed, including ESLint and all 2,001 tests.
  • 1,329,660 boolean comparisons against the base parser returned zero differences for a selected corpus of 20 normalization patterns and nine option sets. Patterns included +(*), *(*), +(*a), *(*a), +(a*), *(a*), +(a*b), *(a*b), x+(*a)y, +(*)c, *(a*b)c, whitespace branches, *(a*|b), +(a*|b), +(ab*|c|d), *(ab*|c|d), +(A*|b), +(W*, *), and *(W*, *). Options covered default, dot, windows, bash, nocase, flags i, flags s with bash, contains, and matchBase. Inputs were all strings of length 0–4 over a,b,A,c,/,backslash,.,!,newline, plus six longer targeted strings.
  • 35 isolated adversarial cases passed a 2-second process deadline and a 128 MB V8 heap limit. Each exercised the matcher, makeRe, and parse → compileRe APIs. The seven families were +(*), *(*a), +(*a|b), +(a*a*a*a*a*), malformed +([*a), +([*a]), and +(W*, *)z, each with default/windows/bash/capture/nobracket options, against long failing inputs (up to 60,001 characters). No child timed out or exited unsuccessfully.

These are bounded regression checks, not a proof of safety for every pattern. The parity corpus intentionally covers the supported normalization cases; it does not imply preserved matching semantics for the complex forms deliberately sent through literal fallback. I also understand that maxExtglobRecursion: false remains an explicit opt-out, so this review does not claim that option is protected. Capture and fallback behavior are covered by the PR's own regression tests as well as the deadline cases above.

Thanks for working on this. This looks like a useful candidate for maintainer review of GHSA-fc5q-39xc-vjpf / CVE-2026-112366. Could a maintainer review the chosen compatibility/fallback behavior and, if acceptable, merge it and publish a patched release so downstream consumers can replace temporary restrictions with a maintained fix?

@tsctupper

Copy link
Copy Markdown

Reproduction script for my independent validation at head 3222059ac27492d9c0147fee5c65f751bbd851ab. This is supplemental review evidence, not part of the proposed implementation.

Run with Node 22.23.4 as node review.cjs /path/to/base /path/to/pr-head after installing each public picomatch checkout. The base checkout runs only the short parity corpus; the long adversarial inputs run only against the candidate. The review above states the finite-corpus, fallback and opt-out limitations.

Standalone corpus and deadline checks
'use strict';
const assert = require('node:assert/strict');
const { spawnSync } = require('node:child_process');
const baseline = require(process.argv[2]);
const candidate = require(process.argv[3]);
const patterns = [
  '+(*)', '*(*)', '+(*a)', '*(*a)', '+(a*)', '*(a*)',
  '+(a*b)', '*(a*b)', 'x+(*a)y', '+(*)c', '*(a*b)c',
  '+( a*)', '+(a* )', '*(a*|b)', '+(a*|b)',
  '+(ab*|c|d)', '*(ab*|c|d)', '+(A*|b)',
  '+(W*, *)', '*(W*, *)'
];
const options = [{}, { dot: true }, { windows: true }, { bash: true },
  { nocase: true }, { flags: 'i' }, { flags: 's', bash: true },
  { contains: true }, { matchBase: true }];
const alphabet = ['a', 'b', 'A', 'c', '/', '\\', '.', '!', '\n'];
let inputs = [''];
let level = [''];
for (let length = 1; length <= 4; length++) {
  level = level.flatMap(prefix => alphabet.map(char => prefix + char));
  inputs.push(...level);
}
inputs.push('W, ', 'W, W, ', 'xaaaay', 'cccabcccc', 'abab', 'aaa');
let comparisons = 0;
const differences = [];
for (const pattern of patterns) {
  for (const opts of options) {
    const before = baseline(pattern, opts);
    const after = candidate(pattern, opts);
    for (const input of inputs) {
      comparisons++;
      const expected = before(input);
      const actual = after(input);
      if (actual !== expected && differences.length < 15)
        differences.push({ pattern, options: opts, input, expected, actual });
    }
  }
}
console.log(JSON.stringify({ comparisons, differences }));
assert.equal(differences.length, 0);

const attacks = [
  ['+(*)', 'a'.repeat(60000) + '/'],
  ['*(*a)', 'a'.repeat(60000) + '!'],
  ['+(*a|b)', 'a'.repeat(60000) + '!'],
  ['+(a*a*a*a*a*)', 'a'.repeat(60000) + '/'],
  ['+([*a)', '[a'.repeat(10000) + '!'],
  ['+([*a])', '[a]'.repeat(10000) + '!'],
  ['+(W*, *)z', 'W, '.repeat(10000) + '!']
];
let boundedCases = 0;
for (const [pattern, input] of attacks) {
  for (const opts of [{}, { windows: true }, { bash: true }, { capture: true }, { nobracket: true }]) {
    const script = `const pm=require(process.argv[1]);const [pattern,input,options]=JSON.parse(process.argv[2]); for(const method of ['matcher','makeRe','parse']) { const re=method==='matcher'?null:method==='makeRe'?pm.makeRe(pattern,options):pm.compileRe(pm.parse(pattern,options),options); if(re) re.test(input);else pm(pattern,options)(input); }`;
    const child = spawnSync(process.execPath, ['--max-old-space-size=128', '-e', script,
      process.argv[3], JSON.stringify([pattern, input, opts])], {
      env: { PATH: process.env.PATH }, encoding: 'utf8', timeout: 2000,
      killSignal: 'SIGKILL', maxBuffer: 8192
    });
    assert.equal(child.error, undefined, JSON.stringify({ pattern, opts, error: child.error?.code }));
    assert.equal(child.status, 0, child.stderr);
    boundedCases++;
  }
}
console.log(JSON.stringify({ boundedChildCases: boundedCases, apisPerChild: 3, node: process.version }));

jakkaj added a commit to AI-Substrate/pij-fleet that referenced this pull request Nov 18, 2026
…fix plan

Jordan: fix the dependency, the allowlist is only the stopgap. The
expiry is the fixed release plus the 7-day npm quarantine, and the
reason names the open upstream fixes (micromatch/picomatch#262-#266)
and the follow-up: a package.json override to ^4.0.8, re-locked, audit
clean, deleting this entry in the same PR.

Pij-Seat: pij-previous-firefly
Pij-Prime: pij-far-jackal
jakkaj added a commit to AI-Substrate/pij-fleet that referenced this pull request Nov 18, 2026
…xed allowlist for GHSA-fc5q-39xc-vjpf (#236)

* ci(deps): time-boxed audit allowlist for GHSA-fc5q-39xc-vjpf

npm audit fails every PR on picomatch <=4.0.7 (high, ReDoS through
single-branch repeated extglobs). It is dev-only (vitest > vite /
tinyglobby / fdir) and only ever matches repo-authored test globs, never
untrusted input. There is no fix to take: as of 2026-11-18 the latest
release is 4.0.7 and the GitHub advisory API says patched: null.

.github/audit-allowlist.json gets one entry naming the advisory, the
reason and an expiry; the expired entry fails the gate, so the exception
cannot outlive 2026-12-18. Proven: the gate exits 1 on main, 0 with the
entry, and 1 again with the entry expired.

Pij-Seat: pij-previous-firefly
Pij-Prime: pij-far-jackal

* ci(deps): GHSA-fc5q-39xc-vjpf entry expires 2026-12-02 and names the fix plan

Jordan: fix the dependency, the allowlist is only the stopgap. The
expiry is the fixed release plus the 7-day npm quarantine, and the
reason names the open upstream fixes (micromatch/picomatch#262-#266)
and the follow-up: a package.json override to ^4.0.8, re-locked, audit
clean, deleting this entry in the same PR.

Pij-Seat: pij-previous-firefly
Pij-Prime: pij-far-jackal

* ci(deps): the audit gate fails closed when npm audit did not run

harness/scripts/audit-gate.mjs read a registry error as a clean audit.
A 429 from the registry proxy makes `npm audit --json` print
{message, statusCode, error} with no vulnerabilities key; the gate
found no advisories in it, printed "no unallowed high findings" and
exited 0, so a rate-limited or broken audit passed every PR.

Now a report with error or statusCode, without a vulnerabilities
object, or that is not JSON, prints "audit did not run: <status>
<message>". It is retried once after 5 s (the proxy rate-limits; CI may
flake on it), then fails the gate. Silent pass is gone.

audit-gate.test.ts runs a copy of the gate in a scratch tree with its
own allowlist and a fake npm: a 429 report retries once then fails, a
report without vulnerabilities fails, one 429 then a clean report
passes, a clean report passes, an allowlisted high passes until its
expiry and fails after it, and an unlisted high fails. The old gate
fails three of them.

Pij-Seat: pij-previous-firefly
Pij-Prime: pij-far-jackal
kleinbem added a commit to kleinbem-dev/cadre that referenced this pull request Nov 18, 2026
…2026-12-18

GHSA-fc5q-39xc-vjpf has no fixed picomatch release (fixes pending in
micromatch/picomatch#262-#266) and reaches us only through Vite's build
tooling; it fails fleet-lint's osv-scanner on every PR since 2026-11-18.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
kleinbem added a commit to kleinbem/hf-bench that referenced this pull request Nov 18, 2026
…2026-12-18

GHSA-fc5q-39xc-vjpf has no fixed picomatch release (fixes pending in
micromatch/picomatch#262-#266) and reaches us only through Vite's build
tooling; it fails fleet-lint's osv-scanner on every PR since 2026-11-18.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
kleinbem added a commit to kleinbem/kleinbem-site that referenced this pull request Nov 18, 2026
…2026-12-18

GHSA-fc5q-39xc-vjpf has no fixed picomatch release (fixes pending in
micromatch/picomatch#262-#266) and reaches us only through Vite's build
tooling; it fails fleet-lint's osv-scanner on every PR since 2026-11-18.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
kleinbem added a commit to kleinbem/web-config that referenced this pull request Nov 18, 2026
…2026-12-18

GHSA-fc5q-39xc-vjpf has no fixed picomatch release (fixes pending in
micromatch/picomatch#262-#266) and reaches us only through Vite's build
tooling; it fails fleet-lint's osv-scanner on every PR since 2026-11-18.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
kleinbem added a commit to kleinbem/web-config that referenced this pull request Nov 18, 2026
…2026-12-18 (#21)

fleet-lint's osv-scanner fails every PR here since 2026-11-18 on
GHSA-fc5q-39xc-vjpf, a ReDoS in picomatch <= 4.0.7 with no fixed release
yet; fixes are pending upstream in micromatch/picomatch#262 to #266.

picomatch reaches us only through Vite's build tooling (`vite`,
`tinyglobby`, `fdir`) and matches our own build globs, never request
data, so it's ignored. The expiry is short (2026-12-18): if picomatch
hasn't released a fix by then, the lint asks again. web-config had no
osv-scanner.toml; this adds it.

Tests: `osv-scanner scan source --config osv-scanner.toml --lockfile
package-lock.json` reports no issues.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
kleinbem added a commit to kleinbem/kleinbem-site that referenced this pull request Nov 18, 2026
…2026-12-18 (#56)

fleet-lint's osv-scanner fails every PR here since 2026-11-18 on
GHSA-fc5q-39xc-vjpf, a ReDoS in picomatch <= 4.0.7 with no fixed release
yet; fixes are pending upstream in micromatch/picomatch#262 to #266.

picomatch reaches us only through Vite's build tooling (`vite`,
`tinyglobby`, `fdir`) and matches our own build globs, never request
data, so it's ignored. The expiry is short (2026-12-18): if picomatch
hasn't released a fix by then, the lint asks again. It replaces the
deepmerge ignore, which osv-scanner now reports as unused.

Tests: `osv-scanner scan source --config osv-scanner.toml --lockfile
package-lock.json` reports no issues.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
kleinbem added a commit to kleinbem/hf-bench that referenced this pull request Nov 18, 2026
…2026-12-18 (#9)

fleet-lint's osv-scanner fails every PR here since 2026-11-18 on
GHSA-fc5q-39xc-vjpf, a ReDoS in picomatch <= 4.0.7 with no fixed release
yet; fixes are pending upstream in micromatch/picomatch#262 to #266.

picomatch reaches us only through Vite's build tooling (`vite`,
`tinyglobby`, `fdir`) and matches our own build globs, never request
data, so it's ignored. The expiry is short (2026-12-18): if picomatch
hasn't released a fix by then, the lint asks again. It replaces the
deepmerge ignore, which osv-scanner now reports as unused.

Tests: `osv-scanner scan source --config osv-scanner.toml --lockfile
package-lock.json` reports no issues.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
kleinbem added a commit to kleinbem-dev/nix-detour that referenced this pull request Nov 18, 2026
…2026-12-18 (#84)

fleet-lint's osv-scanner fails every PR here since 2026-11-18 on
GHSA-fc5q-39xc-vjpf, a ReDoS in picomatch <= 4.0.7 with no fixed release
yet; fixes are pending upstream in micromatch/picomatch#262 to #266.

picomatch reaches us only through Vite's build tooling (`vite`,
`tinyglobby`, `fdir`) and matches our own build globs, never request
data, so it's ignored. The expiry is short (2026-12-18): if picomatch
hasn't released a fix by then, the lint asks again. #83 ignored it until
2027-02-18; this shortens that to match the other repos.

Tests: `osv-scanner scan source --config web/osv-scanner.toml --lockfile
web/package-lock.json` reports no issues.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
kleinbem added a commit to kleinbem-dev/cadre that referenced this pull request Nov 18, 2026
…2026-12-18 (#38)

fleet-lint's osv-scanner fails every PR here since 2026-11-18 on
GHSA-fc5q-39xc-vjpf, a ReDoS in picomatch <= 4.0.7 with no fixed release
yet; fixes are pending upstream in micromatch/picomatch#262 to #266.

picomatch reaches us only through Vite's build tooling (`vite`,
`tinyglobby`, `fdir`) and matches our own build globs, never request
data, so it's ignored. The expiry is short (2026-12-18): if picomatch
hasn't released a fix by then, the lint asks again. It replaces the
deepmerge ignore, which osv-scanner now reports as unused.

Tests: `osv-scanner scan source --config web/osv-scanner.toml --lockfile
web/package-lock.json` reports no issues.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
@vm2f8y95sm-png

Copy link
Copy Markdown

Sharing downstream validation from Bia for the exact proposed head 3222059ac27492d9c0147fee5c65f751bbd851ab (not a merge recommendation or proof of complete ReDoS resistance).

On Node 24.19.0/macOS, an isolated harness with network and home-directory reads denied, no credentials in its environment, a 128 MiB JS heap limit and an external 2-second deadline per child completed 108 additional cases:

  • patterns +(*) and +(*a);
  • subjects "a".repeat(60000) with suffix "", "!", or "/";
  • options {}, {dot:true}, {windows:true}, {bash:true}, {nocase:true}, {flags:"i"};
  • callable matcher, makeRe, and compileRe(parse(...)).

All children exited successfully; measured compile-and-match time was 3–4 ms per case. +(*) matched the empty/! suffix variants and rejected the / suffix except with bash:true; +(*a) matched the all-a subject and rejected both other suffixes. These are finite-corpus results, not a complexity proof. An initial harness error indexed the object returned by parse; that harness error was corrected and the full 108-case matrix rerun.

Earlier isolated checks also found zero Boolean-result differences in 148,860 short base/head comparisons and completed 35 bounded adversarial cases across the three APIs. We have not run the full upstream suite, integrated this patch into Bia, or established compatibility for Next.js's separately bundled older copy. Explicit opt-out behavior and unsupported-pattern fallback remain important limitations.

Could maintainers review this candidate and advise on a supported fix/release path for GHSA-fc5q-39xc-vjpf? We are keeping the dependency security gate enforced rather than suppressing the advisory. Thank you.

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

6 participants