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:
Pavan Kumar Gondhi 2026-07-07 15:22:20 +05:30 committed by GitHub
parent 7e995cbf2b
commit 9133d552ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 5 deletions

View file

@ -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");

View file

@ -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.",
);