Skip to content

OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security

fix(cli): preserve profile provider settings for inline patches (#1810)

Michael D'Angelofad7bdbc600d
diff --git a/sdk/typescript/src/cli.ts b/sdk/typescript/src/cli.ts
index 896dff43d..ffa6a2574 100644
--- a/sdk/typescript/src/cli.ts
+++ b/sdk/typescript/src/cli.ts
@@ -8795,16 +8795,15 @@ async function executeScan(
)
: arguments_.auth;
if (typeof provider === "string") {
+ const providerConfiguration = (
+ resolvedConfiguration["model_providers"] as
+ Record<string, JsonObject> | undefined
+ )?.[provider];
providerOptions = {
provider,
- providerConfiguration:
- (
- effectiveConfiguration["model_providers"] as
- Record<string, JsonObject> | undefined
- )?.[provider] ??
- (isExternalModelProvider(provider)
- ? EXTERNAL_CODEX_PROVIDERS[provider]
- : undefined),
+ providerConfiguration: isExternalModelProvider(provider)
+ ? { ...EXTERNAL_CODEX_PROVIDERS[provider], ...providerConfiguration }
+ : providerConfiguration,
};
}
selectedAuthentication = arguments_.mock
diff --git a/sdk/typescript/tests-ts/cli-scan-patch-settings.test.ts b/sdk/typescript/tests-ts/cli-scan-patch-settings.test.ts
index 12c5759b4..b9e3beabf 100644
--- a/sdk/typescript/tests-ts/cli-scan-patch-settings.test.ts
+++ b/sdk/typescript/tests-ts/cli-scan-patch-settings.test.ts
@@ -1,7 +1,9 @@
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { describe, expect, test } from "bun:test";
+import { parse } from "smol-toml";
import { main, runCodexSkillCommand } from "../src/cli.js";
+import { FIREWORKS_CODEX_PROVIDER, inlineToml } from "../src/config.js";
import { dependencies, fakePreflight, fakeResult } from "./cli-fixtures.js";
import { createCliTest } from "./support/cli-run.js";
import { temporaryDirectory } from "./support/temporary-directories.js";
@@ -18,6 +20,8 @@ const receipt = {
argv: process.argv.slice(2),
homeTier: homeConfig.match(/^service_tier\\s*=\\s*(.*)$/m)?.[1] ?? null,
homeDaybreak: homeConfig.match(/^daybreak\\s*=\\s*(.*)$/m)?.[1] ?? null,
+ providerKey: process.env.SYNTHETIC_PROVIDER_KEY ?? null,
+ providerHeader: process.env.SYNTHETIC_PROVIDER_HEADER ?? null,
};
for await (const line of createInterface({ input: process.stdin })) {
const request = JSON.parse(line);
@@ -69,6 +73,8 @@ interface ChildReceipt {
daybreakEnabled: boolean | null;
experimentalApi: boolean;
features: Record<string, boolean>;
+ providerKey: string | null;
+ providerHeader: string | null;
}
async function patchSettings(
@@ -102,6 +108,10 @@ async function patchSettings(
),
),
OPENAI_API_KEY: "SYNTHETIC_LOCAL_KEY",
+ FIREWORKS_API_KEY: "SYNTHETIC_FIREWORKS_KEY",
+ SYNTHETIC_ROOT_KEY: "SYNTHETIC_ROOT_VALUE",
+ SYNTHETIC_PROVIDER_KEY: "SYNTHETIC_PROVIDER_VALUE",
+ SYNTHETIC_PROVIDER_HEADER: "SYNTHETIC_HEADER_VALUE",
CODEX_HOME: join(root, "home"),
CODEX_SECURITY_STATE_DIR: join(root, "state"),
SYNTHETIC_PATCH_RECEIPT: receipt,
@@ -161,6 +171,143 @@ async function patchSettings(
}
}
+describe("inline patch provider configuration", () => {
+ const provider = {
+ name: "Synthetic gateway",
+ base_url: "https://root.example.test/v1",
+ wire_api: "responses",
+ env_key: "SYNTHETIC_ROOT_KEY",
+ http_headers: { "X-Root": "retained", "X-Selected": "root" },
+ };
+ const selected = {
+ base_url: "https://selected.example.test/v1",
+ env_key: "SYNTHETIC_PROVIDER_KEY",
+ http_headers: { "X-Selected": "profile" },
+ env_http_headers: { "X-Synthetic": "SYNTHETIC_PROVIDER_HEADER" },
+ };
+ const root = [
+ 'model_provider="gateway"',
+ `model_providers.gateway=${inlineToml(provider)}`,
+ ];
+ const definition = (child: ChildReceipt) =>
+ parse(
+ child.argv
+ .filter((value) => value.startsWith("model_providers="))
+ .join("\n"),
+ )["model_providers"];
+
+ test.each([
+ ["root definition", root, provider],
+ [
+ "profile-only definition",
+ [
+ 'profile="selected"',
+ 'profiles.selected.model_provider="gateway"',
+ `profiles.selected.model_providers.gateway=${inlineToml(provider)}`,
+ ],
+ provider,
+ ],
+ [
+ "selected profile overrides",
+ [
+ ...root,
+ 'profile="selected"',
+ `profiles.selected.model_providers.gateway=${inlineToml(selected)}`,
+ ],
+ {
+ ...provider,
+ ...selected,
+ http_headers: { ...provider.http_headers, ...selected.http_headers },
+ },
+ ],
+ [
+ "inactive profile",
+ [
+ ...root,
+ `profiles.inactive.model_providers.gateway=${inlineToml(selected)}`,
+ ],
+ provider,
+ ],
+ ] as const)(
+ "preserves the %s at the child-process boundary",
+ async (_, overrides, expected) => {
+ const child = await patchSettings(
+ overrides.flatMap((value) => ["--codex", value]),
+ );
+ expect(child.argv).toContain('model_provider="gateway"');
+ expect(definition(child)).toEqual({ gateway: expected });
+ expect(child.providerKey).toBe("SYNTHETIC_PROVIDER_VALUE");
+ expect(child.providerHeader).toBe("SYNTHETIC_HEADER_VALUE");
+ expect(child.argv).toContain('model="gpt-6.1-sol"');
+ expect(child.argv).toContain('model_reasoning_effort="low"');
+ expect(child.approvalPolicy).toBe("never");
+ expect(child.sandbox).toBe("workspace-write");
+ expect(child.preflightSandbox).toBe("workspaceWrite");
+ },
+ );
+
+ test.each([
+ ["no override", undefined, FIREWORKS_CODEX_PROVIDER],
+ [
+ "partial override",
+ { http_headers: { "X-Selected": "profile" } },
+ {
+ ...FIREWORKS_CODEX_PROVIDER,
+ http_headers: { "X-Selected": "profile" },
+ },
+ ],
+ ["full override", provider, provider],
+ ] as const)(
+ "preserves external provider defaults with a selected profile %s",
+ async (_, override, expected) => {
+ const child = await patchSettings(
+ [
+ 'profile="selected"',
+ 'profiles.selected.model_provider="fireworks"',
+ ...(override === undefined
+ ? []
+ : [
+ `profiles.selected.model_providers.fireworks=${inlineToml(override)}`,
+ ]),
+ ].flatMap((value) => ["--codex", value]),
+ );
+ expect(child.argv).toContain('model_provider="fireworks"');
+ expect(definition(child)).toEqual({ fireworks: expected });
+ },
+ );
+
+ test("keeps overlapping selected provider definitions isolated", async () => {
+ let arrivals = 0;
+ const { promise: ready, resolve: release } = Promise.withResolvers<void>();
+ const beforeChild = async () => {
+ if (++arrivals === 2) release();
+ await ready;
+ };
+ const providers = ["first", "second"].map((name) => ({
+ ...provider,
+ base_url: `https://${name}.example.test/v1`,
+ }));
+ const children = await Promise.all(
+ providers.map((definition) =>
+ patchSettings(
+ [
+ "--codex",
+ 'profile="selected"',
+ "--codex",
+ 'profiles.selected.model_provider="gateway"',
+ "--codex",
+ `profiles.selected.model_providers.gateway=${inlineToml(definition)}`,
+ ],
+ { beforeChild },
+ ),
+ ),
+ );
+ expect(children.map(definition)).toEqual(
+ providers.map((gateway) => ({ gateway })),
+ );
+ });
+});
+
describe("inline patch service tier", () => {
test.each([
["explicit fast", ["--codex", 'service_tier="fast"'], "fast"],