diff --git a/notebook/2026-11-21-editor-minimatch.md b/notebook/2026-11-21-editor-minimatch.md new file mode 100644 index 0000000..a5b6e36 --- /dev/null +++ b/notebook/2026-11-21-editor-minimatch.md @@ -0,0 +1,95 @@ +# Editor minimatch advisory remediation + +## Scope and decision + +Dependabot alert 9 identifies minimatch 10.2.6 in the editor lockfile. +[GHSA-g3hv-75wg-m249](https://github.com/isaacs/minimatch/security/advisories/GHSA-g3hv-75wg-m249) +describes glob-parts amplification when `optimizationLevel >= 2`; the +[first patched release is 11.0.1](https://github.com/isaacs/minimatch/releases/tag/v11.0.1). +The inspected language-client and VSIX-packaging consumers use the default +optimization level, but retaining the affected dependency leaves the advisory +unresolved. + +The editor now pins minimatch 11.0.9 through its existing npm override facility. +The reviewed consumer versions remain vscode-languageclient 10.1.1 and +@vscode/vsce 4.0.0. The language client is pinned exactly because its two +compatibility adaptations require a fresh review when that implementation +changes. At investigation time, the current upstream language client 11.0.0 +and VSCE 4.1.1 still request minimatch 10, so upgrading either parent alone +does not remove the affected dependency. + +Minimatch 11 uses a nonrecursive matcher and removes `makeRe()`. Its +[documented API](https://github.com/isaacs/minimatch/blob/v11.0.9/README.md) +retains `Minimatch.set`, `Minimatch.match()` and `minimatch()`. +Both inspected language-client calls use `makeRe()` only as a boolean +validation guard before matching; neither consumes a regular expression. +An npm override alone therefore breaks ordinary language-client matching. + +The esbuild helper replaces those two guards with an empty parsed-set check +in the production bundle. It preserves rejection of empty/comment patterns, +leaves constructor errors intact and does not add a fake regular-expression +API or mutate the matcher prototype. The helper checks exact consumer/matcher +versions, exact guard count and inclusion of both reviewed modules, failing +the build if an update changes that contract. Incremental rebuilds are checked +too. Installed upstream packages remain untouched. VSCE uses the supported +`minimatch()` function and needs no adaptation. + +The extension's VS Code minimum remains `^1.95.0`; the existing Node 20 bundle +target and CI Node 22 configuration are unchanged. The helper is excluded +from the VSIX along with source, tests and installed dependencies. + +## Local evidence + +- All 213 extension unit tests pass, including nine new focused compatibility + tests. They exercise the actual bundled language-client consumers, ordinary + and relative globs, Unicode, dotfiles, case and scheme filters, file kinds, + Windows drives/UNC paths and incremental bundling. An unadapted consumer + negative control demonstrates the removed-API failure. A small explicit + expansion limit checks the patched optimization-level-2 rejection. +- The nine focused tests also pass on official Node 20.20.2. Production + bundling succeeds, and `npm audit --json` reports zero vulnerabilities. +- Baseline and candidate VSIX packaging succeeds on official Node 22.23.5. + Both archives have the same seventeen files; only the package manifest and + bundled extension change. The candidate has no `makeRe()` calls and includes + the nonrecursive matcher. The Node archives used for these checks were + verified against the official SHA256 manifests. +- The host's older Node 22.11 reproduces a VSCE/parse5 ESM loading failure in + the untouched baseline. The isolated newer Node packaging check changes + neither the extension engine nor the machine's Node installation. +- The isolated Linux VS Code 1.144.1 campaign passes all 88 checks across all + nine modules without skips, exits zero and confirms complete cleanup. The + immutable SDK's 279 payload files are unchanged. + +## External test-owner correction + +Three earlier candidate runs passed every functional check but failed the +private outer process owner's cleanup classification. All three failures and +an untouched baseline control remain preserved. The observed child was an +editor zygote, with a recorded signal attempt followed by natural exit status +zero. Extension-host termination took eight milliseconds in the observed +candidate runs and seven in the baseline. Review found no additional matcher +timers, listeners or child processes. + +A bounded real-process reproduction identifies the external harness defect: +`pidfd_send_signal()` can succeed for an already-exited, unreaped child. A +natural exit between the owner's readiness check and signal call was therefore +misclassified as required termination. A separately versioned private owner +retains signal attempts and classifies termination from verified child +identity, successful reap, an exited pidfd and authoritative wait status. +Unknown ownership or exit evidence fails closed. Its real escaped-child +positive control passes for natural exit; the live-child negative control +fails when SIGKILL actually terminates the child. Nine incomplete/unknown +evidence cases fail closed too. + +The final unchanged candidate campaign passes with that correction, retaining +the zygote's signal attempt and verified natural exit in the report. No child +was terminated by a signal and no survivors remain. Ownership checks, signals, +deadlines and cleanup windows are unchanged. This correction is confined to +the private evidence driver; no repository runner or extension lifecycle code +changes are included in the dependency patch. + +These changes do not replace the framework's prior source/SDK qualification. +Independent review accepts the guarded adaptation. Hosted platform checks +remain pending for this dependency revision. +The default-branch alert is not claimed closed before the dependency change +reaches that branch and GitHub reevaluates it. diff --git a/vscode/.vscodeignore b/vscode/.vscodeignore index aa039d8..2f8a35e 100644 --- a/vscode/.vscodeignore +++ b/vscode/.vscodeignore @@ -1,5 +1,6 @@ .gitignore esbuild.mjs +tools/** node_modules/** out-test/** package-lock.json diff --git a/vscode/esbuild.mjs b/vscode/esbuild.mjs index 73f47fb..03fabbd 100644 --- a/vscode/esbuild.mjs +++ b/vscode/esbuild.mjs @@ -1,4 +1,5 @@ import * as esbuild from "esbuild"; +import { languageClientGlobCompatibility } from "./tools/minimatch-client-compat.mjs"; const watching = process.argv.includes("--watch"); const production = process.argv.includes("--production"); @@ -13,6 +14,7 @@ const context = await esbuild.context({ target: "node20", sourcemap: production ? false : "inline", minify: false, + plugins: [languageClientGlobCompatibility()], logLevel: "info" }); diff --git a/vscode/package-lock.json b/vscode/package-lock.json index 3fb51b0..9cc0bd4 100644 --- a/vscode/package-lock.json +++ b/vscode/package-lock.json @@ -9,7 +9,7 @@ "version": "1.0.0-rc.1", "license": "MIT", "dependencies": { - "vscode-languageclient": "^10.1.1" + "vscode-languageclient": "10.1.1" }, "devDependencies": { "@types/node": "^22.20.2", @@ -653,6 +653,12 @@ "node": ">=18" } }, + "node_modules/@isaacs/nonrecursive-glob-match": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@isaacs/nonrecursive-glob-match/-/nonrecursive-glob-match-1.1.0.tgz", + "integrity": "sha512-GPm/Dbvk5RLmhRnxXIa7nTpK0xtl4E0wj0MslsuNiJ1FIROU+2+9lgUC/dgF7Ey4QCWhfEsgxilMRMCdHPfDfw==", + "license": "BlueOak-1.0.0" + }, "node_modules/@napi-rs/keyring": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/@napi-rs/keyring/-/keyring-1.3.0.tgz", @@ -2202,15 +2208,16 @@ } }, "node_modules/minimatch": { - "version": "10.2.6", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.6.tgz", - "integrity": "sha512-vpLQEs+VLCr1nU0BXS07maYoFwlDAH0gngQuuttxIwutDFEMHq2blX+8vpgxDdK3J1PwjCJiep77OitTZ4Ll1A==", + "version": "11.0.9", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-11.0.9.tgz", + "integrity": "sha512-KCFkfyjqerNlSstjlhIGNXIKZGA/6O4V4RlhZ+Dsr621SPPw0mzlypE9D9ZOoPiVefHID+j7/XuMMlqfD/F60Q==", "license": "BlueOak-1.0.0", "dependencies": { - "brace-expansion": "^5.0.8" + "@isaacs/nonrecursive-glob-match": "^1.1.0", + "brace-expansion": "^5.0.12" }, "engines": { - "node": "18 || 20 || >=22" + "node": "20 || >=22" }, "funding": { "url": "https://github.com/sponsors/isaacs" diff --git a/vscode/package.json b/vscode/package.json index c0ec683..abc18ef 100644 --- a/vscode/package.json +++ b/vscode/package.json @@ -87,7 +87,7 @@ "test:host": "npm run build && node test/run-host.cjs" }, "dependencies": { - "vscode-languageclient": "^10.1.1" + "vscode-languageclient": "10.1.1" }, "devDependencies": { "@types/node": "^22.20.2", @@ -610,6 +610,7 @@ ] }, "overrides": { + "minimatch": "11.0.9", "@azure/identity": { "@azure/msal-node": "7.1.1" } diff --git a/vscode/src/test/minimatchCompat.test.ts b/vscode/src/test/minimatchCompat.test.ts new file mode 100644 index 0000000..8f5f2d6 --- /dev/null +++ b/vscode/src/test/minimatchCompat.test.ts @@ -0,0 +1,2 @@ +// Exercise the actual bundled language-client consumers in the normal suite. +require("../../test/minimatch-compat.test.cjs"); diff --git a/vscode/test/minimatch-compat.test.cjs b/vscode/test/minimatch-compat.test.cjs new file mode 100644 index 0000000..ea9bc13 --- /dev/null +++ b/vscode/test/minimatch-compat.test.cjs @@ -0,0 +1,162 @@ +const assert = require("node:assert/strict"); +const { before, after, test } = require("node:test"); +const { createRequire } = require("node:module"); +const path = require("node:path"); +const vm = require("node:vm"); +const esbuild = require("esbuild"); +const { Minimatch, minimatch } = require("minimatch"); + +const clientRoot = path.resolve(path.dirname(require.resolve("vscode-languageclient/node")), "../.."); +const globConsumer = path.join(clientRoot, "lib/common/utils/globPattern.js"); +const fileConsumer = path.join(clientRoot, "lib/common/fileOperations.js"); +let adaptLanguageClientGlobGuard; +let languageClientGlobCompatibility; +let consumers; +const entry = `export { matchGlobPattern } from ${JSON.stringify(globConsumer)}; +export { DidCreateFilesFeature } from ${JSON.stringify(fileConsumer)};`; +const buildOptions = { bundle: true, write: false, platform: "node", format: "cjs", + target: "node20", external: ["vscode"], logLevel: "silent" }; + +function uri(fsPath, scheme = "file", directory = false) { + return { fsPath, scheme, directory, toString: () => `${scheme}://${fsPath}` }; +} +function loadBundle(contents) { + const vscode = { + FileType: { File: 1, Directory: 2 }, + workspace: { + onDidCreateFiles: () => ({ dispose() {} }), + fs: { stat: async value => ({ type: value.directory ? 2 : 1 }) } + }, + Uri: { parse(value) { + const parsed = new URL(value); + const basePath = decodeURIComponent(parsed.pathname); + return { path: basePath, with: change => uri(change.path, parsed.protocol.slice(0, -1)) }; + } } + }; + const module = { exports: {} }; + const wrapper = vm.runInThisContext(`(function(require, module, exports) {\n${contents}\n})`); + wrapper(name => name === "vscode" ? vscode : require(name), module, module.exports); + return module.exports; +} +function feature() { + return new consumers.DidCreateFilesFeature({ + code2ProtocolConverter: { asDidCreateFilesParams: event => event }, + warn() {}, info() {} + }); +} + +before(async () => { + ({ adaptLanguageClientGlobGuard, languageClientGlobCompatibility } = + await import("../tools/minimatch-client-compat.mjs")); + const bundle = await esbuild.build({ ...buildOptions, stdin: { contents: entry, resolveDir: clientRoot }, + plugins: [languageClientGlobCompatibility()] }); + consumers = loadBundle(bundle.outputFiles[0].text); +}); +after(() => esbuild.stop()); + +test("every language-client and packaging matcher resolves the patched version", () => { + const lock = require("../package-lock.json"); + const matchers = Object.entries(lock.packages).filter(([name]) => name.endsWith("/minimatch")); + assert.equal(matchers.length, 1); + assert.equal(matchers[0][1].version, "11.0.9"); + for (const parent of ["vscode-languageclient/node", "@vscode/vsce"]) { + const fromParent = createRequire(require.resolve(parent)); + assert.equal(fromParent("minimatch/package.json").version, "11.0.9"); + } + assert.equal(Minimatch.prototype.makeRe, undefined, "no legacy RegExp shim is installed"); +}); + +test("unadapted upstream consumers expose the removed API regression", async () => { + const bundle = await esbuild.build({ ...buildOptions, stdin: { contents: entry, resolveDir: clientRoot } }); + const upstream = loadBundle(bundle.outputFiles[0].text); + assert.throws(() => upstream.matchGlobPattern("**/*.ny", uri("/workspace/main.ny")), /makeRe/); +}); + +test("glob validity adaptation fails closed when upstream call sites change", async () => { + assert.throws(() => adaptLanguageClientGlobGuard("matcher.match(path)"), /changed/); + assert.throws(() => adaptLanguageClientGlobGuard("if (!matcher.makeRe()) { if (!matcher.makeRe()) {"), /changed/); + await assert.rejects(esbuild.build({ ...buildOptions, + stdin: { contents: `export * from ${JSON.stringify(globConsumer)};`, resolveDir: clientRoot }, + plugins: [languageClientGlobCompatibility()] }), /both reviewed/); +}); + +test("incremental bundling retains both reviewed glob consumers", async () => { + const context = await esbuild.context({ ...buildOptions, + stdin: { contents: entry, resolveDir: clientRoot }, + plugins: [languageClientGlobCompatibility()] }); + try { + for (let build = 0; build < 2; build++) { + const result = await context.rebuild(); + assert.equal(loadBundle(result.outputFiles[0].text) + .matchGlobPattern("**/*.ny", uri("/workspace/main.ny")), true); + } + } finally { await context.dispose(); } +}); + +test("bundled language-client globs retain ordinary, escaped and Unicode matching", () => { + for (const [pattern, filename, expected] of [ + ["**/*.{ny,matrix,mat}", "/workspace/main.ny", true], + ["**/*.{ny,matrix,mat}", "/workspace/main.cpp", false], + ["**/file?.ny", "/workspace/file1.ny", true], + ["**/file[0-9].ny", "/workspace/filea.ny", false], + ["**/*.ny", "/workspace/.hidden.ny", false], + ["**/.hidden.ny", "/workspace/.hidden.ny", true], + ["**/café 中文.matrix", "/workspace/café 中文.matrix", true], + ["**/[[]name].ny", "/workspace/[name].ny", true], + ["**/@(first|second).ny", "/workspace/first.ny", false], + ["**/@(first|second).ny", "/workspace/@(first|second).ny", true], + ["**/unfinished[.ny", "/workspace/unfinished[.ny", true], + ["!**/*.ny", "/workspace/main.matrix", true], + ["!**/*.ny", "/workspace/main.ny", false], + ["", "", false], ["#comment", "#comment", false] + ]) assert.equal(consumers.matchGlobPattern(pattern, uri(filename)), expected, `${pattern}: ${filename}`); + assert.equal(consumers.matchGlobPattern({ baseUri: "file:///workspace/caf%C3%A9", pattern: "*.ny" }, + uri("/workspace/café/main.ny")), true); + assert.equal(consumers.matchGlobPattern({ baseUri: "invalid URI", pattern: "*.ny" }, uri("main.ny")), false); +}); + +test("bundled file operations retain dotfiles, case options, schemes and file kinds", async () => { + const registered = feature(); + try { + registered.register({ id: "source", registerOptions: { filters: [ + { scheme: "file", pattern: { glob: "**/*.{ny,matrix}", matches: "file", options: { ignoreCase: true } } } + ] } }); + const files = [uri("/workspace/.hidden.ny"), uri("/workspace/MAIN.NY"), + uri("/workspace/data.matrix"), uri("/workspace/other.txt"), uri("/workspace/main.ny", "untitled"), + uri("/workspace/folder.ny", "file", true), uri("C:\\workspace\\other.ny")]; + assert.deepEqual((await registered.filter({ files }, value => value)).files, + [files[0], files[1], files[2], files[6]]); + registered.unregister("source"); + assert.deepEqual((await registered.filter({ files }, value => value)).files, []); + } finally { registered.clear(); } +}); + +test("bundled file operations keep invalid registrations out of the filter set", () => { + const registered = feature(); + try { + for (const glob of ["", "#comment"]) { + assert.throws(() => registered.register({ id: "invalid", registerOptions: { filters: [{ pattern: { glob } }] } }), /Invalid pattern/); + assert.equal(registered.filterSize(), 0); + } + } finally { registered.clear(); } +}); + +test("patched matcher retains Windows drive, UNC and POSIX glob semantics", () => { + for (const [filename, pattern, options, expected] of [ + ["C:\\work\\main.ny", "C:/work/*.ny", { platform: "win32" }, true], + ["C:\\work\\MAIN.NY", "C:/work/*.ny", { platform: "win32" }, false], + ["C:\\work\\MAIN.NY", "c:/work/*.ny", { platform: "win32", nocase: true }, true], + ["\\\\server\\share\\main.ny", "//server/share/*.ny", { platform: "win32" }, true], + ["//?/C:/work/main.ny", "C:/work/*.ny", { platform: "win32" }, true], + ["/workspace/.config/a.ny", "**/*.ny", { platform: "linux", dot: true }, true], + ["/workspace/.config/a.ny", "**/*.ny", { platform: "darwin", dot: false }, false] + ]) assert.equal(minimatch(filename, pattern, options), expected, `${pattern}: ${filename}`); +}); + +test("bounded optimization-level-2 fixtures enforce the patched expansion limit", () => { + // Tiny explicit limits make these regression inputs bounded even on failure. + assert.throws(() => new Minimatch("**/../a/b/".repeat(8) + "file.ny", + { optimizationLevel: 2, braceExpandMax: 4 }), + { name: "RangeError", message: "optimizationLevel 2: too many patterns from '**/..'" }); + assert.equal(new Minimatch("**/../a/b/file.ny", { optimizationLevel: 2, braceExpandMax: 4 }).match("a/b/file.ny"), true); +}); diff --git a/vscode/tools/minimatch-client-compat.mjs b/vscode/tools/minimatch-client-compat.mjs new file mode 100644 index 0000000..a497940 --- /dev/null +++ b/vscode/tools/minimatch-client-compat.mjs @@ -0,0 +1,56 @@ +import { readFile } from "node:fs/promises"; +import { createRequire } from "node:module"; +import path from "node:path"; + +const require = createRequire(import.meta.url); +const clientVersion = "10.1.1"; +const matcherVersion = "11.0.9"; +const consumers = ["lib/common/fileOperations.js", "lib/common/utils/globPattern.js"]; +const oldGuard = "if (!matcher.makeRe()) {"; + +// Minimatch 11 deliberately no longer creates regular expressions. These two +// upstream callers only use makeRe() as a boolean validity check before match(). +// Empty/comment patterns have an empty parsed set and must remain rejected. +// Keep that check using the documented set property, without fabricating a RegExp API +// or changing the matcher prototype. Constructor errors remain errors. +export function adaptLanguageClientGlobGuard(source) { + if (source.split(oldGuard).length !== 2 || (source.match(/\.makeRe\s*\(/g) || []).length !== 1) { + throw new Error("Language client glob validation changed; review its minimatch compatibility before bundling"); + } + return source.replace(oldGuard, "if (matcher.set.length === 0) {"); +} + +// Apply the reviewed adaptation only to the exact pinned consumer files in the +// production bundle. Leave installed packages untouched, and fail the build if +// dependency updates change either API or remove one of the expected consumers. +export function languageClientGlobCompatibility() { + const clientRoot = path.resolve(path.dirname(require.resolve("vscode-languageclient/node")), "../.."); + const clientManifest = path.join(clientRoot, "package.json"); + const files = new Set(consumers.map(file => path.join(clientRoot, file))); + const seen = new Set(); + return { + name: "language-client-minimatch-11", + setup(build) { + build.onStart(async () => { + seen.clear(); + const client = JSON.parse(await readFile(clientManifest, "utf8")); + const fromClient = createRequire(clientManifest); + const matcher = fromClient("minimatch/package.json"); + if (client.version !== clientVersion || matcher.version !== matcherVersion) { + throw new Error("Language client/minimatch versions changed; review the glob compatibility adaptation"); + } + }); + build.onLoad({ filter: /[/\\]vscode-languageclient[/\\]lib[/\\]common[/\\].*\.js$/ }, async args => { + if (!files.has(args.path)) return; + const contents = adaptLanguageClientGlobGuard(await readFile(args.path, "utf8")); + seen.add(args.path); + return { contents, loader: "js", resolveDir: path.dirname(args.path) }; + }); + build.onEnd(result => { + if (result.errors.length === 0 && seen.size !== files.size) { + return { errors: [{ text: "The extension must bundle both reviewed language-client glob consumers" }] }; + } + }); + } + }; +}