From df28e2e80802c6940b1dbbfccc5b9b5584553810 Mon Sep 17 00:00:00 2001 From: Gabriel Taveira Date: Fri, 20 Nov 2026 19:36:51 -0300 Subject: [PATCH] fix: prepare picomatch parser candidate for security review --- .github/workflows/ci.yml | 2 +- SECURITY.md | 2 + package.json | 2 +- patches/picomatch@2.3.2.patch | 56 ++++++++++++++++++++ patches/picomatch@4.0.5.patch | 47 +++++++++++++++++ pnpm-lock.yaml | 34 ++++++------ pnpm-workspace.yaml | 2 + tools/dependency-security-check.mjs | 1 + tools/picomatch-security-check.mjs | 82 +++++++++++++++++++++++++++++ tools/security-audit.mjs | 39 ++++++++++++++ 10 files changed, 249 insertions(+), 18 deletions(-) create mode 100644 patches/picomatch@2.3.2.patch create mode 100644 patches/picomatch@4.0.5.patch create mode 100644 tools/picomatch-security-check.mjs create mode 100644 tools/security-audit.mjs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 95506cc..c9724ce 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,7 +31,7 @@ jobs: # # One `extra-command`, so they're chained. `&&` short-circuits, which is # what we want: either failing fails the job. - extra-command: npm pack --dry-run && pnpm run changelog:check + extra-command: npm pack --dry-run && pnpm run changelog:check && pnpm run security:check # Nothing here uses turbo. turbo-cache: false diff --git a/SECURITY.md b/SECURITY.md index 8d51d60..2cdc92e 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -28,3 +28,5 @@ Development installs use basic-ftp 6, Zod 4, minimatch 11 and glob 14 for their Use Node 24 and the pinned pnpm version. We use Jest 30 with a TypeScript transformer for these Node-based config-plugin tests. Type checking runs separately. The old expo-module-scripts package and its `expo-module` command are removed; use `pnpm run build`, `pnpm run clean` and `pnpm run test` directly. Jest mocks that require Babel hoisting need explicit setup before importing the module under test. These are contributor tooling changes. Consumers keep the same plugin options. Security commits under `build(deps)` deliberately recommend a patch release under our changelog policy; ordinary chore, build and docs commits alone recommend no release. Public breaking changes still require a conventional breaking-change note with migration instructions, which the shared preset carries into the changelog, release body and annotated tag. + +Picomatch 2.3.2 and 4.0.5 have candidate local parser patches for GHSA-fc5q-39xc-vjpf. These candidates restrict repeated extglob grammar while preserving tested benign cases, including nested star reduction. Installed parser hashes and each reported dependency path are checked. Independent security review is blocked, so the candidate audit gate fails regardless of the current registry status. The candidate is not approved for merge or release. diff --git a/package.json b/package.json index 8ac1ef4..94163e2 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "test": "node tools/dependency-security-check.mjs && node tools/release-check.mjs && jest", "prepare": "pnpm run build", "release": "release-it", - "security:check": "node tools/dependency-security-check.mjs && pnpm audit --audit-level high" + "security:check": "node tools/dependency-security-check.mjs && node tools/security-audit.mjs" }, "devDependencies": { "@babel/core": "^7.29.7", diff --git a/patches/picomatch@2.3.2.patch b/patches/picomatch@2.3.2.patch new file mode 100644 index 0000000..53a940d --- /dev/null +++ b/patches/picomatch@2.3.2.patch @@ -0,0 +1,56 @@ +--- a/lib/parse.js ++++ b/lib/parse.js +@@ -292,6 +292,30 @@ + + const branches = splitTopLevel(body).map(branch => branch.trim()); + ++ // Wildcard operands inside a repeated branch introduce nested quantifiers. ++ // Escaped tokens and ordinary character classes do not. ++ let nested = false; ++ let bracket = false; ++ let escaped = false; ++ let quoted = false; ++ for (let index = 0; index < body.length; index++) { ++ const ch = body[index]; ++ if (escaped) { escaped = false; continue; } ++ if (ch === '\\') { escaped = true; continue; } ++ if (!bracket && ch === '"') { quoted = !quoted; continue; } ++ if (quoted) continue; ++ if (bracket && ch === '[' && body[index + 1] === ':') { ++ const end = body.indexOf(':]', index + 2); ++ if (end !== -1) { index = end + 1; continue; } ++ } ++ if (ch === '[') { bracket = true; continue; } ++ if (ch === ']') { bracket = false; continue; } ++ if (!bracket && (ch === '(' || ch === '{')) nested = true; ++ if (!bracket && ch === '*' && body[index + 1] !== '(') { ++ return { risky: true }; ++ } ++ } ++ + if (branches.length > 1) { + if ( + branches.some(branch => branch === '') || +@@ -304,7 +328,7 @@ + + for (const branch of branches) { + const safeOutput = getStarExtglobSequenceOutput(branch); +- if (safeOutput) { ++ if (safeOutput && branches.length === 1) { + return { risky: true, safeOutput }; + } + +@@ -313,6 +337,13 @@ + } + } + ++ // Preserve flat literal alternatives with disjoint initial characters. ++ // Other nested/alternative grammar is matched literally unless the existing ++ // character-sequence reduction above already proved a safe output. ++ if (nested || (branches.length > 1 && ( ++ branches.some(branch => !/^[a-zA-Z0-9_/-]+$/.test(branch)) || ++ new Set(branches.map(branch => branch[0])).size !== branches.length ++ ))) return { risky: true }; + return { risky: false }; + }; + diff --git a/patches/picomatch@4.0.5.patch b/patches/picomatch@4.0.5.patch new file mode 100644 index 0000000..ee2f419 --- /dev/null +++ b/patches/picomatch@4.0.5.patch @@ -0,0 +1,47 @@ +--- a/lib/parse.js ++++ b/lib/parse.js +@@ -296,6 +296,30 @@ + + const branches = splitTopLevel(body).map(branch => branch.trim()); + ++ // Wildcard operands inside a repeated branch introduce nested quantifiers. ++ // Escaped tokens and ordinary character classes do not. ++ let nested = false; ++ let bracket = false; ++ let escaped = false; ++ let quoted = false; ++ for (let index = 0; index < body.length; index++) { ++ const ch = body[index]; ++ if (escaped) { escaped = false; continue; } ++ if (ch === '\\') { escaped = true; continue; } ++ if (!bracket && ch === '"') { quoted = !quoted; continue; } ++ if (quoted) continue; ++ if (bracket && ch === '[' && body[index + 1] === ':') { ++ const end = body.indexOf(':]', index + 2); ++ if (end !== -1) { index = end + 1; continue; } ++ } ++ if (ch === '[') { bracket = true; continue; } ++ if (ch === ']') { bracket = false; continue; } ++ if (!bracket && (ch === '(' || ch === '{')) nested = true; ++ if (!bracket && ch === '*' && body[index + 1] !== '(') { ++ return { risky: true }; ++ } ++ } ++ + if (branches.length > 1) { + if ( + branches.some(branch => branch === '') || +@@ -343,6 +367,13 @@ + : { risky: true }; + } + ++ // Preserve flat literal alternatives with disjoint initial characters. ++ // Other nested/alternative grammar is matched literally unless the existing ++ // character-sequence reduction above already proved a safe output. ++ if (nested || (branches.length > 1 && ( ++ branches.some(branch => !/^[a-zA-Z0-9_/-]+$/.test(branch)) || ++ new Set(branches.map(branch => branch[0])).size !== branches.length ++ ))) return { risky: true }; + return { risky: false }; + }; + diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 745f120..65f4581 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -29,6 +29,8 @@ patchedDependencies: deepmerge@4.3.1: 9dee383ecd9fc08834a10802fd43859e281c879e1289e86ff3b0f0dfa345cbf6 image-size@1.2.1: 47b9dd91145f35c3b5349ad9fb3775bac13fc02d305a711a31b69cf285982eef minimatch@11.0.4: db261fb6f628df9732ee9a993e0ca9b577aa8de438da9fabf992bc1b334ec1e3 + picomatch@2.3.2: 9fa0a3ed6a965f8964e70e9573e48e2c38bc13b4ae67e7b98f06dc35e21d5348 + picomatch@4.0.5: 36fa68298163a9652ec6b72116781a87f3a65794e90dbbe234053c9a22905d38 importers: @@ -4794,7 +4796,7 @@ snapshots: node-forge: 1.4.3 npm-package-arg: 11.0.3 ora: 3.4.0 - picomatch: 4.0.5 + picomatch: 4.0.5(patch_hash=36fa68298163a9652ec6b72116781a87f3a65794e90dbbe234053c9a22905d38) pretty-format: 29.7.0 progress: 2.0.3 prompts: 2.4.2 @@ -4975,7 +4977,7 @@ snapshots: hermes-parser: 0.36.1 jsc-safe-url: 0.2.4 lightningcss: 1.33.0 - picomatch: 4.0.5 + picomatch: 4.0.5(patch_hash=36fa68298163a9652ec6b72116781a87f3a65794e90dbbe234053c9a22905d38) postcss: 8.5.23 resolve-from: 5.0.0 optionalDependencies: @@ -5692,7 +5694,7 @@ snapshots: detect-libc: 2.1.2 is-glob: 4.0.3 node-addon-api: 7.1.1 - picomatch: 4.0.5 + picomatch: 4.0.5(patch_hash=36fa68298163a9652ec6b72116781a87f3a65794e90dbbe234053c9a22905d38) optionalDependencies: '@parcel/watcher-android-arm64': 2.6.0 '@parcel/watcher-darwin-arm64': 2.6.0 @@ -6030,7 +6032,7 @@ snapshots: anymatch@3.1.3: dependencies: normalize-path: 3.0.0 - picomatch: 2.3.2 + picomatch: 2.3.2(patch_hash=9fa0a3ed6a965f8964e70e9573e48e2c38bc13b4ae67e7b98f06dc35e21d5348) arg@5.0.2: {} @@ -6818,9 +6820,9 @@ snapshots: dependencies: walk-up-path: 4.0.0 - fdir@6.5.0(picomatch@4.0.5): + fdir@6.5.0(picomatch@4.0.5(patch_hash=36fa68298163a9652ec6b72116781a87f3a65794e90dbbe234053c9a22905d38)): optionalDependencies: - picomatch: 4.0.5 + picomatch: 4.0.5(patch_hash=36fa68298163a9652ec6b72116781a87f3a65794e90dbbe234053c9a22905d38) fetch-nodeshim@0.4.10: {} @@ -7244,12 +7246,12 @@ snapshots: '@types/node': 24.13.3 anymatch: 3.1.3 fb-watchman: 2.0.2 - fdir: 6.5.0(picomatch@4.0.5) + fdir: 6.5.0(picomatch@4.0.5(patch_hash=36fa68298163a9652ec6b72116781a87f3a65794e90dbbe234053c9a22905d38)) graceful-fs: 4.2.11 jest-regex-util: 30.5.0 jest-util: 30.5.1 jest-worker: 30.5.1 - picomatch: 4.0.5 + picomatch: 4.0.5(patch_hash=36fa68298163a9652ec6b72116781a87f3a65794e90dbbe234053c9a22905d38) jest-leak-detector@30.5.1: dependencies: @@ -7271,7 +7273,7 @@ snapshots: chalk: 4.1.2 graceful-fs: 4.2.11 jest-util: 30.5.1 - picomatch: 4.0.5 + picomatch: 4.0.5(patch_hash=36fa68298163a9652ec6b72116781a87f3a65794e90dbbe234053c9a22905d38) pretty-format: 30.5.1 slash: 3.0.0 stack-utils: 2.0.6 @@ -7390,7 +7392,7 @@ snapshots: chalk: 4.1.2 ci-info: 3.9.0 graceful-fs: 4.2.11 - picomatch: 2.3.2 + picomatch: 2.3.2(patch_hash=9fa0a3ed6a965f8964e70e9573e48e2c38bc13b4ae67e7b98f06dc35e21d5348) jest-util@30.5.1: dependencies: @@ -7399,7 +7401,7 @@ snapshots: chalk: 4.1.2 ci-info: 4.4.0 graceful-fs: 4.2.11 - picomatch: 4.0.5 + picomatch: 4.0.5(patch_hash=36fa68298163a9652ec6b72116781a87f3a65794e90dbbe234053c9a22905d38) jest-validate@29.7.0: dependencies: @@ -7821,7 +7823,7 @@ snapshots: micromatch@4.0.8: dependencies: braces: 3.0.3 - picomatch: 2.3.2 + picomatch: 2.3.2(patch_hash=9fa0a3ed6a965f8964e70e9573e48e2c38bc13b4ae67e7b98f06dc35e21d5348) mime-db@1.52.0: {} @@ -8112,9 +8114,9 @@ snapshots: picocolors@1.1.1: {} - picomatch@2.3.2: {} + picomatch@2.3.2(patch_hash=9fa0a3ed6a965f8964e70e9573e48e2c38bc13b4ae67e7b98f06dc35e21d5348): {} - picomatch@4.0.5: {} + picomatch@4.0.5(patch_hash=36fa68298163a9652ec6b72116781a87f3a65794e90dbbe234053c9a22905d38): {} pirates@4.0.7: {} @@ -8580,8 +8582,8 @@ snapshots: tinyglobby@0.2.17: dependencies: - fdir: 6.5.0(picomatch@4.0.5) - picomatch: 4.0.5 + fdir: 6.5.0(picomatch@4.0.5(patch_hash=36fa68298163a9652ec6b72116781a87f3a65794e90dbbe234053c9a22905d38)) + picomatch: 4.0.5(patch_hash=36fa68298163a9652ec6b72116781a87f3a65794e90dbbe234053c9a22905d38) tinypool@2.2.0: {} diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 7c8c653..dce7ceb 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -104,3 +104,5 @@ patchedDependencies: deepmerge@4.3.1: patches/deepmerge@4.3.1.patch image-size@1.2.1: patches/image-size@1.2.1.patch minimatch@11.0.4: patches/minimatch@11.0.4.patch + picomatch@2.3.2: patches/picomatch@2.3.2.patch + picomatch@4.0.5: patches/picomatch@4.0.5.patch diff --git a/tools/dependency-security-check.mjs b/tools/dependency-security-check.mjs index ab806bc..a2b6e0d 100644 --- a/tools/dependency-security-check.mjs +++ b/tools/dependency-security-check.mjs @@ -1,3 +1,4 @@ +import "./picomatch-security-check.mjs"; import assert from "node:assert/strict"; import { spawnSync } from "node:child_process"; import { diff --git a/tools/picomatch-security-check.mjs b/tools/picomatch-security-check.mjs new file mode 100644 index 0000000..4aa352b --- /dev/null +++ b/tools/picomatch-security-check.mjs @@ -0,0 +1,82 @@ +import assert from "node:assert/strict"; +import { spawnSync } from "node:child_process"; +import { createHash } from "node:crypto"; +import { readFileSync, readdirSync, realpathSync } from "node:fs"; +import { createRequire } from "node:module"; + +const require = createRequire(import.meta.url); +const hashes = { + "2.3.2": "296547ec9d733720b648854bc52a4cfa1c255247336c10b0f6745433bd9e01f2", + "4.0.5": "86a303b54f309277db4070784c140f955e4e73e5dd9862b813985c4e392ffd32", +}; +export const picomatchEntries = new Map(); +const store = new URL("../node_modules/.pnpm/", import.meta.url); +for (const directory of readdirSync(store).filter((name) => + name.startsWith("picomatch@"), +)) { + const root = new URL(`${directory}/node_modules/picomatch/`, store); + const { version } = JSON.parse( + readFileSync(new URL("package.json", root), "utf8"), + ); + assert.ok(hashes[version], `Unverified picomatch version: ${version}`); + const digest = createHash("sha256") + .update(readFileSync(new URL("lib/parse.js", root))) + .digest("hex"); + assert.equal(digest, hashes[version], `Unpatched picomatch: ${directory}`); + const entry = realpathSync(require.resolve(root.pathname)); + picomatchEntries.set(entry, version); + const probe = spawnSync( + process.execPath, + [ + "-e", + ` + const p = require(${JSON.stringify(entry)}); + const a = require('node:assert/strict'); + a.equal(p('+(a|b)')('abba'), true); + a.equal(p('+(*(a))')('aaaa'), true); + a.equal(p('+([ab])')('abba'), true); + a.equal(p('+([*?])')('*?*'), true); + a.equal(p(String.raw\`+(\\*)\`)('***'), true); + a.equal(p('src/**/*.ts')('src/a/b.ts'), true); + a.equal(p('+(file?.ts)')('file1.tsfile2.ts'), true); + a.equal(p('+("*")')('***'), true); + a.equal(p('+([[:alpha:]*])')('a*a'), true); + `, + ], + { timeout: 3000, killSignal: "SIGKILL", encoding: "utf8" }, + ); + assert.equal(probe.status, 0, probe.stderr || String(probe.error)); + console.log( + `picomatch ${version}: exact parser hash and benign compatibility probes passed`, + ); +} +assert.deepEqual( + new Set(picomatchEntries.values()), + new Set(Object.keys(hashes)), +); + +// Resolve every edge from the project, including packages with only type exports. +export const verifyPicomatchFinding = (finding) => { + assert.ok(finding.paths.length > 0, "Missing audit dependency paths"); + for (const path of finding.paths) { + const names = path.split(">"); + assert.equal(names.shift(), "."); + assert.equal(names.at(-1), "picomatch"); + let entry = new URL("../package.json", import.meta.url).pathname; + for (const name of names) { + const from = createRequire(entry); + try { + entry = from.resolve(`${name}/package.json`); + } catch { + entry = from.resolve(name); + } + } + // Normalize package.json to its public entry before comparing real paths. + const resolved = createRequire(entry).resolve("picomatch"); + assert.equal( + picomatchEntries.get(realpathSync(resolved)), + finding.version, + `Unverified audit path: ${path}`, + ); + } +}; diff --git a/tools/security-audit.mjs b/tools/security-audit.mjs new file mode 100644 index 0000000..5ca1623 --- /dev/null +++ b/tools/security-audit.mjs @@ -0,0 +1,39 @@ +import assert from "node:assert/strict"; +import { spawnSync } from "node:child_process"; + +import { verifyPicomatchFinding } from "./picomatch-security-check.mjs"; + +// Validate the candidate without accepting the advisory while independent +// security review is blocked. Existing workspace exceptions remain unchanged. +const result = spawnSync("pnpm", ["audit", "--json"], { + encoding: "utf8", + timeout: 60000, + maxBuffer: 10 * 1024 * 1024, +}); +assert.ok( + result.status === 0 || result.status === 1, + result.stderr || String(result.error), +); +const audit = JSON.parse(result.stdout); +assert.ok(audit.metadata && audit.advisories, "Missing audit response"); +let paths = 0; +for (const advisory of Object.values(audit.advisories)) { + assert.equal( + advisory.github_advisory_id, + "GHSA-fc5q-39xc-vjpf", + `Unmitigated advisory: ${advisory.github_advisory_id}`, + ); + assert.equal(advisory.module_name, "picomatch"); + assert.ok(advisory.findings.length > 0); + for (const finding of advisory.findings) { + verifyPicomatchFinding(finding); + paths += finding.paths.length; + } +} +console.log( + `Validated ${paths} candidate picomatch audit paths; security review remains blocked.`, +); +// Keep the candidate blocked even when the registry withdraws or omits a finding. +assert.fail( + "Independent parser security review is blocked; do not merge or release this candidate.", +);