Skip to content

fix: rewrite star-literal repeated extglobs into a single repetition (GHSA-fc5q-39xc-vjpf) - #273

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

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

Conversation

@lkakonyi

Copy link
Copy Markdown

Problem

GHSA-fc5q-39xc-vjpf (CVE-2026-112366) has no patched version yet. A single-branch repeated extglob whose body is a star, or a literal with a star at one or both ends, compiles to a nested quantifier. On 4.0.7 and 2.3.2:

pm.makeRe('+(*a)').source  //=> '^(?:(?=.)(?:[^/]*?a)+)$'
pm.makeRe('+(*)').source   //=> '^(?:(?=.)(?:[^/]*?)+)$'

Matching 'a'.repeat(n) + 'b' against +(*a) takes 2 ms at n=16, 4 ms at n=20 and 60 ms at n=24, about ×15 for every 4 characters. +(*), *(*a) and +(a*) grow the same way.

Fix

analyzeRepeatedExtglob already rewrites other risky repeated extglobs. This PR adds one more case: a single branch of the form *, *L, L* or *L*, where L is a plain literal (normalizeSimpleBranch) without a path separator.

For these bodies the repetition can be dropped without changing what matches:

  • *L: a concatenation of several repetitions still ends with L.
  • L*: it still starts with L.
  • *L*: it still contains L.
  • *: absorbs everything.
  • The converse: any string that matches one repetition is itself a valid result.

So:

Pattern Before After
+(*a) (?:[^/]*?a)+ [^/]*?a
+(a*) (?:a[^/]*?)+ a[^/]*?
+(*ab*) (?:[^/]*?ab[^/]*?)+ [^/]*?ab[^/]*?
+(*), *(*) (?:[^/]*?)+, (?:[^/]*?)* [^/]*?
*(*a) (?:[^/]*?a)* (?:[^/]*?a)? (a star extglob stays optional)

The * inside the rewrite is the output the body's own star token would get: .*? under bash, the windows and capture forms otherwise.

What it leaves alone:

  • A path separator in L: the repeated form is kept, because +(*a/b) matches xa/bya/b, which a single *a/b cannot.
  • A literal ending in a dot before the trailing star (+(a.*)): that star carries its own dot guard, so the repeated form is kept.
  • regex: true: emits a raw * after the paren, so it is skipped.
  • The maxExtglobRecursion: false opt-out: still honoured.

Verification

  • New tests: test/redos-star-literal-extglob.js (8 tests) covers the compiled sources, the non-matching attack inputs (64 characters), matching semantics, optional star extglobs, the bash and windows stars, the path-separator and dot cases, and capture. Without the change in lib/parse.js, the source assertions fail and the attack test hangs past the mocha timeout.
  • Full suite: 2,006 passing; eslint lib test is clean.
  • Equivalence: I compared the patched build with 4.0.7 on every string up to length 5 over a b x . / * \. That covered 28 patterns, including embedded, escaped, dot-literal and !(...)/@(...)-wrapped forms, under 11 option sets: default, dot, capture, nocase, bash, bash+dot, windows, windows+dot, regex, noextglob and posix. The result: 6,039,264 pattern/string pairs, 0 differences.
  • After the change: the same inputs at n=50,000 finish in under 1.5 ms for +(*a), *(*a), +(*) and +(a*). *(*ab*) keeps the usual quadratic cost of [^/]*?ab[^/]*?: about 1.3 s on a 100,000-character non-matching input, against about 2.0 s for the plain glob *ab* on the same input.

The same code is on the 2.x and 3.x lines, which the advisory also covers. I'm happy to open backports if you'd like them.

🤖 Generated with Claude Code

A single-branch `+(...)`/`*(...)` whose body is a star, or a plain literal
with a star on one or both ends (`*`, `*L`, `L*`, `*L*`), compiled to a
nested quantifier such as `(?:[^/]*?a)+` and backtracked exponentially on
short non-matching input (GHSA-fc5q-39xc-vjpf / CVE-2026-112366).

