mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 02:01:25 +00:00
test: add env -S allowlist bypass regressions
This commit is contained in:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user