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): support custom inference providers in patch commands (#1131)
ianw-oai62e86432bc88
diff --git a/sdk/typescript/README.md b/sdk/typescript/README.mdindex 084f0c5b1..bcd2d33e7 100644--- a/sdk/typescript/README.md+++ b/sdk/typescript/README.md@@ -880,8 +880,24 @@ stay enabled: `agents.max_threads` and`features.multi_agent_v2.enabled=false` are rejected.`validate`, `patch`, and `verify-fix` accept `--auth`, `--effort`, and the `model`,-`model_reasoning_effort`, and `analytics.enabled` keys in `--codex`, but no-other runtime overrides.+`model_reasoning_effort`, `model_provider`, `model_providers`, and+`analytics.enabled` keys in `--codex`, but no other runtime overrides.+Use the same provider settings as `scan` when routing a standalone patch+through a custom inference gateway:++```bash+npx @openai/codex-security patch "Security issue" \+ --codex 'model="gateway-model"' \+ --codex 'model_provider="gateway"' \+ --codex 'model_providers.gateway.name="Gateway"' \+ --codex 'model_providers.gateway.base_url="https://gateway.example.test/v1"' \+ --codex 'model_providers.gateway.wire_api="responses"' \+ --codex 'model_providers.gateway.env_key="GATEWAY_API_KEY"'+```++Set the selected provider's API-key environment variable before running the+command. Provider settings also apply to `patch --assess-patch-risk`.+Sandbox, approval, and plugin settings remain controlled by the command.Use `--codex 'analytics.enabled=false'` to disable Codex usage analytics andbuilt-in metrics for a command:diff --git a/sdk/typescript/src/cli.ts b/sdk/typescript/src/cli.tsindex 05537c3ee..e8fa98ff5 100644--- a/sdk/typescript/src/cli.ts+++ b/sdk/typescript/src/cli.ts@@ -309,6 +309,8 @@ const DEFAULT_SCAN_MODEL_CONFIGURATION =scanModelConfiguration(DEFAULT_CODEX_CONFIG);const CODEX_OVERRIDE_DESCRIPTION ='Repeat TOML KEY=VALUE; e.g. model_reasoning_effort="high" or features.multi_agent_v2.max_concurrent_threads_per_session=4.';+const SKILL_CODEX_OVERRIDE_DESCRIPTION =+ 'Repeat TOML model="gpt-5.6-terra", model_reasoning_effort="high", model_provider="gateway", model_providers.<name>.<key>=VALUE, or analytics.enabled=false.';const PLUGIN_PATH_DESCRIPTION ="Codex Security plugin directory or ZIP (default: bundled plugin).";const PYTHON_PATH_DESCRIPTION =@@ -4848,9 +4850,7 @@ export async function main(codex: z.array(optionValue("--codex")).default([])- .describe(- 'Repeat TOML model="gpt-5.6-terra", model_reasoning_effort="high", or analytics.enabled=false.',- ),+ .describe(SKILL_CODEX_OVERRIDE_DESCRIPTION),}),async run({ options }) {try {@@ -4909,9 +4909,7 @@ export async function main(codex: z.array(optionValue("--codex")).default([])- .describe(- 'Repeat TOML model="gpt-5.6-terra", model_reasoning_effort="high", or analytics.enabled=false.',- ),+ .describe(SKILL_CODEX_OVERRIDE_DESCRIPTION),}),output: z.record(z.string(), z.unknown()).optional(),async run({ format, options }) {@@ -5148,9 +5146,7 @@ export async function main(codex: z.array(optionValue("--codex")).default([])- .describe(- 'Repeat TOML model="gpt-5.6-terra", model_reasoning_effort="high", or analytics.enabled=false.',- ),+ .describe(SKILL_CODEX_OVERRIDE_DESCRIPTION),}),output: z.record(z.string(), z.unknown()).optional(),async run({ format, options, error: commandError }) {@@ -7389,6 +7385,8 @@ async function runSkill(([key, value]) =>key !== "model" &&key !== "model_reasoning_effort" &&+ key !== "model_provider" &&+ key !== "model_providers" &&!(key === "analytics" &&isJsonObject(value) &&@@ -7397,12 +7395,24 @@ async function runSkill()) {throw new CodexSecurityError(- "Skill commands only support model, model_reasoning_effort, and analytics.enabled overrides.",+ "Skill commands only support model, model_reasoning_effort, model_provider, model_providers, and analytics.enabled overrides.",);}const { model, reasoningEffort } = scanModelConfiguration(await mergedCodexConfig({ codexOverrides: overrides }),);+ const provider =+ options.provider ?? (overrides["model_provider"] as string | undefined);+ const providerConfiguration =+ options.providerConfiguration ??+ (provider === undefined+ ? undefined+ : ((+ overrides["model_providers"] as Record<string, JsonObject> | undefined+ )?.[provider] ??+ (isExternalModelProvider(provider)+ ? EXTERNAL_CODEX_PROVIDERS[provider]+ : undefined)));const directory = options.directory ?? dependencies.currentDirectory();const contents: Array<string | Finding> = [...(options.findings ?? [])];for (const input of inputs) {@@ -7565,24 +7575,24 @@ async function runSkill(value.startsWith("analytics.") || value.startsWith("analytics="),).flatMap((value) => ["--config", value]),- ...(options.provider === undefined- ? []- : ["--config", `model_provider=${JSON.stringify(options.provider)}`]),- ...(options.provider === undefined ||- options.providerConfiguration === undefined+ ...(provider === undefined? []- : modelProviderConfigOverride(- resolveCommandAuthConfig(- {- model_providers: {- [options.provider]: options.providerConfiguration,+ : ["--config", `model_provider=${JSON.stringify(provider)}`]),+ ...modelProviderConfigOverride(+ resolveCommandAuthConfig(+ mergeCodexOverrides(+ overrides,+ provider === undefined || providerConfiguration === undefined+ ? {}+ : {+ model_providers: {+ [provider]: providerConfiguration,+ },},- },- configuredCodexHome(- options.environment ?? dependencies.environment,- ),- ),- ).flatMap((value) => ["--config", value])),+ ),+ configuredCodexHome(options.environment ?? dependencies.environment),+ ),+ ).flatMap((value) => ["--config", value]),"--config",verify || assess? 'approval_policy="on-request"'@@ -7613,8 +7623,8 @@ async function runSkill(command: verify ? "verify-fix" : patch || assess ? "patch" : "validate",auth: options.auth ?? "auto",directory,- modelProvider: options.provider,- providerConfiguration: options.providerConfiguration,+ modelProvider: provider,+ providerConfiguration,stdout,stderr,...(appServerdiff --git a/sdk/typescript/tests-ts/cli-authentication.test.ts b/sdk/typescript/tests-ts/cli-authentication.test.tsindex dc74503c5..9a51eaea1 100644--- a/sdk/typescript/tests-ts/cli-authentication.test.ts+++ b/sdk/typescript/tests-ts/cli-authentication.test.ts@@ -1315,17 +1315,19 @@ describe("skill authentication", () => {},);test.each([- ["auto", false, undefined],- ["chatgpt", false, undefined],- ["chatgpt", true, undefined],- ["chatgpt", false, "synthetic"],- ["api-key", false, undefined],- ["api-key", true, undefined],- ["auto", false, "synthetic"],- ["api-key", false, "synthetic"],+ ["auto", false, undefined, false],+ ["chatgpt", false, undefined, false],+ ["chatgpt", true, undefined, false],+ ["chatgpt", false, "synthetic", false],+ ["api-key", false, undefined, false],+ ["api-key", true, undefined, false],+ ["auto", false, "synthetic", false],+ ["api-key", false, "synthetic", false],+ ["api-key", false, "synthetic", true],+ ["chatgpt", false, "synthetic", true],] as const)(- "patch uses %s auth without replacing a saved login (failure: %p, provider: %s)",- async (auth, loginFailure, provider) => {+ "patch uses %s auth without replacing a saved login (failure: %p, provider: %s, explicit: %p)",+ async (auth, loginFailure, provider, explicitProvider) => {const repository = join(stateDirectory, "repository");await mkdir(repository);const ambientHome = join(stateDirectory, "ambient");@@ -1360,7 +1362,14 @@ describe("skill authentication", () => {'forced_login_method = "api"',);}- if (provider !== undefined) {+ const providerConfiguration = {+ name: "Synthetic provider",+ base_url: "https://example.test/v1",+ wire_api: "responses",+ env_key: "OPENAI_API_KEY",+ requires_openai_auth: auth === "chatgpt",+ };+ if (provider !== undefined && !explicitProvider) {await writeFile(join(ambientHome, "config.toml"),[@@ -1405,7 +1414,24 @@ describe("skill authentication", () => {};expect(await main(- ["patch", "Synthetic issue", "--auth", auth],+ [+ "patch",+ "Synthetic issue",+ "--auth",+ auth,+ ...(explicitProvider+ ? [+ "--codex",+ `model_provider=${JSON.stringify(provider)}`,+ ...Object.entries(providerConfiguration).flatMap(+ ([key, value]) => [+ "--codex",+ `model_providers.${provider}.${key}=${JSON.stringify(value)}`,+ ],+ ),+ ]+ : []),+ ],stdout.stream,stderr.stream,dependencies({@@ -1446,7 +1472,7 @@ describe("skill authentication", () => {expect(requests.find((request) => request.method === "thread/start").params.modelProvider,- ).toBeUndefined();+ ).toBe(explicitProvider ? provider : undefined);}expect(methods).toEqual(["initialize",diff --git a/sdk/typescript/tests-ts/cli-patch.test.ts b/sdk/typescript/tests-ts/cli-patch.test.tsindex 25aa99f11..0ea6b9ce0 100644--- a/sdk/typescript/tests-ts/cli-patch.test.ts+++ b/sdk/typescript/tests-ts/cli-patch.test.ts@@ -758,11 +758,29 @@ describe("scan and patch workflow", () => {"--assess-patch-risk","--codex","analytics.enabled=false",+ "--codex",+ 'model_provider="synthetic.gateway"',+ "--codex",+ 'model_providers={"synthetic.gateway"={name="Synthetic",base_url="https://gateway.example.test/v1",wire_api="responses",env_key="SYNTHETIC_KEY"}}',],{currentDirectory: repository,onCodex: async (args, output) => {expect(args).toContain("analytics.enabled=false");+ expect(args).toContain('model_provider="synthetic.gateway"');+ expect(output?.modelProvider).toBe("synthetic.gateway");+ expect(output?.providerConfiguration?.["env_key"]).toBe(+ "SYNTHETIC_KEY",+ );+ expect(+ parseToml(+ args.find((arg) => arg.startsWith("model_providers="))!,+ ),+ ).toMatchObject({+ model_providers: {+ "synthetic.gateway": { env_key: "SYNTHETIC_KEY" },+ },+ });if (output?.appServer?.prompt.includes("$codex-security:assess-patch-risk",diff --git a/sdk/typescript/tests-ts/cli-skills.test.ts b/sdk/typescript/tests-ts/cli-skills.test.tsindex 70d0267a4..b1544b3f8 100644--- a/sdk/typescript/tests-ts/cli-skills.test.ts+++ b/sdk/typescript/tests-ts/cli-skills.test.ts@@ -5,6 +5,7 @@ import { tmpdir } from "node:os";import { join, posix, resolve, win32 } from "node:path";import { setTimeout as delay } from "node:timers/promises";import { describe, expect, spyOn, test } from "bun:test";+import { parse as parseToml } from "smol-toml";import {main,readSkillCommandOutput,@@ -844,6 +845,79 @@ describe("CLI skill commands", () => {}});+ test.each(["validate", "patch", "verify-fix"] as const)(+ "passes custom inference settings and authentication to %s",+ async (command) => {+ const providerConfiguration = {+ name: "Synthetic gateway",+ base_url: "https://gateway.example.test/v1",+ wire_api: "responses",+ env_key: "SYNTHETIC_GATEWAY_KEY",+ };+ const overrides = [+ 'model="synthetic-model"',+ 'model_provider="synthetic"',+ ...Object.entries(providerConfiguration).map(+ ([key, value]) =>+ `model_providers.synthetic.${key}=${JSON.stringify(value)}`,+ ),+ ];+ const stderr = capture();+ let invocation: readonly string[] = [];+ expect(+ await main(+ [+ command,+ "Synthetic finding",+ ...overrides.flatMap((override) => ["--codex", override]),+ ],+ capture().stream,+ stderr.stream,+ dependencies({+ environment: { SYNTHETIC_GATEWAY_KEY: "SYNTHETIC_VALUE" },+ onCodex: (args, output, environment) => {+ invocation = args;+ expect(output?.modelProvider).toBe("synthetic");+ expect(output?.providerConfiguration).toEqual(+ providerConfiguration,+ );+ expect(environment?.["SYNTHETIC_GATEWAY_KEY"]).toBe(+ "SYNTHETIC_VALUE",+ );+ if (command === "verify-fix") {+ output?.stdout.write(+ JSON.stringify({+ results: [+ {+ id: "finding-1",+ status: "fixed",+ evidence: "Synthetic verification",+ },+ ],+ }),+ );+ }+ return 0;+ },+ }),+ ),+ stderr.text(),+ ).toBe(0);+ expect(invocation).toContain('model="synthetic-model"');+ expect(invocation).toContain('model_provider="synthetic"');+ expect(+ parseToml(+ invocation.find((arg) => arg.startsWith("model_providers="))!,+ ),+ ).toEqual({ model_providers: { synthetic: providerConfiguration } });+ expect(invocation).toContain(+ command === "verify-fix"+ ? 'approval_policy="on-request"'+ : 'approval_policy="never"',+ );+ },+ );+test.each(["validate", "patch", "verify-fix"] as const)("passes explicit analytics settings to %s",async (command) => {@@ -893,7 +967,7 @@ describe("CLI skill commands", () => {}for (const override of [- 'model_provider="synthetic"',+ 'sandbox_mode="danger-full-access"',"features.goals=false","analytics.unrelated=false","analytics.enabled=false",