fix(coding-agent): stop tool argument injection

closes #4018
This commit is contained in:
Mario Zechner
2026-04-30 21:31:43 +02:00
parent fe66edd943
commit 3d43d2e175
4 changed files with 29 additions and 2 deletions

View File

@@ -617,6 +617,23 @@ describe("Coding Agent Tools", () => {
// Ensure second match is not present
expect(output).not.toContain("match two");
});
it("should treat flag-like patterns as search text", async () => {
const marker = join(testDir, "grep-injection-marker");
const payload = join(testDir, "payload.sh");
const testFile = join(testDir, "target.txt");
writeFileSync(payload, `#!/bin/sh\necho executed > ${marker}\ncat "$1"\n`);
chmodSync(payload, 0o755);
writeFileSync(testFile, "target\n");
const result = await grepTool.execute("test-call-grep-injection", {
pattern: `--pre=${payload}`,
path: testDir,
});
expect(getTextOutput(result)).toContain("No matches found");
expect(existsSync(marker)).toBe(false);
});
});
describe("find tool", () => {
@@ -663,6 +680,15 @@ describe("Coding Agent Tools", () => {
}),
).rejects.toThrow(/error parsing glob|fd exited with code 1|fd error/i);
});
it("should treat flag-like patterns as search text", async () => {
const result = await findTool.execute("test-call-find-flag-pattern", {
pattern: "--help",
path: testDir,
});
expect(getTextOutput(result)).toContain("No files found matching pattern");
});
});
describe("ls tool", () => {