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(scan): accept large saved post-scan prompts (#876)
mldangelo-oai22dd89bf37e0
diff --git a/plugins/codex-security/scripts/workbench_db.py b/plugins/codex-security/scripts/workbench_db.pyindex 7decf27c7..cc482f3f1 100644--- a/plugins/codex-security/scripts/workbench_db.py+++ b/plugins/codex-security/scripts/workbench_db.py@@ -149,7 +149,6 @@ from workbench_validation import (FINDING_ARTIFACT_DIRECTORIES_LIMIT = 80FINDING_ARTIFACTS_LIMIT = 40FINDING_WRITEUP_REPORT_PATH = re.compile(r"^findings/([a-z0-9][a-z0-9._-]*)/\1\.md$")-SCAN_RECIPE_MAX_BYTES = 256 * 1024def now() -> str:@@ -1820,8 +1819,6 @@ def set_scan_cost_limit(connection: sqlite3.Connection, args: argparse.Namespacedef parse_scan_recipe(value: str, repository: Path) -> dict[str, Any]:- if len(value.encode("utf-8")) > SCAN_RECIPE_MAX_BYTES:- raise SystemExit("Scan launch recipe must be no larger than 256 KiB.")try:recipe = json.loads(value, parse_constant=reject_non_finite_json)except (TypeError, UnicodeError, ValueError) as exc:diff --git a/sdk/typescript/tests-ts/scan-recipe.test.ts b/sdk/typescript/tests-ts/scan-recipe.test.tsnew file mode 100644index 000000000..50020aaa6--- /dev/null+++ b/sdk/typescript/tests-ts/scan-recipe.test.ts@@ -0,0 +1,95 @@+import { mkdir, rm, writeFile } from "node:fs/promises";+import { join } from "node:path";+import { afterEach, expect, test } from "bun:test";+import { main } from "../src/cli.js";+import { runWorkbench } from "../src/runtime.js";+import { capture, dependencies } from "./cli-fixtures.js";+import { PLUGIN_ROOT } from "./plugin-root.js";+import { TestClient } from "./support/api-client.js";+import {+ createApiTestFixtures,+ preparedRuntime,+} from "./support/api-events.js";++const { temporaryDirectory, cleanup } = createApiTestFixtures();+afterEach(cleanup);++test.each(["standard", "deep"])(+ "%s scans save large post-scan prompts before starting Codex",+ async (mode) => {+ const root = await temporaryDirectory();+ const repository = join(root, "repository");+ const codexHome = join(root, "state", "codex-home");+ await mkdir(repository);+ await mkdir(codexHome, { recursive: true });+ await writeFile(join(repository, "source.py"), "# synthetic source\n");+ const promptFile = join(root, "post-scan.md");+ const postScanPrompt =+ "Review the completed scan and its evidence.\n".repeat(10_000);+ expect(Buffer.byteLength(postScanPrompt)).toBeGreaterThan(256 * 1024);+ await writeFile(promptFile, postScanPrompt);+ const python = Bun.which("python3") ?? Bun.which("python");+ if (python === null) throw new Error("Python is required for this test.");+ const environment = {+ PATH: process.env["PATH"],+ SystemRoot: process.env["SystemRoot"],+ TEMP: process.env["TEMP"],+ TMP: process.env["TMP"],+ CODEX_HOME: codexHome,+ CODEX_SECURITY_STATE_DIR: join(root, "state"),+ OPENAI_API_KEY: "synthetic-launch-key",+ };+ const command = (args: readonly string[], input?: string) =>+ runWorkbench(+ { python, pluginRoot: PLUGIN_ROOT, environment },+ args,+ input,+ );+ const stdout = capture();+ const stderr = capture();+ const code = await main(+ [+ "scan",+ repository,+ "--mode",+ mode,+ "--output-dir",+ join(root, "scan"),+ "--post-scan-prompt-file",+ promptFile,+ "--json",+ ],+ stdout.stream,+ stderr.stream,+ {+ ...dependencies({ environment, currentDirectory: root }),+ runWorkbench: command,+ createSecurity: (config) =>+ new TestClient(config, {+ environment,+ prepareRuntime: async () => preparedRuntime(codexHome),+ resolvePluginPython: async () => python,+ runWorkbench,+ createCodex: () => {+ throw new Error("Synthetic stop after registration");+ },+ }),+ },+ );+ expect(code).toBe(2);+ expect(stderr.text()).toContain("Synthetic stop after registration");+ await rm(promptFile);+ const scans = (await command(["list-scans", "--repository", repository]))[+ "scans"+ ] as Array<{ scanId: string }>;+ expect(scans).toHaveLength(1);+ const saved = await command([+ "get-scan-recipe",+ "--scan-id",+ scans[0]!.scanId,+ ]);+ expect(saved["recipe"]).toMatchObject({ mode, postScanPrompt });+ expect(JSON.stringify(saved)).not.toContain(promptFile);+ expect(JSON.stringify(saved)).not.toContain("synthetic-launch-key");+ },+);