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(reports): preserve saved diff snapshot provenance (#1286)
mldangelo-oai7e396e79b300
diff --git a/plugins/codex-security/mcp-app/src/threat-model-document.ts b/plugins/codex-security/mcp-app/src/threat-model-document.tsindex be4df8fef..3ded2045d 100644--- a/plugins/codex-security/mcp-app/src/threat-model-document.ts+++ b/plugins/codex-security/mcp-app/src/threat-model-document.ts@@ -7,6 +7,7 @@ import {replaceArtifactText,} from "./artifact-io.js";import { resolvePythonCommand } from "./python_command.js";+import { asRecord } from "./record.js";const pendingDocuments = new Map<string, Promise<void>>();@@ -40,11 +41,8 @@ async function writeCurrentThreatModelDocument([context.layout === "scan" ? "scan-manifest.json" : "result.json"],"saved threat model",);- const document = context.layout === "scan" ? source.scan : source;- const threatModel =- document && typeof document === "object" && !Array.isArray(document)- ? (document as Record<string, unknown>).threatModel- : undefined;+ const document = asRecord(context.layout === "scan" ? source.scan : source);+ const threatModel = document?.threatModel;if (threatModel === undefined) return;const destination = await artifactDestination(context,@@ -52,8 +50,7 @@ async function writeCurrentThreatModelDocument("threat model document",);const python = context.pythonCommand ?? (await resolvePythonCommand());- const target = context.targetContract?.target as- Record<string, unknown> | undefined;+ const target = asRecord(document?.target);const markdown = await renderThreatModel(python, context.pluginRoot!, {threatModel,provenance: {@@ -61,7 +58,9 @@ async function writeCurrentThreatModelDocument(scanId: context.scanId,target: context.repoRoot,revision: context.targetRevision,- snapshotDigest: target?.requiredSnapshotDigest,+ snapshotDigest:+ target?.snapshotDigest ??+ asRecord(context.targetContract?.target)?.requiredSnapshotDigest,status: context.status ?? "running",provisional: context.status !== "complete",...(context.scope === undefineddiff --git a/plugins/codex-security/mcp-app/tests/test_threat_model_document.ts b/plugins/codex-security/mcp-app/tests/test_threat_model_document.tsindex 0875a5d7e..9de025692 100644--- a/plugins/codex-security/mcp-app/tests/test_threat_model_document.ts+++ b/plugins/codex-security/mcp-app/tests/test_threat_model_document.ts@@ -135,6 +135,37 @@ for (const complete of [true, undefined]) {}}+for (const kind of ["working_tree", "commit", "range"]) {+ test(`diff threat model includes its saved ${kind} snapshot`, async () => {+ const root = await temporaryDirectory("threatmodel-diff-");+ try {+ const { context, draft } = draftFixture(root, "diff");+ context.pluginRoot = pluginRoot;+ const target = context.targetContract!.target as Record<string, unknown>;+ const diffTarget = context.targetContract!.diffTarget as Record<+ string,+ unknown+ >;+ delete target.requiredSnapshotDigest;+ diffTarget.kind = kind;+ if (kind === "working_tree")+ diffTarget.contentDigest =+ "codex-security-snapshot/v1:sha256:" + "c".repeat(64);+ await recordCodexSecurityScanDraft(context, { ...draft(), threatModel });+ const manifest = await readJson(root, "scan-manifest.json");+ const digest = manifest.scan.target.snapshotDigest;+ assert.match(+ digest,+ /^codex-security-snapshot\/v1:sha256:[a-f0-9]{64}$/u,+ );+ const document = await readFile(join(root, "threatmodel.md"), "utf8");+ assert.ok(document.includes(`Snapshot: ${digest}`), document);+ } finally {+ await rm(root, { recursive: true, force: true });+ }+ });+}+test("terminal Deep model inheritance retries a changed canonical draft", async () => {const root = await temporaryDirectory("threatmodel-deep-retry-");try {diff --git a/plugins/codex-security/references/final-report.md b/plugins/codex-security/references/final-report.mdindex c187d6593..892cfb7bf 100644--- a/plugins/codex-security/references/final-report.md+++ b/plugins/codex-security/references/final-report.md@@ -160,8 +160,6 @@ Recommended outcomes:- `Not applicable`: the risk class does not apply to that surface.- `Needs follow-up`: plausible but not fully closed because of a concrete blocker or proof gap.-Write the same content, or a slightly more detailed version, to `<coverage_dir>/reviewed_surfaces.md`.-For broad scans where the completed coverage is useful for triage but too large for high-precision review, include a concise `## Open Questions And Follow Up` section near the end of the report. Use concrete, copyable prompt ideas that narrow the next review to individual commits from the current scan. Do not include this section for precise scans where the requested scope was already sufficient.Follow-up prompts should be tailored to the actual scan results:diff --git a/plugins/codex-security/references/scan-artifacts.md b/plugins/codex-security/references/scan-artifacts.mdindex d75f57533..44291d04e 100644--- a/plugins/codex-security/references/scan-artifacts.md+++ b/plugins/codex-security/references/scan-artifacts.md@@ -73,7 +73,6 @@ The worklist, per-finding receipt, and phase-report paths below apply only to st- Repository-wide coverage ledger: `<coverage_dir>/repository_coverage_ledger.md`- This is a coverage artifact, not a findings list: it should include checked surfaces with not_applicable, suppressed, deferred, or reportable dispositions.-- Reviewed surfaces summary: `<coverage_dir>/reviewed_surfaces.md` if applicable## Validation (Phase 3) Paths