Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions notebook/2026-11-21-editor-minimatch.md
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions vscode/.vscodeignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.gitignore
esbuild.mjs
tools/**
node_modules/**
out-test/**
package-lock.json
Expand Down
2 changes: 2 additions & 0 deletions vscode/esbuild.mjs
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -13,6 +14,7 @@ const context = await esbuild.context({
target: "node20",
sourcemap: production ? false : "inline",
minify: false,
plugins: [languageClientGlobCompatibility()],
logLevel: "info"
});

Expand Down
19 changes: 13 additions & 6 deletions vscode/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -610,6 +610,7 @@
]
},
"overrides": {
"minimatch": "11.0.9",
"@azure/identity": {
"@azure/msal-node": "7.1.1"
}
Expand Down
2 changes: 2 additions & 0 deletions vscode/src/test/minimatchCompat.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Exercise the actual bundled language-client consumers in the normal suite.
require("../../test/minimatch-compat.test.cjs");
162 changes: 162 additions & 0 deletions vscode/test/minimatch-compat.test.cjs
Original file line number Diff line number Diff line change
@@ -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);
});
Loading
Loading