mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-10 00:11:19 +00:00
fix: block mixed-case cron shell jobs from agent tool [AI] (#101350)
* fix: normalize cron tool shell guard kinds * fix(cron): narrow mixed-case shell guard --------- Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
parent
7e995cbf2b
commit
9133d552ac
2 changed files with 11 additions and 5 deletions
|
|
@ -1046,7 +1046,10 @@ describe("cron tool", () => {
|
|||
expect(params?.failureAlert).toBe(false);
|
||||
});
|
||||
|
||||
it("rejects command payloads from the agent cron tool on add", async () => {
|
||||
it.each([
|
||||
["canonical", "command"],
|
||||
["mixed-case", "Command"],
|
||||
])("rejects %s command payloads from the agent cron tool on add", async (_case, kind) => {
|
||||
const tool = createTestCronTool();
|
||||
|
||||
await expect(
|
||||
|
|
@ -1056,7 +1059,7 @@ describe("cron tool", () => {
|
|||
name: "command",
|
||||
schedule: { at: new Date(123).toISOString() },
|
||||
sessionTarget: "isolated",
|
||||
payload: { kind: "command", argv: ["sh", "-lc", "echo ok"] },
|
||||
payload: { kind, argv: ["sh", "-lc", "echo ok"] },
|
||||
},
|
||||
}),
|
||||
).rejects.toThrow("cron command payloads cannot be created or edited");
|
||||
|
|
@ -2073,7 +2076,10 @@ describe("cron tool", () => {
|
|||
expect(params?.patch?.failureAlert).toBe(false);
|
||||
});
|
||||
|
||||
it("rejects command payloads from the agent cron tool on update", async () => {
|
||||
it.each([
|
||||
["canonical", "command"],
|
||||
["mixed-case", "Command"],
|
||||
])("rejects %s command payloads from the agent cron tool on update", async (_case, kind) => {
|
||||
const tool = createTestCronTool();
|
||||
|
||||
await expect(
|
||||
|
|
@ -2081,7 +2087,7 @@ describe("cron tool", () => {
|
|||
action: "update",
|
||||
id: "job-4",
|
||||
patch: {
|
||||
payload: { kind: "command", argv: ["sh", "-lc", "echo ok"] },
|
||||
payload: { kind, argv: ["sh", "-lc", "echo ok"] },
|
||||
},
|
||||
}),
|
||||
).rejects.toThrow("cron command payloads cannot be created or edited");
|
||||
|
|
|
|||
|
|
@ -444,7 +444,7 @@ function assertNoCronShellExecution(value: unknown): void {
|
|||
return;
|
||||
}
|
||||
const payload = isRecord(value.payload) ? value.payload : undefined;
|
||||
if (payload?.kind === "command") {
|
||||
if (normalizeLowercaseStringOrEmpty(payload?.kind) === "command") {
|
||||
throw new Error(
|
||||
"cron command payloads cannot be created or edited through the agent cron tool; use the CLI or Gateway API.",
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue