mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 11:01:24 +00:00
fix: harden Windows exec allowlist
This commit is contained in:
@@ -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", () => {
|
||||
|
||||
Reference in New Issue
Block a user