OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security
TypeScript ai-securityapplication-securityclicode-scanningcodexcodex-securitycybersecuritydevsecopsnodejsnpmopenaisdksecuritytypescriptvulnerability-scanning
fix(plugin): preserve MCP connections for large scan checkpoints (#1873)
Michael D'Angelod60d56d5040a
diff --git a/plugins/codex-security/mcp-app/main.ts b/plugins/codex-security/mcp-app/main.tsindex 4ec8dbaf4..87c750b1b 100644--- a/plugins/codex-security/mcp-app/main.ts+++ b/plugins/codex-security/mcp-app/main.ts@@ -12,7 +12,12 @@ async function main(): Promise<void> {const server = artifactWriter? await createCodexSecurityArtifactWriterServer(): createCodexSecurityServer();- await server.connect(new StdioServerTransport());+ await server.connect(+ new StdioServerTransport(process.stdin, process.stdout, {+ // Local scan checkpoints can exceed the SDK's default 10 MiB buffer.+ maxBufferSize: Infinity,+ }),+ );let closing = false;const close = async (exitCode?: number): Promise<void> => {if (closing) return;diff --git a/plugins/codex-security/mcp-app/tests/test_compact_artifact_server.ts b/plugins/codex-security/mcp-app/tests/test_compact_artifact_server.tsindex 4f76bfd67..bd306d6f8 100644--- a/plugins/codex-security/mcp-app/tests/test_compact_artifact_server.ts+++ b/plugins/codex-security/mcp-app/tests/test_compact_artifact_server.ts@@ -78,6 +78,9 @@ try {await testParentToolList(bundle);await testClaimedParentArtifactOperations(bundle, runtimeLabel);await testSemanticScanDraftCompletion(bundle, runtimeLabel);+ for (const artifactWriter of [false, true]) {+ await testLargeScanDraftCheckpoints(bundle, runtimeLabel, artifactWriter);+ }await testCompactDiffScanCompletion(bundle, runtimeLabel);await testDiscoveryWorkerToolList(bundle);await testReducerWorkerToolList(bundle);@@ -97,6 +100,104 @@ async function createScanFixture(label: string) {return { repoRoot, environment };}+async function testLargeScanDraftCheckpoints(+ bundle: string,+ runtimeLabel: string,+ artifactWriter: boolean,+) {+ const label = `large-draft-${runtimeLabel}-${artifactWriter ? "worker" : "parent"}`;+ const { repoRoot, environment } = await createScanFixture(label);+ await writeFile(path.join(repoRoot, "src", "fixture.py"), "value = 1\n");+ let scanId: string = randomUUID();+ let scanDir = path.join(temporaryRoot, label, "output");+ let handoffClaimToken: string | undefined;+ if (artifactWriter) await mkdir(scanDir);+ const client = await startClient(bundle, {+ ...environment,+ ...(artifactWriter+ ? {+ CODEX_SECURITY_ARTIFACT_ROOT: scanDir,+ CODEX_SECURITY_REPO_ROOT: repoRoot,+ CODEX_SECURITY_ARTIFACT_LAYOUT: "worker",+ CODEX_SECURITY_SCAN_ID: scanId,+ CODEX_SECURITY_PLUGIN_ROOT: bundledPluginRoot,+ }+ : {}),+ });+ const ownerThread = `${label}-owner`;+ const call = toolCaller(client, ownerThread);++ try {+ if (!artifactWriter) {+ ({ scanId, scanDir, handoffClaimToken } = await startScan(+ call,+ ownerThread,+ { targetPath: repoRoot, scope: ".", mode: "standard" },+ {+ workspace: `${label}: open workspace`,+ setup: `${label}: submit setup`,+ scan: `${label}: start scan`,+ claim: `${label}: claim scan`,+ owner: `${label}: attach owner`,+ },+ ));+ }++ const mib = 1024 * 1024;+ // Exercise both one large excerpt and a request with smaller excerpts+ // that together exceed the SDK's default 10 MiB stdio buffer.+ for (const [step, sizes] of [+ [9 * mib],+ [11 * mib],+ [6 * mib, 6 * mib],+ [32],+ ].entries()) {+ const findings = sizes.map((size, index) => ({+ ...finding(`checkpoint-${step}-${index}`, "src/fixture.py"),+ evidenceExcerpt: `checkpoint-${step}-${index}:`.padEnd(size, "e"),+ }));+ const result = requireSuccessfulTool(+ await call("record_codex_security_scan_draft", {+ ...workerDraft(findings),+ scanId,+ ...(handoffClaimToken === undefined ? {} : { handoffClaimToken }),+ complete: false,+ }),+ `${label}: save checkpoint ${step}`,+ );+ assert.equal(result.status, "draft_written");+ const saved = await readJson(+ scanDir,+ artifactWriter ? "result.json" : "findings.json",+ );+ assert.equal(result.findingCount, saved.findings.length);+ const head = await readJson(scanDir, "checkpoint-head.json");+ const checkpoint = await readJson(+ scanDir,+ "checkpoints",+ head.checkpoint,+ );+ assert.equal(checkpoint.complete, false);+ for (const document of [saved, checkpoint]) {+ assert.equal(document.scanId, scanId);+ for (const expected of findings) {+ const actual = document.findings.find(+ (entry: { ruleId: string }) => entry.ruleId === expected.ruleId,+ );+ assert.equal(+ actual?.evidenceExcerpt,+ expected.evidenceExcerpt,+ `${label}: checkpoint ${step} must retain every evidence byte`,+ );+ }+ }+ assert.deepEqual(await client.ping(), {});+ }+ } finally {+ await client.close();+ }+}+async function testCompactDiffScanCompletion(bundle: string,runtimeLabel: string,diff --git a/plugins/codex-security/mcp-app/tests/test_deep_scan_executor.ts b/plugins/codex-security/mcp-app/tests/test_deep_scan_executor.tsindex 76c4bcbbf..5c0005a83 100644--- a/plugins/codex-security/mcp-app/tests/test_deep_scan_executor.ts+++ b/plugins/codex-security/mcp-app/tests/test_deep_scan_executor.ts@@ -2252,6 +2252,8 @@ env_key = "SYNTHETIC_GATEWAY_KEY"`,"mcp","server.mjs",),+ "mcp_servers.cs_artifacts.args.1": "--artifact-writer",+ "mcp_servers.cs_artifacts.args.2": "--stdio","mcp_servers.cs_artifacts.env.CODEX_SECURITY_PLUGIN_ROOT":path.join(fixture.root, `plugin-${index}`),"mcp_servers.cs_artifacts.env.CODEX_SECURITY_ARTIFACT_LAYOUT":