One repetition of such a body already matches every concatenation of
several (they all end with L, start with L or contain L, and `*` absorbs
everything), so the repetition is dropped: `+(*a)` -> `[^/]*?a`, and a
star extglob keeps its optionality (`*(*a)` -> `(?:[^/]*?a)?`). The rewrite
uses the star output the body itself would get (`.*?` with `bash`). It
is skipped for literals with a path separator (`+(*a/b)` can span
segments that a single `*a/b` cannot), for a literal ending in a dot
before the trailing star (that star carries its own dot guard), and in
`regex` mode.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@samuelT2

Copy link
Copy Markdown

Thanks for picking this up! This advisory currently fails npm audit --audit-level=high in CI for anything using Jest 30: it pulls in picomatch 4.0.7 (via jest-util, jest-haste-map and @parcel/watcher) and 2.3.2 (via anymatch@3, which needs ^2). Because there is no patched version, there is nothing to upgrade to yet.

So a release would help a lot, and the 2.x backport you offered would be needed too; otherwise the 2.3.2 copy keeps the audit red. Happy to test a pre-release if that's useful.

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

propr-dev Bot pushed a commit to integry/propr that referenced this pull request Nov 19, 2026
…on upstream picomatch from the npm registry. A clean `npm ci`, the unit suite (799/799), typecheck and lint all pass. I couldn't change the PR title or description: both `gh pr edit` and the GitHub API returned 403 "Resource not accessible by integration". Please set the title to **Remove the vendored picomatch builds (advisory GHSA-fc5q-39xc-vjpf withdrawn)** and use the description at the end.

I removed the vendored picomatch builds, and ProPR is back on upstream picomatch from the npm registry. A clean `npm ci`, the unit suite (799/799), typecheck and lint all pass. I couldn't change the PR title or description: both `gh pr edit` and the GitHub API returned 403 "Resource not accessible by integration". Please set the title to **Remove the vendored picomatch builds (advisory GHSA-fc5q-39xc-vjpf withdrawn)** and use the description at the end.

**What changed**
- **Guard work dropped.** `vendor/picomatch/`, `vendor/picomatch-v2/`, both tarballs and `test/vendoredPicomatch.test.mjs` are deleted, so the `extglobguard.3` changes go with them.
- **`package.json`.** The `"picomatch": "$picomatch"` override and the three nested ones (`anymatch`, `micromatch`, `readdirp`) are gone. The vendoring commit (800738d) was what added picomatch as a direct dependency, so I removed it rather than replacing it with a version range.
- **Signed-RPM acceptance files.** The Dockerfile `COPY` lines, the allowlist in `signed-rpm-acceptance-context.mjs` and its test assertions are back to their pre-vendoring braces-only form.
- **Docs.** I removed the picomatch section from `docs/dependency-audit-exceptions.md` and the vendored picomatch row from `THIRD_PARTY_LICENSES.md` (MIT count 225 → 224). The notices validator passes.
- **`CHANGELOG.md`.** One entry under Unreleased → Removed.
- No CI workflow or `.npmrc` referred to the vendored builds. `vendor/braces/` is untouched.

**Lockfile** (regenerated with `npm install`; a second run leaves it byte-identical)

| Path | Version |
|---|---|
| `node_modules/picomatch` | 4.0.7 (dev) |
| `node_modules/anymatch/node_modules/picomatch` | 2.3.2 |
| `node_modules/micromatch/node_modules/picomatch` | 2.3.2 |
| `node_modules/readdirp/node_modules/picomatch` | 2.3.2 |

All four come from the registry. The only `file:` entry left is the braces tarball.

**Audit gates**
- `npm audit --omit=dev`: `found 0 vulnerabilities`
- `npm run audit:runtime`: `runtime dependency audit passed.`
- `npm run desktop:audit:packaging`: `packaging dependency audit passed.`
- **"Review dependency changes":** this job compares pushed commits through GitHub's dependency graph, so it can't run locally. As a stand-in, I asked the same API to compare the vendoring commit with its parent. It now lists `[email protected]` and `2.3.2` with no vulnerabilities, so GitHub's data already reflects the withdrawal. The job itself will run on CI after the push. I added no ignore entry.

