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(config): preserve literal TOML override strings (#1792)
Michael D'Angelo798a8a1c93b5
diff --git a/plugins/codex-security/mcp-app/tests/deep_scan_worker_telemetry_fixture.ts b/plugins/codex-security/mcp-app/tests/deep_scan_worker_telemetry_fixture.tsindex be07b5a81..566922db1 100644--- a/plugins/codex-security/mcp-app/tests/deep_scan_worker_telemetry_fixture.ts+++ b/plugins/codex-security/mcp-app/tests/deep_scan_worker_telemetry_fixture.ts@@ -30,6 +30,12 @@ export function workerTelemetryFixture(index % 2 === 0 ? "openai" : "amazon-bedrock",custom_tag: `synthetic-scan-${index}`,"team.tag": `literal-key-${index}`,+ ...(index === 1 || index === 4+ ? {+ "literal.key": `scan-${index}"\\雪\u007f`,+ 'quote"\\雪\u007f': `literal-key-${index}`,+ }+ : {}),...(mergeProfileTelemetry? {root_only: "native-root",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 b35a539d1..ba5a107f9 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@@ -1452,7 +1452,10 @@ env_key = "SYNTHETIC_GATEWAY_KEY"`,{ model: "gpt-6-astra", reasoningEffort: "ultra" },{ model: "gpt-6.1-sol", reasoningEffort: "max" },{ model: "gpt-6-sol", reasoningEffort: "high" },- { model: "fixture-future-model", reasoningEffort: "future-effort" },+ {+ model: 'fixture-"future"\\模型',+ reasoningEffort: 'future-"effort"\\強度\u007f',+ },// Omitted settings preserve the model and effort in the Codex home.{},];@@ -1545,6 +1548,7 @@ env_key = "SYNTHETIC_GATEWAY_KEY"`,nativeProfile === undefined? undefined: path.join(codexHome, `${nativeProfile}.config.toml`);+ const literalDeniedPath = `/repo/literal.key"\\雪\u007f-${index}`;const parentSandbox = {filesystemDenies: [...trustedParentSandboxWithDenials.filesystemDenies,@@ -1553,6 +1557,7 @@ env_key = "SYNTHETIC_GATEWAY_KEY"`,...trustedParentSandboxWithDenials.literalFilesystemDenies,deepPath,codexHome,+ literalDeniedPath,],globScanMaxDepth: trustedParentSandboxWithDenials.globScanMaxDepth,};@@ -1604,6 +1609,7 @@ env_key = "SYNTHETIC_GATEWAY_KEY"`,...deniedWorkerPermissionProfile.filesystem,[deepPath]: { ".": "deny" },[codexHome]: { ".": "deny" },+ [literalDeniedPath]: { ".": "deny" },},},provider,@@ -2086,12 +2092,12 @@ env_key = "SYNTHETIC_GATEWAY_KEY"`,path.join(fixture.root, `cache-${index} `),);assert.deepEqual(- invocation.argv.filter((arg: string) =>- arg.startsWith("model_reasoning_effort="),- ),- reasoningEffort === undefined- ? []- : [`model_reasoning_effort=${JSON.stringify(reasoningEffort)}`],+ nativeConfigOverrides(invocation.argv)+ .filter((override) =>+ override.startsWith("model_reasoning_effort="),+ )+ .map((override) => parseToml(override).model_reasoning_effort),+ reasoningEffort === undefined ? [] : [reasoningEffort],);if (model === undefined) {assert.equal(invocation.argv.includes("--model"), false);diff --git a/sdk/typescript/src/cli.ts b/sdk/typescript/src/cli.tsindex 2f2e19b94..010ba7dd1 100644--- a/sdk/typescript/src/cli.ts+++ b/sdk/typescript/src/cli.ts@@ -146,6 +146,7 @@ import {mergeCodexOverrides,hasCommandAuth,inlineToml,+ quoteTomlString,modelProviderConfigOverride,resolveCommandAuthConfig,resolveCodexProfile,@@ -8001,9 +8002,9 @@ async function runSkill("plugins",...(appServer ? [] : ["--ephemeral", "--color", "never", "--json"]),"--config",- `model=${JSON.stringify(model)}`,+ `model=${quoteTomlString(model)}`,"--config",- `model_reasoning_effort=${JSON.stringify(reasoningEffort)}`,+ `model_reasoning_effort=${quoteTomlString(reasoningEffort)}`,...(options.serviceTier === undefined? []: ["--config", `service_tier=${JSON.stringify(options.serviceTier)}`]),@@ -9504,8 +9505,8 @@ async function executeScan(selected,{codex: [- `model=${JSON.stringify(effectiveModel)}`,- `model_reasoning_effort=${JSON.stringify(effectiveReasoningEffort)}`,+ `model=${quoteTomlString(effectiveModel)}`,+ `model_reasoning_effort=${quoteTomlString(effectiveReasoningEffort)}`,`daybreak=${inlineToml(patchDaybreak)}`,...(patchAnalyticsOverride === undefined? []diff --git a/sdk/typescript/src/config.ts b/sdk/typescript/src/config.tsindex 6fe847f84..167fb54ad 100644--- a/sdk/typescript/src/config.ts+++ b/sdk/typescript/src/config.ts@@ -167,6 +167,11 @@ export function structuredCodexConfig(config: JsonObject = {}): JsonObject {return structured;}+/** @internal Quote a TOML string without changing its contents. */+export function quoteTomlString(value: string): string {+ return JSON.stringify(value).replaceAll("\u007f", "\\u007f");+}+/** @internal Serialize one Codex CLI override value without flattening its keys. */export function inlineToml(value: JsonValue): string {if (value === null)@@ -177,7 +182,7 @@ export function inlineToml(value: JsonValue): string {if (isObject(value)) {return `{${Object.entries(value).filter(([, item]) => item !== null)- .map(([key, item]) => `${JSON.stringify(key)}=${inlineToml(item)}`)+ .map(([key, item]) => `${quoteTomlString(key)}=${inlineToml(item)}`).join(",")}}`;}return stringify({ value }).slice("value = ".length).trim();diff --git a/sdk/typescript/src/deduplication/codex-review.ts b/sdk/typescript/src/deduplication/codex-review.tsindex 5508c842c..44e235b03 100644--- a/sdk/typescript/src/deduplication/codex-review.ts+++ b/sdk/typescript/src/deduplication/codex-review.ts@@ -299,7 +299,7 @@ export class CodexReviewRunner {"--config",'default_permissions="codex_security_review"',"--config",- `permissions.codex_security_review={extends=":read-only",filesystem={${[...privatePaths].map((path) => `${JSON.stringify(path)}="deny"`).join(",")}}}`,+ `permissions.codex_security_review={extends=":read-only",filesystem=${inlineToml(Object.fromEntries([...privatePaths].map((path) => [path, "deny"])))}}`,"--config",`windows=${inlineToml(executionConfig["windows"] ?? DEFAULT_CODEX_CONFIG["windows"]!)}`,);diff --git a/sdk/typescript/tests-ts/cli-patch.test.ts b/sdk/typescript/tests-ts/cli-patch.test.tsindex 9150a58ed..fff504813 100644--- a/sdk/typescript/tests-ts/cli-patch.test.ts+++ b/sdk/typescript/tests-ts/cli-patch.test.ts@@ -1345,9 +1345,9 @@ describe("scan and patch workflow", () => {"--auth","chatgpt","--model",- "gpt-5.6-terra",+ 'synthetic-"model"\\雪\u007f',"--effort",- "high",+ 'future-"effort"\\雪\u007f',"--json",],{@@ -1368,8 +1368,16 @@ describe("scan and patch workflow", () => {},);expect(chatgpt.exitCode).toBe(0);- expect(invocation).toContain('model="gpt-5.6-terra"');- expect(invocation).toContain('model_reasoning_effort="high"');+ expect(+ parseToml(invocation.find((value) => value.startsWith("model="))!),+ ).toEqual({ model: 'synthetic-"model"\\雪\u007f' });+ expect(+ parseToml(+ invocation.find((value) =>+ value.startsWith("model_reasoning_effort="),+ )!,+ ),+ ).toEqual({ model_reasoning_effort: 'future-"effort"\\雪\u007f' });expect(authentication).toBe("chatgpt");const attributed = await runWorkflow(diff --git a/sdk/typescript/tests-ts/cli-skills.test.ts b/sdk/typescript/tests-ts/cli-skills.test.tsindex 974eee741..10ed52aac 100644--- a/sdk/typescript/tests-ts/cli-skills.test.ts+++ b/sdk/typescript/tests-ts/cli-skills.test.ts@@ -1182,6 +1182,7 @@ describe("CLI skill commands", () => {["gpt-6-astra", "max"],["gpt-6.1-sol", "max"],["synthetic-future-model", "synthetic-future-effort"],+ ['synthetic-"model"\\雪\u007f', 'future-"effort"\\雪\u007f'],] as const) {let invocation: readonly string[] = [];const stderr = captureCli(main, "stderr");@@ -1218,8 +1219,16 @@ describe("CLI skill commands", () => {),stderr.text(),).toBe(0);- expect(invocation).toContain(`model="${model}"`);- expect(invocation).toContain(`model_reasoning_effort="${effort}"`);+ expect(+ parseToml(invocation.find((value) => value.startsWith("model="))!),+ ).toEqual({ model });+ expect(+ parseToml(+ invocation.find((value) =>+ value.startsWith("model_reasoning_effort="),+ )!,+ ),+ ).toEqual({ model_reasoning_effort: effort });}for (const [options, message] of [diff --git a/sdk/typescript/tests-ts/codex-review.test.ts b/sdk/typescript/tests-ts/codex-review.test.tsindex 0a4afafb0..eafce17e5 100644--- a/sdk/typescript/tests-ts/codex-review.test.ts+++ b/sdk/typescript/tests-ts/codex-review.test.ts@@ -190,7 +190,13 @@ const transportCases: {windowsConfig?: JsonObject;expectedWindowsSandbox?: string;surface?: CodexSecuritySurface;+ permissionPathSuffix?: string;}[] = [+ {+ scenario: "correction",+ name: "literal permission paths",+ permissionPathSuffix: "literal.path-雪\u007f-",+ },{scenario: "recover-server-error",name: "CLI attribution survives a retried review session",@@ -264,12 +270,15 @@ for (const {windowsConfig,expectedWindowsSandbox,surface,+ permissionPathSuffix = "",} of transportCases) {const runCase = test.skipIf(windowsOnly && process.platform !== "win32");runCase(`Codex review transport: ${name}`, async () => {const modelHome = await mkdtemp(join(tmpdir(), "codex-review-test-"));const checkout = await temporaryDirectory("codex-review-source-", true);- const ghConfig = await mkdtemp(join(tmpdir(), "codex-review-gh-"));+ const ghConfig = await mkdtemp(+ join(tmpdir(), `codex-review-gh-${permissionPathSuffix}`),+ );const transcript = join(modelHome, "messages.jsonl");let child: ChildProcessWithoutNullStreams | undefined;let starts = 0;@@ -562,12 +571,17 @@ for (const {const permissions = args.find((argument) =>argument.startsWith("permissions.codex_security_review="),);- expect(permissions).toContain(- `${JSON.stringify(resolve(modelHome))}="deny"`,- );- expect(permissions).toContain(- `${JSON.stringify(resolve(ghConfig))}="deny"`,- );+ expect(parse(permissions!)).toMatchObject({+ permissions: {+ codex_security_review: {+ extends: ":read-only",+ filesystem: {+ [resolve(modelHome)]: "deny",+ [resolve(ghConfig)]: "deny",+ },+ },+ },+ });if (scenario !== "cancel") {const messages = parseJsonLines<{method?: string;diff --git a/sdk/typescript/tests-ts/config.test.ts b/sdk/typescript/tests-ts/config.test.tsindex c34a72293..63611c437 100644--- a/sdk/typescript/tests-ts/config.test.ts+++ b/sdk/typescript/tests-ts/config.test.ts@@ -6,6 +6,7 @@ import { scanRuntimeCodexConfig } from "../src/api.js";import {type JsonObject,inlineToml,+ quoteTomlString,modelProviderConfigOverride,resolveCodexProfile,scanModelConfiguration,@@ -33,6 +34,34 @@ const { temporaryDirectory, cleanup } = createApiTestFixtures(afterEach(cleanup);+test("inline Codex overrides preserve literal keys and string values", () => {+ const metadata = {+ "literal.key": "value.with.dots",+ 'quote"slash\\雪': 'quote"slash\\雪',+ "control\u007fkey": "control\u0000\b\t\n\f\r\u007fvalue",+ };+ expect(parse(`responses_api_metadata=${inlineToml(metadata)}`)).toEqual({+ responses_api_metadata: metadata,+ });+ expect(+ parse(+ `permissions=${inlineToml({+ review: { filesystem: { "path.with.dots/雪\u007f": "deny" } },+ })}`,+ ),+ ).toEqual({+ permissions: {+ review: { filesystem: { "path.with.dots/雪\u007f": "deny" } },+ },+ });+ for (const value of ["\ud800", "\udc00"]) {+ expect(() => parse(`model=${quoteTomlString(value)}`)).toThrow();+ expect(() =>+ parse(`metadata=${inlineToml({ [value]: "literal" })}`),+ ).toThrow();+ }+});+test("inline Codex overrides omit optional null fields like the file writer", async () => {for (const value of [null, { args: ["fixture", null] }]) {expect(() => inlineToml(value)).toThrow(ConfigurationError);