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(scans): preserve inference endpoints on rerun and resume (#2286)

Michael D'Angelo24c16b8a4bf3
diff --git a/plugins/codex-security/.mcp.json b/plugins/codex-security/.mcp.json
index c42b1fb3a..e5e523af4 100644
--- a/plugins/codex-security/.mcp.json
+++ b/plugins/codex-security/.mcp.json
@@ -8,6 +8,8 @@
"CODEX_HOME",
"CODEX_SQLITE_HOME",
"CODEX_API_KEY",
+ "CODEX_OSS_BASE_URL",
+ "CODEX_OSS_PORT",
"CODEX_SAFETY_IDENTIFIER",
"CODEX_BROWSER_USE_NODE_PATH",
"CODEX_CLI_PATH",
@@ -18,6 +20,9 @@
"OPENROUTER_API_KEY",
"FIREWORKS_API_KEY",
"CHEAPER_INFERENCE_API_KEY",
+ "GOOGLE_CLOUD_PROJECT",
+ "GOOGLE_CLOUD_LOCATION",
+ "GOOGLE_APPLICATION_CREDENTIALS",
"AWS_BEARER_TOKEN_BEDROCK",
"AWS_ACCESS_KEY_ID",
"AWS_SECRET_ACCESS_KEY",
diff --git a/plugins/codex-security/mcp-app/tests/test_deep_scan_coordinator.ts b/plugins/codex-security/mcp-app/tests/test_deep_scan_coordinator.ts
index 8bb4a655f..230e7ad03 100644
--- a/plugins/codex-security/mcp-app/tests/test_deep_scan_coordinator.ts
+++ b/plugins/codex-security/mcp-app/tests/test_deep_scan_coordinator.ts
@@ -32,6 +32,7 @@ import {
DeepScanCoordinatorRegistry,
WorkbenchDeepScanStore,
DeepScanRemoteCoordinator,
+ DeepScanNonRetryableError,
AsyncLock,
classifyCodexWorkerError,
codexWorkerTurnError,
diff --git a/plugins/codex-security/mcp-app/tests/test_mcp_app_smoke.ts b/plugins/codex-security/mcp-app/tests/test_mcp_app_smoke.ts
index ea1f11b65..817d272e9 100644
--- a/plugins/codex-security/mcp-app/tests/test_mcp_app_smoke.ts
+++ b/plugins/codex-security/mcp-app/tests/test_mcp_app_smoke.ts
@@ -78,6 +78,8 @@ assert.deepEqual(
"CODEX_HOME",
"CODEX_SQLITE_HOME",
"CODEX_API_KEY",
+ "CODEX_OSS_BASE_URL",
+ "CODEX_OSS_PORT",
"CODEX_SAFETY_IDENTIFIER",
"CODEX_BROWSER_USE_NODE_PATH",
"CODEX_CLI_PATH",
@@ -88,6 +90,9 @@ assert.deepEqual(
"OPENROUTER_API_KEY",
"FIREWORKS_API_KEY",
"CHEAPER_INFERENCE_API_KEY",
+ "GOOGLE_CLOUD_PROJECT",
+ "GOOGLE_CLOUD_LOCATION",
+ "GOOGLE_APPLICATION_CREDENTIALS",
"AWS_BEARER_TOKEN_BEDROCK",
"AWS_ACCESS_KEY_ID",
"AWS_SECRET_ACCESS_KEY",
@@ -126,7 +131,7 @@ assert.deepEqual(
"NODE_EXTRA_CA_CERTS",
"XDG_CACHE_HOME",
],
- "The MCP process and SDK workers must inherit Codex, external-provider, and Bedrock authentication, AWS credential-chain settings, runtime paths, and enterprise proxy/certificate configuration.",
+ "The MCP process and SDK workers must inherit provider routing and authentication, runtime paths, and enterprise proxy/certificate configuration.",
);
const target = await temporaryDirectory("codex-security-target-");
const replacementTarget = await temporaryDirectory(
diff --git a/sdk/typescript/docs/cli.md b/sdk/typescript/docs/cli.md
index e98b1d3aa..002526fe1 100644
--- a/sdk/typescript/docs/cli.md
+++ b/sdk/typescript/docs/cli.md
@@ -2092,9 +2092,21 @@ history. Inspect its saved status before choosing resume or rerun, and supply
the original custom prompt files for reruns. Structured history and log output
and command selection defaults are unchanged.
-Recipes save settings and authentication choice, not credentials. Reruns use the
-current checkout/context files and do not reload project files. Supply replacement
-scan and custom-validation prompts when the original used them:
+Reruns use the current checkout/context files and do not reload project files.
+The readable scan recipe records your authentication choice. A separate private
+replay profile stores explicit `openai_base_url`, `chatgpt_base_url`, and custom
+`model_providers` settings, including any credentials written directly in
+`http_headers`. If you use `env_key` or `env_http_headers`, the profile stores
+the variable names. Set those variables when you rerun or resume. Settings
+inherited from a named file profile are reloaded from that file. If an older
+scan omitted your endpoint, start a new scan with the original `--codex` override.
+
+When routing through environment variables, set them for each launch, including
+rerun and resume. Deep workers inherit `CODEX_OSS_BASE_URL` and `CODEX_OSS_PORT`
+for Ollama and LM Studio, and `GOOGLE_CLOUD_PROJECT`, `GOOGLE_CLOUD_LOCATION`,
+and `GOOGLE_APPLICATION_CREDENTIALS` for Vertex AI.
+
+Supply replacement scan and custom-validation prompts when the original used them:
```bash
codex-security scans rerun SCAN_ID --scan-prompt-file instructions.md
diff --git a/sdk/typescript/src/api.ts b/sdk/typescript/src/api.ts
index 4c6004641..6c8e27f91 100644
--- a/sdk/typescript/src/api.ts
+++ b/sdk/typescript/src/api.ts
@@ -2629,25 +2629,41 @@ export class CodexSecurity {
};
}
}
+ let replayOverrides: JsonObject = {};
if (fileProfile) {
recipeConfig["profile"] = profileName;
delete recipeConfig["skills"];
// Reload inherited file settings, retaining explicit refinements omitted
// from the readable recipe in the existing private replay snapshot.
delete recipeConfig["model_providers"];
- const replayOverrides = privateReplayOverrides(overrides, recipeConfig);
+ replayOverrides = privateReplayOverrides(overrides, recipeConfig);
resolveNestedConfigPaths(replayOverrides, scanDir);
- if (
- options.resumeScanId === undefined &&
- Object.keys(replayOverrides).length > 0
- ) {
- savedProviderProfile = await createProviderProfile(
- codexSecurityCredentialHome(this.#dependencies.environment),
- replayOverrides,
- { replay: true },
- );
+ } else {
+ // The readable recipe can contain a provider's defaults in place of its overrides.
+ for (const key of [
+ "openai_base_url",
+ "chatgpt_base_url",
+ "model_providers",
+ ]) {
+ const value = workerRuntimeConfig[key];
+ if (
+ value !== undefined &&
+ !isDeepStrictEqual(value, recipeConfig[key])
+ ) {
+ replayOverrides[key] = value;
+ }
}
}
+ if (
+ options.resumeScanId === undefined &&
+ Object.keys(replayOverrides).length > 0
+ ) {
+ savedProviderProfile = await createProviderProfile(
+ codexSecurityCredentialHome(this.#dependencies.environment),
+ replayOverrides,
+ { replay: true },
+ );
+ }
const scanKnowledge =
knowledgeBase === null ? undefined : options.knowledgeBaseSnapshot;
let severityRubric: SeverityRubricSnapshot | undefined;
diff --git a/sdk/typescript/tests-ts/api-provider-isolation.test.ts b/sdk/typescript/tests-ts/api-provider-isolation.test.ts
index b93552717..dacd1bc3c 100644
--- a/sdk/typescript/tests-ts/api-provider-isolation.test.ts
+++ b/sdk/typescript/tests-ts/api-provider-isolation.test.ts
@@ -1,7 +1,14 @@
import { codexFactory, completedEvents } from "./support/api-events.js";
import { afterEach, expect, mock, test } from "bun:test";
import { parse as parseToml, stringify as stringifyToml } from "smol-toml";
-import type { JsonObject } from "../src/config.js";
+import {
+ OPENROUTER_CODEX_PROVIDER,
+ resolveCodexProfile,
+ type JsonObject,
+} from "../src/config.js";
+import { main } from "../src/cli.js";
+import { dependencies } from "./cli-fixtures.js";
+import { createCliTest } from "./support/cli-run.js";
import { spawn } from "node:child_process";
import { once } from "node:events";
import { existsSync } from "node:fs";
@@ -80,6 +87,10 @@ async function nativeRequest(
}
}
+async function readProviderProfile(home: string, name: string) {
+ return parseToml(await readFile(join(home, `${name}.config.toml`), "utf8"));
+}
+
async function effectiveProvider(
environment: Record<string, string>,
cwd: string,
@@ -87,11 +98,9 @@ async function effectiveProvider(
nativeProfile?: string,
) {
if (nativeProfile !== undefined) {
- const config = parseToml(
- await readFile(
- join(environment["CODEX_HOME"]!, `${nativeProfile}.config.toml`),
- "utf8",
- ),
+ const config = await readProviderProfile(
+ environment["CODEX_HOME"]!,
+ nativeProfile,
);
const result = await nativeRequest(environment, cwd, [], "thread/start", {
cwd,
@@ -1110,51 +1119,85 @@ test("standard scans do not require Deep Scan plugin capabilities", async () =>
}
});
-test.each(["root", "profile"])(
- "current Deep workers inherit the %s endpoint",
- async (selection) => {
+test.each([
+ ["root", "openai"],
+ ["profile", "openai"],
+ ["root", "openrouter"],
+ ["profile", "openrouter"],
+] as const)(
+ "Deep workers, rerun and resume inherit the %s %s endpoint",
+ async (selection, provider) => {
const root = await temporaryDirectory();
const repository = join(root, "repository");
const scan = join(root, "scan");
await mkdir(repository);
await mkdir(scan, { mode: 0o700 });
const endpoint = "https://endpoint.example.test/v1";
+ const routing: JsonObject =
+ provider === "openai"
+ ? {
+ openai_base_url: endpoint,
+ chatgpt_base_url: "https://account.example.test",
+ }
+ : {
+ model_provider: provider,
+ model_providers: {
+ [provider]: {
+ ...OPENROUTER_CODEX_PROVIDER,
+ base_url: endpoint,
+ query_params: { version: "preview" },
+ },
+ },
+ };
+ const environment = {
+ CODEX_SECURITY_STATE_DIR: join(root, "state"),
+ OPENAI_API_KEY: "synthetic-openai-key",
+ OPENROUTER_API_KEY: "synthetic-openrouter-key",
+ };
+ let recipe: JsonObject;
const client = new TestClient(
{
pluginPath: PLUGIN_ROOT,
codexOverrides:
selection === "root"
- ? { openai_base_url: endpoint }
+ ? routing
: {
+ openai_base_url: "https://unused.example.test/v1",
profile: "selected",
- profiles: {
- selected: {
- model_provider: "openai",
- openai_base_url: endpoint,
- },
- },
+ profiles: { selected: routing },
},
},
{
- environment: {
- CODEX_SECURITY_STATE_DIR: join(root, "state"),
- OPENAI_API_KEY: "synthetic-openai-key",
+ environment,
+ runWorkbench: async (_options, args, input) => {
+ if (args[0] === "register-cli-scan")
+ recipe = JSON.parse(input!).recipe;
+ return mockWorkbench(args, input);
},
resolvePluginPython: async () => "/managed/python",
prepareOutputDir: async () => scan,
repositoryRevision: async () => "deadbeef",
createCodex: (options) =>
codexFactory(async function runStreamed() {
- expect(options.config?.["openai_base_url"]).toBe(endpoint);
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);
+ const runtime = worker["worker_runtime"] as JsonObject;
+ const profile = runtime["native_profile"];
+ const providerConfig =
+ typeof profile === "string"
+ ? await readProviderProfile(
+ options.env!["CODEX_HOME"]!,
+ profile,
+ )
+ : {};
+ expect({ ...options.config, ...providerConfig }).toMatchObject(
+ routing,
+ );
+ expect({ ...runtime, ...providerConfig }).toMatchObject(routing);
throw new Error("synthetic endpoint inherited");
})(),
},
@@ -1163,6 +1206,24 @@ test.each(["root", "profile"])(
await expect(client.run(repository, { mode: "deep" })).rejects.toThrow(
"synthetic endpoint inherited",
);
+ expect(JSON.stringify(recipe!)).not.toContain(endpoint);
+ for (const command of ["rerun", "resume"]) {
+ const { runCli, stderr } = createCliTest(main);
+ const status = await runCli(
+ ["scans", command, "saved", "--json"],
+ dependencies({
+ currentDirectory: repository,
+ environment,
+ onWorkbench: () => ({ scanId: "saved", scanDir: scan, recipe }),
+ onConfig: ({ codexOverrides }) => {
+ expect(resolveCodexProfile(codexOverrides!)).toMatchObject(
+ routing,
+ );
+ },
+ }),
+ );
+ expect(status, stderr.text()).toBe(0);
+ }
} finally {
await client.close();
}