**Other checks**
- `git grep -n "extglobguard\|picomatch-v2"` finds matches only in `CHANGELOG.md` history; the lockfile has none.
- The 799 unit tests and the signed-RPM context test (5/5) pass. A clean `npm ci` installs only picomatch 4.0.7 and 2.3.2.

There are no visual previews because nothing user-visible changed.

**PR description to paste:**

---
Closes #3728

GitHub withdrew advisory GHSA-fc5q-39xc-vjpf on 2026-11-18, and the picomatch maintainers say on micromatch/picomatch#273 that it is not a security issue. The two vendored picomatch builds only existed because that advisory had no fixed release. This PR removes them and goes back to upstream picomatch from the npm registry. It also drops this PR's earlier work extending the extglob guard (`extglobguard.3`).

**Removed**
- `vendor/picomatch/`, `vendor/picomatch-v2/`, both tarballs and `test/vendoredPicomatch.test.mjs`.
- From `package.json`: the `"picomatch": "$picomatch"` override, the nested `picomatch` overrides under `anymatch`, `micromatch` and `readdirp`, and the direct `picomatch` dependency, which the vendoring commit had added.
- The vendored picomatch tarballs from the signed-RPM acceptance Dockerfile, its allowlist and its test, which are back to braces only.
- The picomatch section of `docs/dependency-audit-exceptions.md` and the vendored picomatch row in `THIRD_PARTY_LICENSES.md`.

`vendor/braces/` and the braces advisories are unchanged.

**Lockfile:** picomatch resolves from the registry only, as 4.0.7 at the root (dev) and 2.3.2 under `anymatch`, `micromatch` and `readdirp`. The only `file:` entry left is the braces tarball.

**Audit gates:** `npm audit --omit=dev` finds 0 vulnerabilities, and `audit:runtime` and `desktop:audit:packaging` pass. GitHub's dependency-graph compare API lists `[email protected]` and `2.3.2` with no vulnerabilities. No ignore entry was added.

**Verification:** a clean `npm ci` succeeds, `test:unit` passes 799/799, and typecheck, lint and `signed-rpm-acceptance-context.test.mjs` pass. `git grep -n "extglobguard\|picomatch-v2"` matches only `CHANGELOG.md` history.

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

