Infra: tighten exec allowlist glob matching (#43798)

* Infra: tighten exec allowlist glob matching

* Changelog: note GHSA-f8r2 exec allowlist fix
This commit is contained in:
Vincent Koc
2026-03-12 03:33:50 -04:00
committed by GitHub
parent d8ee97c466
commit 82e3ac21ee
3 changed files with 18 additions and 3 deletions

View File

@@ -0,0 +1,14 @@
import { describe, expect, it } from "vitest";
import { matchesExecAllowlistPattern } from "./exec-allowlist-pattern.js";
describe("matchesExecAllowlistPattern", () => {
it("does not let ? cross path separators", () => {
expect(matchesExecAllowlistPattern("/tmp/a?b", "/tmp/a/b")).toBe(false);
expect(matchesExecAllowlistPattern("/tmp/a?b", "/tmp/acb")).toBe(true);
});
it.runIf(process.platform !== "win32")("preserves case sensitivity on POSIX", () => {
expect(matchesExecAllowlistPattern("/tmp/Allowed-Tool", "/tmp/allowed-tool")).toBe(false);
expect(matchesExecAllowlistPattern("/tmp/Allowed-Tool", "/tmp/Allowed-Tool")).toBe(true);
});
});

View File

@@ -9,7 +9,7 @@ function normalizeMatchTarget(value: string): string {
const stripped = value.replace(/^\\\\[?.]\\/, "");
return stripped.replace(/\\/g, "/").toLowerCase();
}
return value.replace(/\\\\/g, "/").toLowerCase();
return value.replace(/\\\\/g, "/");
}
function tryRealpath(value: string): string | null {
@@ -46,7 +46,7 @@ function compileGlobRegex(pattern: string): RegExp {
continue;
}
if (ch === "?") {
regex += ".";
regex += "[^/]";
i += 1;
continue;
}
@@ -55,7 +55,7 @@ function compileGlobRegex(pattern: string): RegExp {
}
regex += "$";
const compiled = new RegExp(regex, "i");
const compiled = new RegExp(regex, process.platform === "win32" ? "i" : "");
if (globRegexCache.size >= GLOB_REGEX_CACHE_LIMIT) {
globRegexCache.clear();
}