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(cli): preserve canonical parent IDs for scan reruns (#1244)
mldangelo-oaif7256641c01a
diff --git a/sdk/typescript/src/cli.ts b/sdk/typescript/src/cli.tsindex 011faaa6c..70f4d749c 100644--- a/sdk/typescript/src/cli.ts+++ b/sdk/typescript/src/cli.ts@@ -2334,11 +2334,13 @@ export async function main(if (scanId === undefined) return;let scanArguments: ScanArguments;try {- const { recipe } = await dependencies.runWorkbench([- "get-scan-recipe",- "--scan-id",- scanId,- ]);+ const { recipe, scanId: resolvedScanId } =+ await dependencies.runWorkbench([+ "get-scan-recipe",+ "--scan-id",+ scanId,+ ]);+ const parentScanId = resolvedScanId as string;if (isJsonObject(recipe) &&recipe["import"] !== undefined &&@@ -2370,7 +2372,7 @@ export async function main(const outcome = await runImport({sourcePath,format,- parentScanId: scanId,+ parentScanId,});exitCode = outcome.exitCode;if (outcome.error !== undefined) {@@ -2384,7 +2386,7 @@ export async function main(}scanArguments = await prepareScanArgumentsFromRecipe(recipe,- scanId,+ parentScanId,{scanPromptFile:options.scanPromptFile === undefineddiff --git a/sdk/typescript/tests-ts/cli-fixtures.ts b/sdk/typescript/tests-ts/cli-fixtures.tsindex 367a0bc40..db38dcdb5 100644--- a/sdk/typescript/tests-ts/cli-fixtures.ts+++ b/sdk/typescript/tests-ts/cli-fixtures.ts@@ -112,6 +112,7 @@ export const savedRecipe = (config: JsonObject = {},target: JsonObject = { kind: "repository", paths: [] },) => ({+ scanId: "scan-original",recipe: {repository: "/original/repository",target,diff --git a/sdk/typescript/tests-ts/cli-project-config.test.ts b/sdk/typescript/tests-ts/cli-project-config.test.tsindex d74403838..727769e35 100644--- a/sdk/typescript/tests-ts/cli-project-config.test.ts+++ b/sdk/typescript/tests-ts/cli-project-config.test.ts@@ -689,7 +689,7 @@ test("rerun accepts replacement scan and validation files relative to the invoca],dependencies({currentDirectory: input.configDirectory,- onWorkbench: async () => ({ recipe }),+ onWorkbench: async () => ({ scanId: "saved", recipe }),onTurn,}),),@@ -1142,7 +1142,7 @@ test("rerun restores all saved deep settings and authentication without loadingOPENAI_API_KEY: "synthetic-test-key",CODEX_SECURITY_PROJECT_CONFIG: input.config,},- onWorkbench: async () => ({ recipe }),+ onWorkbench: async () => ({ scanId: "saved", recipe }),onTurn,}),),diff --git a/sdk/typescript/tests-ts/cli-scan-import.test.ts b/sdk/typescript/tests-ts/cli-scan-import.test.tsindex 6fcefd86d..1e3896f30 100644--- a/sdk/typescript/tests-ts/cli-scan-import.test.ts+++ b/sdk/typescript/tests-ts/cli-scan-import.test.ts@@ -206,32 +206,37 @@ describe("scan import", () => {});});- test("reruns an imported scan from its retained source", async () => {- const { deps, calls } = importDependencies();- deps.runWorkbench = async (args) => {- expect(args).toEqual(["get-scan-recipe", "--scan-id", "previous-scan"]);- return {- recipe: {- import: {- format: "csv",- sourcePath: resolve("retained", "source.csv"),+ test.each(["12345678-1234-4234-8234-123456789abc", "12345678"])(+ "reruns imported scan %s from its retained source with the resolved parent UUID",+ async (selector) => {+ const scanId = "12345678-1234-4234-8234-123456789abc";+ const { deps, calls } = importDependencies();+ deps.runWorkbench = async (args) => {+ expect(args).toEqual(["get-scan-recipe", "--scan-id", selector]);+ return {+ scanId,+ recipe: {+ import: {+ format: "csv",+ sourcePath: resolve("retained", "source.csv"),+ },},- },+ };};- };- const stdout = captureCli(main, "stdout");- expect(- await stdout.run(["scans", "rerun", "previous-scan", "--json"], deps),- ).toBe(0);- expect(calls[0]).toMatchObject({- sourcePath: resolve("retained", "source.csv"),- format: "csv",- parentScanId: "previous-scan",- });- expect(JSON.parse(stdout.text())).toMatchObject({- manifest: { scan: { id: "scan" } },- });- });+ const stdout = captureCli(main, "stdout");+ expect(+ await stdout.run(["scans", "rerun", selector, "--json"], deps),+ ).toBe(0);+ expect(calls[0]).toMatchObject({+ sourcePath: resolve("retained", "source.csv"),+ format: "csv",+ parentScanId: scanId,+ });+ expect(JSON.parse(stdout.text())).toMatchObject({+ manifest: { scan: { id: "scan" } },+ });+ },+ );test.each(["--validation-prompt-file", "--scan-prompt-file"])("rejects %s when rerunning an imported scan",diff --git a/sdk/typescript/tests-ts/cli-scan-prompts.test.ts b/sdk/typescript/tests-ts/cli-scan-prompts.test.tsindex 61beb481d..9db116952 100644--- a/sdk/typescript/tests-ts/cli-scan-prompts.test.ts+++ b/sdk/typescript/tests-ts/cli-scan-prompts.test.ts@@ -226,6 +226,7 @@ describe("CLI scan prompts", () => {currentDirectory: root,onTurn,onWorkbench: () => ({+ scanId: "saved",recipe: {repository: root,target: { kind: "repository", paths: [] },diff --git a/sdk/typescript/tests-ts/cli-workbench.test.ts b/sdk/typescript/tests-ts/cli-workbench.test.tsindex 63a183ac8..9d0f8123c 100644--- a/sdk/typescript/tests-ts/cli-workbench.test.ts+++ b/sdk/typescript/tests-ts/cli-workbench.test.ts@@ -1277,6 +1277,7 @@ describe("CLI workbench", () => {args[0] === "list-scans"? { scans: [{ scanId: "latest-scan" }] }: {+ scanId: "latest-scan",recipe: {repository: "/current/repository",target: { kind: "repository", paths: [] },@@ -1290,6 +1291,25 @@ describe("CLI workbench", () => {expect(parentScanId).toBe("latest-scan");});+ test("reruns a scan prefix with its resolved parent UUID", async () => {+ const scanId = "12345678-1234-4234-8234-123456789abc";+ const prefix = scanId.slice(0, 8);+ const onTurn = mock<(repository: string, options: ScanOptions) => void>();+ const onWorkbench = mock((args: readonly string[]): JsonObject => {+ expect(args).toEqual(["get-scan-recipe", "--scan-id", prefix]);+ return { ...savedRecipe(), scanId };+ });++ expect(+ await runCapturedCli(+ main,+ ["scans", "rerun", prefix],+ dependencies({ onWorkbench, onTurn }),+ ),+ ).toBe(0);+ expect(onTurn.mock.lastCall?.[1]?.parentScanId).toBe(scanId);+ });+test("reruns canonical recipes with exact config, policy, plugin, and lineage", async () => {const onConfig = mock<(config: CodexSecurityConfig) => void>();const onTurn = mock<(repository: string, options: ScanOptions) => void>();@@ -1309,6 +1329,7 @@ describe("CLI workbench", () => {onConfig,onTurn,onWorkbench: () => ({+ scanId: "scan-original",recipe: {repository: "/original/repository",target: { kind: "paths", paths: ["src", "packages/core"] },