fix: harden Windows exec allowlist

This commit is contained in:
Peter Steinberger
2026-02-03 09:34:08 -08:00
parent 8f3bfbd1c4
commit a7f4a53ce8
5 changed files with 170 additions and 2 deletions

View File

@@ -161,6 +161,24 @@ describe("exec approvals shell parsing", () => {
expect(res.ok).toBe(true);
expect(res.segments[0]?.argv[0]).toBe("echo");
});
it("rejects windows shell metacharacters", () => {
const res = analyzeShellCommand({
command: "ping 127.0.0.1 -n 1 & whoami",
platform: "win32",
});
expect(res.ok).toBe(false);
expect(res.reason).toBe("unsupported windows shell token: &");
});
it("parses windows quoted executables", () => {
const res = analyzeShellCommand({
command: '"C:\\Program Files\\Tool\\tool.exe" --version',
platform: "win32",
});
expect(res.ok).toBe(true);
expect(res.segments[0]?.argv).toEqual(["C:\\Program Files\\Tool\\tool.exe", "--version"]);
});
});
describe("exec approvals shell allowlist (chained commands)", () => {
@@ -227,6 +245,19 @@ describe("exec approvals shell allowlist (chained commands)", () => {
expect(result.analysisOk).toBe(true);
expect(result.allowlistSatisfied).toBe(true);
});
it("rejects windows chain separators for allowlist analysis", () => {
const allowlist: ExecAllowlistEntry[] = [{ pattern: "/usr/bin/ping" }];
const result = evaluateShellAllowlist({
command: "ping 127.0.0.1 -n 1 & whoami",
allowlist,
safeBins: new Set(),
cwd: "/tmp",
platform: "win32",
});
expect(result.analysisOk).toBe(false);
expect(result.allowlistSatisfied).toBe(false);
});
});
describe("exec approvals safe bins", () => {