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: preserve per-scan endpoints in Deep Scan workers (#1326)
mldangelo-oaie884fc1ddd38
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 4d5afafe5..6415afabd 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@@ -1316,7 +1316,8 @@ async function testWorkerRuntimeSettings() {await mkdir(codexHome);await writeFile(path.join(codexHome, "config.toml"),- `model = "fixture-inherited-model"+ `openai_base_url = "https://ambient.example.test/v1"+model = "fixture-inherited-model"model_reasoning_effort = "medium"model_provider = "synthetic"[model_providers.synthetic]@@ -1348,6 +1349,10 @@ env_key = "SYNTHETIC_GATEWAY_KEY"`,string,Record<string, unknown>>;+ const endpoint =+ index === 1+ ? undefined+ : `https://synthetic-user:synthetic-password@worker-${index}.example.test/v1?token=synthetic-${index}-token`;const serviceTier =index === 0 ? undefined : index === 3 ? "flex" : "fast";const instructionsFile =@@ -1437,6 +1442,7 @@ env_key = "SYNTHETIC_GATEWAY_KEY"`,SYNTHETIC_GATEWAY_KEY: providerKeys[index],SYNTHETIC_HEADER_VALUE: providerHeaders[index],},+ endpoint,serviceTier,instructionsFile,verbosity,@@ -1476,8 +1482,11 @@ env_key = "SYNTHETIC_GATEWAY_KEY"`,writeFile(entry.deepPath,stringifyToml({- worker_runtime:- entry.provider === undefined+ worker_runtime: {+ ...(entry.endpoint === undefined+ ? {}+ : { openai_base_url: entry.endpoint }),+ ...(entry.provider === undefined? {}: {model_instructions_file: entry.instructionsFile,@@ -1491,7 +1500,8 @@ env_key = "SYNTHETIC_GATEWAY_KEY"`,environment: entry.environment,windows: { sandbox: entry.windowsSandbox },features: entry.features,- },+ }),+ },}),),...(entry.profilePath === undefined@@ -1662,6 +1672,7 @@ env_key = "SYNTHETIC_GATEWAY_KEY"`,assert.equal(process.env.SYNTHETIC_GATEWAY_KEY, undefined);assert.equal(process.env.SYNTHETIC_HEADER_VALUE, undefined);assertConfigOverrides(invocation.argv, {+ openai_base_url: workerConfigurations[index].endpoint,model_reasoning_summary: expected,service_tier: workerConfigurations[index].serviceTier,model_instructions_file:@@ -1808,6 +1819,7 @@ env_key = "SYNTHETIC_GATEWAY_KEY"`,selectedProvider.environment?.SYNTHETIC_HEADER_VALUE,);assertConfigOverrides(preflight.argv, {+ openai_base_url: selectedProvider.endpoint,model_instructions_file: selectedProvider.instructionsFile,model_verbosity: selectedProvider.verbosity,model_context_window: selectedProvider.modelContextWindow,@@ -1892,7 +1904,7 @@ env_key = "SYNTHETIC_GATEWAY_KEY"`,),writeFile(entry.deepPath,- '[worker_runtime.features]\nshell_tool = true\nunified_exec = true\nview_image = true\n[worker_runtime]\nweb_search = "live"\nmodel_provider = "changed"\nnative_profile = "changed"\nmodel_instructions_file = "changed-instructions.md"\nmodel_verbosity = "changed"\nmodel_context_window = 999000\nmodel_auto_compact_token_limit = 888000\n[worker_runtime.windows]\nsandbox = "changed"\n[worker_runtime.environment]\nSYNTHETIC_GATEWAY_KEY = "changed"\nSYNTHETIC_HEADER_VALUE = "changed"\n',+ '[worker_runtime.features]\nshell_tool = true\nunified_exec = true\nview_image = true\n[worker_runtime]\nopenai_base_url = "https://changed-snapshot.example.test/v1"\nweb_search = "live"\nmodel_provider = "changed"\nnative_profile = "changed"\nmodel_instructions_file = "changed-instructions.md"\nmodel_verbosity = "changed"\nmodel_context_window = 999000\nmodel_auto_compact_token_limit = 888000\n[worker_runtime.windows]\nsandbox = "changed"\n[worker_runtime.environment]\nSYNTHETIC_GATEWAY_KEY = "changed"\nSYNTHETIC_HEADER_VALUE = "changed"\n',),]),),diff --git a/sdk/typescript/src/api.ts b/sdk/typescript/src/api.tsindex a08a97d22..988e2ca30 100644--- a/sdk/typescript/src/api.ts+++ b/sdk/typescript/src/api.ts@@ -2875,11 +2875,13 @@ export class CodexSecurity {);const approvalPolicy = scanApprovalPolicy(effectiveConfig);const preflightConfig = scanPreflightCodexConfig(effectiveConfig);- const providers = resolveCodexProfile(effectiveConfig)["model_providers"];+ const resolvedConfig = resolveCodexProfile(effectiveConfig);+ const providers = resolvedConfig["model_providers"];if (deepScan &&((typeof modelProvider === "string" && modelProvider !== "openai") ||- (isRecord(providers) && Object.keys(providers).length > 0)) &&+ (isRecord(providers) && Object.keys(providers).length > 0) ||+ resolvedConfig["openai_base_url"] !== undefined) &&(runtime.deepScanConfigPath === undefined ||!(await pluginSupportsWorkerProviderSnapshot(runtime.plugin.pluginRoot,@@ -4894,6 +4896,7 @@ function selectedWorkerRuntimeConfig(return {...Object.fromEntries([+ "openai_base_url","features","model_auto_compact_token_limit","model_context_window",diff --git a/sdk/typescript/tests-ts/api-attribution-concurrency.test.ts b/sdk/typescript/tests-ts/api-attribution-concurrency.test.tsindex c606e50cf..6420836f5 100644--- a/sdk/typescript/tests-ts/api-attribution-concurrency.test.ts+++ b/sdk/typescript/tests-ts/api-attribution-concurrency.test.ts@@ -17,12 +17,16 @@ afterEach(fixtures.cleanup);describe("delegated scan attribution", () => {test.each([- ["standard", true],- ["deep", true],- ["standard", false],+ ["standard", true, "root"],+ ["deep", true, "profile-override"],+ ["standard", false, "unset"],+ ["deep", false, "profile-only"],+ ["deep", true, "root"],+ ["deep", true, "profile-fallback"],+ ["deep", true, "unset"],] as const)(- "keeps overlapping CLI and SDK %s scans attributed with Cyber selection %p",- async (mode, selectProgram) => {+ "keeps overlapping CLI and SDK %s scans attributed with Cyber selection %p and %s endpoint",+ async (mode, selectProgram, endpointSource) => {const root = await fixtures.temporaryDirectory();const repository = join(root, "repository");const ambientHome = join(root, "ambient-home");@@ -41,6 +45,21 @@ describe("delegated scan attribution", () => {const clients = await Promise.all((["cli", "sdk"] as const).map(async (surface) => {const program = surface === "cli" ? programs[0] : programs[1];+ const endpoint =+ endpointSource === "unset"+ ? undefined+ : `https://synthetic-user:synthetic-password@${surface}.example.test/v1?token=synthetic-${surface}-token`;+ const rootEndpoint =+ endpointSource === "profile-only"+ ? undefined+ : endpointSource === "profile-override"+ ? "https://overridden.example.test/v1"+ : endpoint;+ const profileEndpoint =+ endpointSource === "profile-only" ||+ endpointSource === "profile-override"+ ? endpoint+ : undefined;const features = selectProgram? {api_key_cyber_access_programs: surface === "cli",@@ -64,7 +83,26 @@ describe("delegated scan attribution", () => {return new InternalSecurity({pluginPath: PLUGIN_ROOT,- ...(surface === "sdk" ? { codexOverrides: { features } } : {}),+ codexOverrides: {+ ...(rootEndpoint === undefined+ ? {}+ : { openai_base_url: rootEndpoint }),+ ...(endpointSource.startsWith("profile-")+ ? {+ profile: "selected",+ profiles: {+ selected:+ profileEndpoint === undefined+ ? {}+ : { openai_base_url: profileEndpoint },+ unselected: {+ openai_base_url: "https://unused.example.test/v1",+ },+ },+ }+ : {}),+ ...(surface === "sdk" ? { features } : {}),+ },},{environment: {@@ -135,6 +173,9 @@ describe("delegated scan attribution", () => {expect(options.env).not.toHaveProperty("OPENAI_API_KEY");expect(options.apiKey).toBe(`synthetic-${surface}-key`);expect(turnOptions?.cyberAccessProgram).toBe(program);+ expect(options.config?.["openai_base_url"]).toBe(+ endpoint,+ );expect(options.config).toMatchObject({features,responses_api_metadata: {@@ -148,7 +189,28 @@ describe("delegated scan attribution", () => {configPaths.add(configPath!);const initialConfig = await readFile(configPath!, "utf8");const runtimeConfig = parseToml(initialConfig);+ if (mode === "deep") {+ const deepConfigPath =+ options.env?.["CODEX_SECURITY_DEEP_SCAN_CONFIG_PATH"];+ expect(deepConfigPath).toBeString();+ const deepConfig = parseToml(+ await readFile(deepConfigPath!, "utf8"),+ );+ const workerRuntime = deepConfig[+ "worker_runtime"+ ] as Record<string, unknown>;+ if (endpoint === undefined)+ expect(workerRuntime).not.toHaveProperty(+ "openai_base_url",+ );+ else+ expect(workerRuntime["openai_base_url"]).toBe(+ endpoint,+ );+ }expect(runtimeConfig).toMatchObject({ features });+ expect(initialConfig).not.toContain("openai_base_url");+ expect(initialConfig).not.toContain("synthetic-password");if (program === undefined) {expect(runtimeConfig).not.toHaveProperty("codex_security",@@ -174,6 +236,12 @@ describe("delegated scan attribution", () => {"responses_api_metadata",);expect(sharedConfig).not.toHaveProperty("codex_security");+ expect(JSON.stringify(sharedConfig)).not.toContain(+ "openai_base_url",+ );+ expect(JSON.stringify(sharedConfig)).not.toContain(+ "synthetic-password",+ );expect(sharedConfig["features"] ?? {}).not.toHaveProperty("api_key_cyber_access_programs",);diff --git a/sdk/typescript/tests-ts/api-preflight-config.test.ts b/sdk/typescript/tests-ts/api-preflight-config.test.tsindex e1b90d3ed..0f64544c5 100644--- a/sdk/typescript/tests-ts/api-preflight-config.test.ts+++ b/sdk/typescript/tests-ts/api-preflight-config.test.ts@@ -615,6 +615,8 @@ describe("CodexSecurity preflight configuration", () => {const sanitized = scanPreflightCodexConfig({model: "gpt-5.6-sol",model_reasoning_effort: "high",+ openai_base_url:+ "https://synthetic-user:[email protected]/v1?token=synthetic-root-token",features: {plugins: true,goals: true,@@ -626,6 +628,8 @@ describe("CodexSecurity preflight configuration", () => {profiles: {review: {model: "profile-model",+ openai_base_url:+ "https://synthetic-user:[email protected]/v1?token=synthetic-profile-token",features: { goals: true, secret: "PROFILE_SECRET" },agents: { max_threads: 4, token: "PROFILE_AGENT_TOKEN" },shell_environment_policy: { set: { SECRET: "PROFILE_ENV_SECRET" } },diff --git a/sdk/typescript/tests-ts/api-provider-isolation.test.ts b/sdk/typescript/tests-ts/api-provider-isolation.test.tsindex 4ed84eeeb..5c92302d8 100644--- a/sdk/typescript/tests-ts/api-provider-isolation.test.ts+++ b/sdk/typescript/tests-ts/api-provider-isolation.test.ts@@ -572,6 +572,7 @@ const legacyScanCases: Array<capability?: true | number;inherited?: string;managed?: string;+ isolatedConfig?: boolean;rejects?: boolean;reads?: boolean;},@@ -588,6 +589,93 @@ const legacyScanCases: Array<["standard", "standard", {}, {}],["deep", "deep", {}, {}],["standard with explicit provider", "standard", legacyProviders[0]![1], {}],+ [+ "deep with a root endpoint and no private snapshot",+ "deep",+ { openai_base_url: "https://endpoint.example.test/v1" },+ { isolatedConfig: false, rejects: true },+ ],+ [+ "deep with an OpenAI endpoint and readable snapshot",+ "deep",+ {+ model_provider: "openai",+ openai_base_url: "https://endpoint.example.test/v1",+ },+ { capability: true, rejects: true },+ ],+ [+ "deep with a profile endpoint and selector snapshot 2",+ "deep",+ {+ profile: "selected",+ profiles: {+ selected: { openai_base_url: "https://endpoint.example.test/v1" },+ },+ },+ { capability: 2, rejects: true },+ ],+ [+ "deep with a profile endpoint override and selector snapshot 3",+ "deep",+ {+ openai_base_url: "https://unused.example.test/v1",+ profile: "selected",+ profiles: {+ selected: {+ model_provider: "openai",+ openai_base_url: "https://endpoint.example.test/v1",+ },+ },+ },+ { capability: 3, rejects: true },+ ],+ [+ "deep with an endpoint fallback and no private snapshot path",+ "deep",+ {+ openai_base_url: "https://endpoint.example.test/v1",+ profile: "selected",+ profiles: { selected: { model_provider: "openai" } },+ },+ { capability: 4, isolatedConfig: false, rejects: true },+ ],+ [+ "standard with an endpoint and no private snapshot",+ "standard",+ { openai_base_url: "https://endpoint.example.test/v1" },+ { isolatedConfig: false },+ ],+ [+ "deep with an unused profile endpoint",+ "deep",+ {+ profiles: {+ unused: { openai_base_url: "https://unused.example.test/v1" },+ },+ },+ { isolatedConfig: false },+ ],+ [+ "deep with a root endpoint and runtime snapshot 4",+ "deep",+ { openai_base_url: "https://endpoint.example.test/v1" },+ { capability: 4 },+ ],+ [+ "deep with a profile endpoint and runtime snapshot 4",+ "deep",+ {+ profile: "selected",+ profiles: {+ selected: {+ model_provider: "openai",+ openai_base_url: "https://endpoint.example.test/v1",+ },+ },+ },+ { capability: 4 },+ ],["deep with explicit OpenAI","deep",@@ -664,6 +752,15 @@ test.each(legacyScanCases)(if (native.capability === undefined) delete manifest.codexSecurity;else manifest.codexSecurity = { workerProviderSnapshot: native.capability };await writeFile(manifestPath, JSON.stringify(manifest));+ if (native.isolatedConfig === false) {+ const mcpPath = join(plugin, ".mcp.json");+ const configuration = JSON.parse(await readFile(mcpPath, "utf8"));+ const server = configuration.mcpServers["codex-security"];+ server.env_vars = server.env_vars.filter(+ (name: string) => name !== "CODEX_SECURITY_DEEP_SCAN_CONFIG_PATH",+ );+ await writeFile(mcpPath, JSON.stringify(configuration));+ }const callsPath = join(root, "config-reads.jsonl");const fakeNative = join(root, "native-config.mjs");await writeFile(@@ -727,6 +824,21 @@ test.each(legacyScanCases)(expect(resolveCodexProfile(config as JsonObject)["model_provider"],).toBe(resolveCodexProfile(overrides)["model_provider"]);+ const endpoint =+ resolveCodexProfile(overrides)["openai_base_url"];+ expect(endpoint).toBe(options.config?.["openai_base_url"]);+ expect(config).not.toHaveProperty("openai_base_url");+ if (mode === "deep" && endpoint !== undefined) {+ const worker = parseToml(+ await readFile(+ options.env!["CODEX_SECURITY_DEEP_SCAN_CONFIG_PATH"]!,+ "utf8",+ ),+ );+ expect(+ (worker["worker_runtime"] as JsonObject)["openai_base_url"],+ ).toBe(endpoint);+ }if (native.capability === 2 || native.capability === 3) {const worker = parseToml(await readFile(