From 7b12cd6ad57ac20c103aca3f8292e30b94e73211 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 23 Jun 2026 20:37:04 +0000 Subject: [PATCH] feat(agent-audit): cover OpenCode + Codex agents MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Broadens kit's agent coverage beyond Claude/Cursor/VSCode: - agent-audit: scan `opencode.json`/`opencode.jsonc` and `.codex/config.*` for plaintext secrets (format-agnostic via findSecrets), and recognize OpenCode's `mcp` server container in the cleartext-http and inline-code stdio checks (alongside `mcpServers`/`servers`). - scan-transcripts: walk `.codex/` (project) + `~/.codex/projects/` for replayed-secret leaks, alongside the existing `.claude`/`.opencode`/`.cursor`/ `.aider` dirs. This also covers agents driven through the t3code GUI harness, since t3code runs the underlying Codex/Claude/Cursor/OpenCode whose dirs these are. (Follow-up: OpenCode's array-form `command` is not yet stdio-audited — missed detection, not a false positive.) Stacked on the stdio-MCP-audit branch. Co-Authored-By: Claude Opus 4.8 (1M context) Claude-Session: https://claude.ai/code/session_015ERHw6bVUz39sAuoQZ1iyg --- src/agent-audit.test.ts | 23 +++++++++++++++++++++++ src/agent-audit.ts | 9 +++++++++ src/scan-transcripts.test.ts | 13 +++++++++++++ src/scan-transcripts.ts | 6 ++++-- 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/agent-audit.test.ts b/src/agent-audit.test.ts index 3b6eb7fd..9382b244 100644 --- a/src/agent-audit.test.ts +++ b/src/agent-audit.test.ts @@ -99,3 +99,26 @@ describe("auditMcpStdio", () => { assert.deepEqual(auditMcpStdio("not json"), []); }); }); + +describe("OpenCode `mcp` container coverage", () => { + it("flags a cleartext http:// remote server nested under `mcp`", () => { + const cfg = JSON.stringify({ + mcp: { + local: { type: "remote", url: "http://mcp.internal:8080" }, + good: { type: "remote", url: "https://mcp.ok" }, + }, + }); + const hits = auditMcpServers(cfg); + assert.equal(hits.length, 1); + assert.match(hits[0], /^local → http:\/\//); + }); + + it("flags an inline-code stdio server nested under `mcp`", () => { + const cfg = JSON.stringify({ + mcp: { evil: { command: "node", args: ["-e", "doBadThings()"] } }, + }); + const hits = auditMcpStdio(cfg); + assert.equal(hits.length, 1); + assert.equal(hits[0].server, "evil"); + }); +}); diff --git a/src/agent-audit.ts b/src/agent-audit.ts index 907b02fc..7787fb4d 100644 --- a/src/agent-audit.ts +++ b/src/agent-audit.ts @@ -39,6 +39,7 @@ export function auditMcpServers(json: string): string[] { const containers = [ (obj as { mcpServers?: Record })?.mcpServers, (obj as { servers?: Record })?.servers, + (obj as { mcp?: Record })?.mcp, // OpenCode nests servers under `mcp` ].filter((c): c is Record => !!c && typeof c === "object"); for (const servers of containers) { for (const [name, def] of Object.entries(servers)) { @@ -110,6 +111,7 @@ export function auditMcpStdio(json: string): StdioMcpFinding[] { const containers = [ (obj as { mcpServers?: Record })?.mcpServers, (obj as { servers?: Record })?.servers, + (obj as { mcp?: Record })?.mcp, // OpenCode nests servers under `mcp` ].filter((c): c is Record => !!c && typeof c === "object"); const out: StdioMcpFinding[] = []; for (const servers of containers) { @@ -154,6 +156,13 @@ const CONFIG_FILES = [ ".vscode/mcp.json", ".claude/settings.json", ".claude/settings.local.json", + // OpenCode (project config carries an `mcp` block) + Codex CLI. secrets-in-config + // is format-agnostic (findSecrets reads raw text); the JSON-shaped MCP checks + // simply no-op on the TOML files. + "opencode.json", + "opencode.jsonc", + ".codex/config.toml", + ".codex/config.json", ]; const HOOK_DIRS = [".git/hooks", ".githooks", ".husky"]; diff --git a/src/scan-transcripts.test.ts b/src/scan-transcripts.test.ts index c457e4ff..f957e2af 100644 --- a/src/scan-transcripts.test.ts +++ b/src/scan-transcripts.test.ts @@ -66,4 +66,17 @@ describe("scanTranscripts", () => { rmSync(dir, { recursive: true, force: true }); } }); + + it("scans the Codex CLI .codex dir", async () => { + const dir = makeRepo(); + try { + mkdirSync(join(dir, ".codex"), { recursive: true }); + writeFileSync(join(dir, ".codex", "session.jsonl"), '{"text":"AKIA0123456789ABCDEF"}\n'); + const hits = await scanTranscripts(dir); + assert.equal(hits.length, 1); + assert.ok(hits[0].file.includes(".codex")); + } finally { + rmSync(dir, { recursive: true, force: true }); + } + }); }); diff --git a/src/scan-transcripts.ts b/src/scan-transcripts.ts index ac5b4395..a977d07c 100644 --- a/src/scan-transcripts.ts +++ b/src/scan-transcripts.ts @@ -14,6 +14,7 @@ import { findSecrets, type SecretFinding } from "./utils/redactSecrets.js"; * Scans: * - `/.claude/` — project-local Claude Code state * - `/.opencode/` — OpenCode local state + * - `/.codex/` — Codex CLI local state * - `~/.claude/projects//` — global Claude Code project cache * - `~/.claude/projects/-/` — same, with normalized slashes * @@ -72,17 +73,18 @@ export async function scanTranscripts(cwd: string = process.cwd()): Promise