mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 21:39:34 +00:00
fix(security): enforce strict environment variable validation in exec tool (#4896)
This commit is contained in:
@@ -86,7 +86,7 @@ describe("exec PATH login shell merge", () => {
|
||||
expect(shellPathMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("skips login-shell PATH when env.PATH is provided", async () => {
|
||||
it("throws security violation when env.PATH is provided", async () => {
|
||||
if (isWin) {
|
||||
return;
|
||||
}
|
||||
@@ -98,13 +98,14 @@ describe("exec PATH login shell merge", () => {
|
||||
shellPathMock.mockClear();
|
||||
|
||||
const tool = createExecTool({ host: "gateway", security: "full", ask: "off" });
|
||||
const result = await tool.execute("call1", {
|
||||
command: "echo $PATH",
|
||||
env: { PATH: "/explicit/bin" },
|
||||
});
|
||||
const entries = normalizePathEntries(result.content.find((c) => c.type === "text")?.text);
|
||||
|
||||
expect(entries).toEqual(["/explicit/bin"]);
|
||||
await expect(
|
||||
tool.execute("call1", {
|
||||
command: "echo $PATH",
|
||||
env: { PATH: "/explicit/bin" },
|
||||
}),
|
||||
).rejects.toThrow(/Security Violation: Custom 'PATH' variable is forbidden/);
|
||||
|
||||
expect(shellPathMock).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user