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): parse existing option values consistently (#1248)
mldangelo-oai0b59e9689fbb
diff --git a/sdk/typescript/src/cli.ts b/sdk/typescript/src/cli.tsindex fb0ef3c7d..99225d46d 100644--- a/sdk/typescript/src/cli.ts+++ b/sdk/typescript/src/cli.ts@@ -5805,11 +5805,16 @@ export async function main(let notice: UpdateNotice | undefined;try {await cli.serve(- argv.flatMap((argument) =>- argument.startsWith("--format=")- ? ["--format", argument.slice("--format=".length)]- : [argument],- ),+ argv.flatMap((argument) => {+ if (+ !/^--(?:format|filter-output|token-limit|token-offset)=/u.test(+ argument,+ )+ )+ return [argument];+ const separator = argument.indexOf("=");+ return [argument.slice(0, separator), argument.slice(separator + 1)];+ }),{stdout: frameworkCapture.stream.write,exit: (code) => {@@ -6193,6 +6198,8 @@ function validateCliArguments("validate","verify-fix","suggest-owners",+ "classify-severity",+ "dedupe","patch","login","logout",@@ -6328,9 +6335,14 @@ function validateCliArguments(}const equals = value.indexOf("=");const option = equals < 0 ? value : value.slice(0, equals);+ const canonicalOption = option.replace(+ /[A-Z]/g,+ (letter) => `-${letter.toLowerCase()}`,+ );if (equals >= 0 ||- (!VALUE_OPTIONS.has(option) && !(scanImport && option === "--json"))+ (!VALUE_OPTIONS.has(canonicalOption) &&+ !(scanImport && option === "--json")))continue;const next = argv[index + 1];@@ -9399,12 +9411,12 @@ export function parseCodexOverrides(}for (const value of values) {const separator = value.indexOf("=");- const key = separator < 0 ? "" : value.slice(0, separator);+ const key = separator < 0 ? "" : value.slice(0, separator).trim();const literal = separator < 0 ? "" : value.slice(separator + 1);if (key.length === 0 || literal.length === 0) {throw new CodexSecurityError("--codex expects KEY=VALUE");}- const parts = key.split(".");+ const parts = key.split(".").map((part) => part.trim());if (parts.some((part) =>diff --git a/sdk/typescript/tests-ts/cli-classify-severity.test.ts b/sdk/typescript/tests-ts/cli-classify-severity.test.tsindex ea2a6f070..a0763fa57 100644--- a/sdk/typescript/tests-ts/cli-classify-severity.test.ts+++ b/sdk/typescript/tests-ts/cli-classify-severity.test.ts@@ -15,9 +15,12 @@ const result = {assessments: [],};-test.each(["latest", "scan_prefix"])(- "classify-severity accepts saved scan selector %s",- async (selector) => {+test.each([+ ["latest", "--finding-id"],+ ["scan_prefix", "--findingId"],+])(+ "classify-severity accepts saved scan selector %s with %s",+ async (selector, findingFlag) => {const deps = dependencies();const stdout = captureCli(main, "stdout");deps.classifyScanSeverity = async (scanId, options, history, surface) => {@@ -46,9 +49,9 @@ test.each(["latest", "scan_prefix"])("policy.md","--knowledge-base","context.md",- "--finding-id",+ findingFlag,"finding-one",- "--finding-id",+ findingFlag,"finding-two","--model","synthetic-model",diff --git a/sdk/typescript/tests-ts/cli-dedupe.test.ts b/sdk/typescript/tests-ts/cli-dedupe.test.tsindex 69d01f2ae..bed7bcbb7 100644--- a/sdk/typescript/tests-ts/cli-dedupe.test.ts+++ b/sdk/typescript/tests-ts/cli-dedupe.test.ts@@ -52,7 +52,10 @@ test.each([false, true])(},);-test("dedupe resolves a workflow's pinned scan and passes the workflow ID to the SDK", async () => {+test.each([+ ["--workflow-id", "--findings-url"],+ ["--workflowId", "--findingsUrl"],+])("dedupe accepts %s and %s", async (workflowFlag, findingsFlag) => {const deps = dependencies();deps.runWorkbench = async (args, input) => {expect(args).toEqual(["finding-workflow"]);@@ -83,9 +86,9 @@ test("dedupe resolves a workflow's pinned scan and passes the workflow ID to theawait stdout.run(["dedupe",- "--workflow-id",+ workflowFlag,"workflow-example",- "--findings-url",+ findingsFlag,"http://localhost:3000","--json",],diff --git a/sdk/typescript/tests-ts/cli.test.ts b/sdk/typescript/tests-ts/cli.test.tsindex e14079936..bedd10381 100644--- a/sdk/typescript/tests-ts/cli.test.ts+++ b/sdk/typescript/tests-ts/cli.test.ts@@ -1478,6 +1478,44 @@ describe("CLI", () => {expect(stderr.text()).toContain("info metadata field");});+ test.each([+ { options: [["--format", "json"]] },+ { options: [["--filter-output", "model,reasoningEffort"]] },+ { options: [["--token-limit", "4"]] },+ {+ options: [+ ["--token-offset", "1"],+ ["--token-limit", "4"],+ ],+ },+ ])("accepts equivalent output option forms %j", async ({ options }) => {+ const separated = captureCli(main, "stdout");+ const equals = captureCli(main, "stdout");+ expect(+ await separated.run(["info", ...options.flat()], dependencies()),+ ).toBe(0);+ expect(+ await equals.run(+ ["info", ...options.map(([flag, value]) => `${flag}=${value}`)],+ dependencies(),+ ),+ ).toBe(0);+ expect(equals.text()).toBe(separated.text());+ expect(equals.text()).not.toBe("");+ });++ test.each(["--format", "--filter-output", "--token-limit", "--token-offset"])(+ "rejects missing values for output option %s",+ async (flag) => {+ for (const args of [[flag], [flag, "--json"], [`${flag}=`]]) {+ const { stdout, stderr, runCli } = createCliTest(main);+ expect(await runCli(["info", ...args], dependencies())).toBe(2);+ expect(stdout.text()).toBe("");+ expect(stderr.text()).toContain(flag);+ }+ },+ );+test("registers the scoped package as the MCP command", async () => {const home = await temporaryDirectory("codex-security-mcp-home-");try {@@ -2517,6 +2555,65 @@ describe("CLI", () => {}});+ test("ignores override key whitespace and preserves literal string contents", () => {+ expect(+ parseCodexOverrides([+ ' model = " example " ',+ " agents . max_threads = 4",+ ]),+ ).toEqual({ model: " example ", agents: { max_threads: 4 } });+ expect(() =>+ parseCodexOverrides([+ "agents.max_threads=4",+ " agents . max_threads = 8",+ ]),+ ).toThrow("Duplicate --codex key");+ expect(() =>+ parseCodexOverrides(["agents=4", " agents . max_threads = 8"]),+ ).toThrow("Conflicting --codex key");+ expect(() => parseCodexOverrides([' model = "example"'], "other")).toThrow(+ "--model conflicts with --codex model",+ );+ for (const key of ["agents. .limit", "agents. __proto__ .limit"]) {+ expect(() => parseCodexOverrides([`${key}=1`])).toThrow(+ "Invalid --codex key",+ );+ }+ });++ test.each(+ [+ ["classify-severity", "--scan", "--rubric", "policy.md"],+ ["classify-severity", "--scan-dir", "--rubric", "policy.md"],+ ["classify-severity", "--scan", "latest", "--rubric", "--reprocess"],+ [+ "dedupe",+ "--scan",+ "--all-repositories",+ "--findings-url",+ "http://localhost:3000",+ ],+ [+ "dedupe",+ "--workflow-id",+ "--all-repositories",+ "--findings-url",+ "http://localhost:3000",+ ],+ ].map((args) => ({ args })),+ )("rejects missing option values before running %j", async ({ args }) => {+ const deps = dependencies();+ const unexpected = mock(throwing("Unexpected SDK or workbench call"));+ deps.classifyScanSeverity = unexpected;+ deps.classifyScanDirectorySeverity = unexpected;+ deps.deduplicateScan = unexpected;+ deps.runWorkbench = unexpected;+ const stderr = captureCli(main, "stderr");+ expect(await stderr.run(args, deps)).toBe(2);+ expect(stderr.text()).toContain("Missing value for flag:");+ expect(unexpected).not.toHaveBeenCalled();+ });+test("does not echo malformed --codex overrides and accepts large values", () => {const secret = "SYNTHETIC_TOML_SECRET_MUST_NOT_ECHO";let malformed: unknown;