PR: #3735
Comment by: @integry (ID: 7006455579)
Model: Claude Opus 5.5
integry pushed a commit to integry/propr that referenced this pull request Nov 19, 2026
… still takes seconds on a 27-character string (#3735)

* Both vendored picomatch builds now handle a group followed by `+` whose body can match the same text in more than one way. Every pattern from the issue returns in under 1 ms on a 5,000-character non-matching string, in both builds. I ran `test:unit` and the picomatch tests, not the full `npm run test:full` suite.

How it works. The existing extglob guard turns a risky `+(...)` into literal text, so I did the same here: the group and its `+` are matched as the literal string. The change is identical in `vendor/picomatch/lib/parse.js` (4.x) and `vendor/picomatch-v2/lib/parse.js` (2.3.2).
- Groups checked: plain `(...)`, `@(...)`, `!(...)` and comma braces `{a,b}` when followed by `+`.
- When a body counts as risky:
  - it contains `*`, ``, a regex `+`, or a nested repeating extglob (`(*a)+`, `(*)+x`, `(a*)+b`, `((*)+)+`, `{*a,}+`, `(a+|b)+`, `(*(a))+b`).
  - it has an alternation inside a nested group (`((a|aa))+`).
  - its top-level branches are not plain words that join together in only one way (`(a|aa)+`, `(ab|a|ba)+`, `(a|)+`). With `nocase`, branches are lowercased first, so `(A|a)+` counts.
- Negation: `!(...)+` is always treated as risky. Its compiled form ends in `*`, so it took about 5–6 s on 26 characters whatever the body was.
- Unchanged: `(js|ts)+`, `{a,b}+`, `(ab)+`, `([a-z][0-9])+`, `(a?)+`, and anything not followed by `+`. That includes `(*)*x`, whose second `*` is a wildcard rather than a repeat; it stays at about 7 ms on 5,000 characters. `maxExtglobRecursion: false` turns this check off along with the existing guard.

Behaviour change. Glob users who relied on these patterns will now get literal matches. Upstream's own mocha suites (4.0.7 and 2.3.2 tags) still pass except for 9 assertions, up from the 4 already documented. The 5 new ones are all `(a+|b)+`, which took 13 s on 29 characters with the old build. Both READMEs and `docs/dependency-audit-exceptions.md` describe this.

Version bump and lockfile.
- The tarballs were rebuilt with `npm pack` from the source directories and renamed to `…extglobguard.3.tgz`.
- I updated every reference: `package.json` overrides, the lockfile, `THIRD_PARTY_LICENSES.md`, the test and the signed-RPM acceptance files.
- Lockfile integrity was set as the README describes and regenerated with `npm install`. `npm ls` shows no invalid entries.

Tests.
- `test/vendoredPicomatch.test.mjs`: 17/17 pass. The new cases cover each issue pattern against both builds with a 50 ms bound, check that safe groups keep their results, and add a check through the real `anymatch`.
- `npm ci` in a clean copy of the tree succeeded and the same 17 tests pass there.
- `signed-rpm-acceptance-context.test.mjs` passes.
- `npm run test:unit`: 798 of 799 pass. The one failure was caused by my setting `PROPR_DEMO_MODE`; that file passes when rerun without it.
- A fuzz of 200,000 random globs per build found no unintended output changes, no new errors and no slow regexes.

Where controllable globs reach picomatch in ProPR (for the PR description). No ProPR source imports picomatch, micromatch, fast-glob, globby or similar libraries directly. They are reached through two dependencies:
1. `chokidar.watch(...)` in `packages/api/services/taskWatcher.ts:177`, `:233` and `:286` (picomatch via anymatch and readdirp). The watched path is built from the operator's agent config path in the database and a session ID, which comes from `randomUUID()` or the Claude CLI's output stream. No globbing option is turned off, so glob characters in that path would be read as a glob.
2. repomix `pack()` in `packages/core/src/services/context/optimizedContext.ts:63`, `:80` and `:238` (globby → fast-glob → micromatch → picomatch).
   - The include patterns are file paths from the cloned repository. Repomix escapes `( ) [ ] \` in them, and fast-glob expands braces before compiling, so a repository file name cannot form a repeated group.
   - Repomix also reads the target repository's `.gitignore`, `.ignore` and `.repomixignore`. globby turns those rules into extra skip patterns for fast-glob, but drops any rule containing `(){}|\`.
   - `.git/info/exclude` is passed to fast-glob without escaping. A cloned remote can't set that file, but an agent working in the clone could write it.
   - Repomix config files in the target repository are not read, because `pack()` is the library API rather than the CLI.

   Build-only users: vite, vitest, tailwind, eslint and Playwright configs.

There are no visual previews because nothing user-visible changed.

* feat(ai): I removed the vendored picomatch builds, and ProPR is back on upstream picomatch from the npm registry. A clean `npm ci`, the unit suite (799/799), typecheck and lint all pass. I couldn't change the PR title or description: both `gh pr edit` and the GitHub API returned 403 "Resource not accessible by integration". Please set the title to **Remove the vendored picomatch builds (advisory GHSA-fc5q-39xc-vjpf withdrawn)** and use the description at the end.

I removed the vendored picomatch builds, and ProPR is back on upstream picomatch from the npm registry. A clean `npm ci`, the unit suite (799/799), typecheck and lint all pass. I couldn't change the PR title or description: both `gh pr edit` and the GitHub API returned 403 "Resource not accessible by integration". Please set the title to **Remove the vendored picomatch builds (advisory GHSA-fc5q-39xc-vjpf withdrawn)** and use the description at the end.

**What changed**
- **Guard work dropped.** `vendor/picomatch/`, `vendor/picomatch-v2/`, both tarballs and `test/vendoredPicomatch.test.mjs` are deleted, so the `extglobguard.3` changes go with them.
- **`package.json`.** The `"picomatch": "$picomatch"` override and the three nested ones (`anymatch`, `micromatch`, `readdirp`) are gone. The vendoring commit (800738d) was what added picomatch as a direct dependency, so I removed it rather than replacing it with a version range.
- **Signed-RPM acceptance files.** The Dockerfile `COPY` lines, the allowlist in `signed-rpm-acceptance-context.mjs` and its test assertions are back to their pre-vendoring braces-only form.
- **Docs.** I removed the picomatch section from `docs/dependency-audit-exceptions.md` and the vendored picomatch row from `THIRD_PARTY_LICENSES.md` (MIT count 225 → 224). The notices validator passes.
- **`CHANGELOG.md`.** One entry under Unreleased → Removed.
- No CI workflow or `.npmrc` referred to the vendored builds. `vendor/braces/` is untouched.

**Lockfile** (regenerated with `npm install`; a second run leaves it byte-identical)

| Path | Version |
|---|---|
| `node_modules/picomatch` | 4.0.7 (dev) |
| `node_modules/anymatch/node_modules/picomatch` | 2.3.2 |
| `node_modules/micromatch/node_modules/picomatch` | 2.3.2 |
| `node_modules/readdirp/node_modules/picomatch` | 2.3.2 |

All four come from the registry. The only `file:` entry left is the braces tarball.

**Audit gates**
- `npm audit --omit=dev`: `found 0 vulnerabilities`
- `npm run audit:runtime`: `runtime dependency audit passed.`
- `npm run desktop:audit:packaging`: `packaging dependency audit passed.`
- **"Review dependency changes":** this job compares pushed commits through GitHub's dependency graph, so it can't run locally. As a stand-in, I asked the same API to compare the vendoring commit with its parent. It now lists `[email protected]` and `2.3.2` with no vulnerabilities, so GitHub's data already reflects the withdrawal. The job itself will run on CI after the push. I added no ignore entry.

**Other checks**
- `git grep -n "extglobguard\|picomatch-v2"` finds matches only in `CHANGELOG.md` history; the lockfile has none.
- The 799 unit tests and the signed-RPM context test (5/5) pass. A clean `npm ci` installs only picomatch 4.0.7 and 2.3.2.

There are no visual previews because nothing user-visible changed.

**PR description to paste:**

---
Closes #3728

GitHub withdrew advisory GHSA-fc5q-39xc-vjpf on 2026-11-18, and the picomatch maintainers say on micromatch/picomatch#273 that it is not a security issue. The two vendored picomatch builds only existed because that advisory had no fixed release. This PR removes them and goes back to upstream picomatch from the npm registry. It also drops this PR's earlier work extending the extglob guard (`extglobguard.3`).

**Removed**
- `vendor/picomatch/`, `vendor/picomatch-v2/`, both tarballs and `test/vendoredPicomatch.test.mjs`.
- From `package.json`: the `"picomatch": "$picomatch"` override, the nested `picomatch` overrides under `anymatch`, `micromatch` and `readdirp`, and the direct `picomatch` dependency, which the vendoring commit had added.
- The vendored picomatch tarballs from the signed-RPM acceptance Dockerfile, its allowlist and its test, which are back to braces only.
- The picomatch section of `docs/dependency-audit-exceptions.md` and the vendored picomatch row in `THIRD_PARTY_LICENSES.md`.

`vendor/braces/` and the braces advisories are unchanged.

**Lockfile:** picomatch resolves from the registry only, as 4.0.7 at the root (dev) and 2.3.2 under `anymatch`, `micromatch` and `readdirp`. The only `file:` entry left is the braces tarball.

**Audit gates:** `npm audit --omit=dev` finds 0 vulnerabilities, and `audit:runtime` and `desktop:audit:packaging` pass. GitHub's dependency-graph compare API lists `[email protected]` and `2.3.2` with no vulnerabilities. No ignore entry was added.

**Verification:** a clean `npm ci` succeeds, `test:unit` passes 799/799, and typecheck, lint and `signed-rpm-acceptance-context.test.mjs` pass. `git grep -n "extglobguard\|picomatch-v2"` matches only `CHANGELOG.md` history.

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

PR: #3735
Comment by: @integry (ID: 7006455579)
Model: Claude Opus 5.5

---------

Co-authored-by: propr-dev[bot] <1316198+propr-dev[bot]@users.noreply.github.com>
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