test: add env -S allowlist bypass regressions

This commit is contained in:
Peter Steinberger
2026-02-24 02:27:22 +00:00
parent 6634030be3
commit 3f923e8313
4 changed files with 50 additions and 2 deletions

View File

@@ -254,6 +254,35 @@ describe("exec approvals command resolution", () => {
expect(resolution?.rawExecutable).toBe("/usr/bin/env");
});
it("fails closed for env -S even when env itself is allowlisted", () => {
const dir = makeTempDir();
const binDir = path.join(dir, "bin");
fs.mkdirSync(binDir, { recursive: true });
const envName = process.platform === "win32" ? "env.exe" : "env";
const envPath = path.join(binDir, envName);
fs.writeFileSync(envPath, process.platform === "win32" ? "" : "#!/bin/sh\n");
if (process.platform !== "win32") {
fs.chmodSync(envPath, 0o755);
}
const analysis = analyzeArgvCommand({
argv: [envPath, "-S", 'sh -c "echo pwned"'],
cwd: dir,
env: makePathEnv(binDir),
});
const allowlistEval = evaluateExecAllowlist({
analysis,
allowlist: [{ pattern: envPath }],
safeBins: normalizeSafeBins([]),
cwd: dir,
});
expect(analysis.ok).toBe(true);
expect(analysis.segments[0]?.resolution?.policyBlocked).toBe(true);
expect(allowlistEval.allowlistSatisfied).toBe(false);
expect(allowlistEval.segmentSatisfiedBy).toEqual([null]);
});
it("unwraps env wrapper with shell inner executable", () => {
const resolution = resolveCommandResolutionFromArgv(["/usr/bin/env", "bash", "-lc", "echo hi"]);
expect(resolution?.rawExecutable).toBe("bash");