fix(security): harden node exec approvals against symlink rebind
This commit is contained in:
@@ -471,6 +471,44 @@ describe("exec approval handlers", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("prefers systemRunPlanV2 canonical command/cwd when present", async () => {
|
||||
const { handlers, broadcasts, respond, context } = createExecApprovalFixture();
|
||||
await requestExecApproval({
|
||||
handlers,
|
||||
respond,
|
||||
context,
|
||||
params: {
|
||||
command: "echo stale",
|
||||
commandArgv: ["echo", "stale"],
|
||||
cwd: "/tmp/link/sub",
|
||||
systemRunPlanV2: {
|
||||
version: 2,
|
||||
argv: ["/usr/bin/echo", "ok"],
|
||||
cwd: "/real/cwd",
|
||||
rawCommand: "/usr/bin/echo ok",
|
||||
agentId: "main",
|
||||
sessionKey: "agent:main:main",
|
||||
},
|
||||
},
|
||||
});
|
||||
const requested = broadcasts.find((entry) => entry.event === "exec.approval.requested");
|
||||
expect(requested).toBeTruthy();
|
||||
const request = (requested?.payload as { request?: Record<string, unknown> })?.request ?? {};
|
||||
expect(request["command"]).toBe("/usr/bin/echo ok");
|
||||
expect(request["commandArgv"]).toEqual(["/usr/bin/echo", "ok"]);
|
||||
expect(request["cwd"]).toBe("/real/cwd");
|
||||
expect(request["agentId"]).toBe("main");
|
||||
expect(request["sessionKey"]).toBe("agent:main:main");
|
||||
expect(request["systemRunPlanV2"]).toEqual({
|
||||
version: 2,
|
||||
argv: ["/usr/bin/echo", "ok"],
|
||||
cwd: "/real/cwd",
|
||||
rawCommand: "/usr/bin/echo ok",
|
||||
agentId: "main",
|
||||
sessionKey: "agent:main:main",
|
||||
});
|
||||
});
|
||||
|
||||
it("accepts resolve during broadcast", async () => {
|
||||
const manager = new ExecApprovalManager();
|
||||
const handlers = createExecApprovalHandlers(manager);
|
||||
|
||||
Reference in New Issue
Block a user