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(deep-scan): preserve inherited MCP transports and native profile server names (#2303)

Michael D'Angelodb45a14af7a3
diff --git a/plugins/codex-security/mcp-app/src/deep-scan/executor.ts b/plugins/codex-security/mcp-app/src/deep-scan/executor.ts
index d7cff5a57..bcf54cfcf 100644
--- a/plugins/codex-security/mcp-app/src/deep-scan/executor.ts
+++ b/plugins/codex-security/mcp-app/src/deep-scan/executor.ts
@@ -80,6 +80,7 @@ interface CodexSdkWorkerRuntimeSettings {
config: Record<string, unknown>;
preflightProviderOverrides?: string[];
nativeProfile?: string;
+ profileMcpServerNames?: string[];
cyberAccessProgram?: CyberAccessProgram;
}
@@ -210,12 +211,6 @@ export class CodexSdkWorkerExecutor implements CodexWorkerExecutor {
...(this.modelSettings.serviceTier === undefined
? {}
: { service_tier: this.modelSettings.serviceTier }),
- mcp_servers: {
- // A disabled server still needs a valid transport during native resolution.
- "codex-security": { command: "node", enabled: false },
- ...(discovery &&
- this.compactArtifactServer(discovery, includePathsFile)),
- },
...(discovery
? workerSubagentConfig(
discovery.subagents,
@@ -230,6 +225,9 @@ export class CodexSdkWorkerExecutor implements CodexWorkerExecutor {
apps: false,
plugins: false,
shell_tool: false,
+ view_image: false,
+ image_generation: false,
+ computer_use: false,
unified_exec: false,
code_mode: false,
code_mode_only: false,
@@ -294,14 +292,23 @@ export class CodexSdkWorkerExecutor implements CodexWorkerExecutor {
expectedProfile: workerProfile,
allowOpenAiApiKeyFallback: Boolean(openAiApiKey && !codexApiKey),
});
- if (!discovery) {
- for (const name of mcpServerNames) {
- if (name !== "codex-security")
- configOverrides.push(
- `mcp_servers.${JSON.stringify(name)}.enabled=false`,
- );
- }
- }
+ const inheritedServers = new Set([
+ ...mcpServerNames,
+ ...(runtimeSettings.profileMcpServerNames ?? []),
+ ]);
+ // Merge flags into the existing transports. Native -c splits dotted keys
+ // even when the server name is quoted; a single TOML table preserves it.
+ const servers = discovery
+ ? {
+ "codex-security": inheritedServers.has("codex-security")
+ ? { enabled: false }
+ : { command: "node", enabled: false },
+ ...this.compactArtifactServer(discovery, includePathsFile),
+ }
+ : Object.fromEntries(
+ [...inheritedServers].map((name) => [name, { enabled: false }]),
+ );
+ configOverrides.push(...profileConfigOverrides({ mcp_servers: servers }));
const prompt =
request.kind === "compare"
? request.prompt
@@ -725,6 +732,11 @@ export async function workerRuntimeSettings(
"utf8",
),
);
+ if (isRecord(nativeProfileConfig.mcp_servers)) {
+ settings.profileMcpServerNames = Object.keys(
+ nativeProfileConfig.mcp_servers,
+ );
+ }
if (isRecord(nativeProfileConfig.model_providers)) {
const providers = preflightProviderDefinitions(
nativeProfileConfig.model_providers,
diff --git a/plugins/codex-security/mcp-app/tests/support/fake-codex-source.ts b/plugins/codex-security/mcp-app/tests/support/fake-codex-source.ts
index 7bea514e5..696f95bc9 100644
--- a/plugins/codex-security/mcp-app/tests/support/fake-codex-source.ts
+++ b/plugins/codex-security/mcp-app/tests/support/fake-codex-source.ts
@@ -38,7 +38,7 @@ ${jsonLineInputSource(` if (message.method === 'initialized') continue;
}
result = { thread: { id: message.params.threadId, path: join(process.env.CODEX_HOME, message.params.threadId + '.jsonl') } };
} else if (message.method === 'config/read') {
- result = { config: { default_permissions: 'codex_security_deep_scan_worker', permissions: { codex_security_deep_scan_worker: preflightProfile }, mcp_servers: { 'fixture.catalog': { command: 'node' } } }, origins: {}, layers: null };
+ result = { config: { default_permissions: 'codex_security_deep_scan_worker', permissions: { codex_security_deep_scan_worker: preflightProfile }, mcp_servers: { 'fixture.catalog': { command: 'node' }, 'codex-security': { url: 'https://fixture.invalid/mcp' } } }, origins: {}, layers: null };
} else if (message.method === 'permissionProfile/list') {
result = { data: [{ id: 'codex_security_deep_scan_worker', description: null, allowed: preflightAllowed }], nextCursor: null };
} else if (message.method === 'account/read') {
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.ts
index 5a3b41180..047fb7515 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
@@ -979,7 +979,7 @@ async function testSdkInvocationAndThreadCapture() {
assertFlagPair(invocation.argv, "--model", "gpt-5.6-luna");
assertConfigOverrides(invocation.argv, {
model_reasoning_effort: "xhigh",
- "mcp_servers.codex-security.command": "node",
+ "mcp_servers.codex-security.command": undefined,
"mcp_servers.codex-security.enabled": false,
});
assertReadOnlyWorkerPolicy(invocation.argv);
@@ -995,7 +995,9 @@ async function testSdkInvocationAndThreadCapture() {
const preflight = await readJson(fixture.preflightMarkerPath);
assert.deepEqual(
nativeConfigOverrides(preflight.argv),
- nativeConfigOverrides(invocation.argv),
+ nativeConfigOverrides(invocation.argv).filter(
+ (arg) => !arg.startsWith("mcp_servers="),
+ ),
);
assertWorkerSubagentPolicy(invocation.argv, 3);
assertFlagPair(invocation.argv, "--cd", workingDirectory);
@@ -1032,12 +1034,23 @@ async function testReportOnlyComparison() {
"responses_api_metadata.codex_security_worker_role": "compare",
"mcp_servers.cs_artifacts": undefined,
"features.shell_tool": false,
+ "features.image_generation": false,
+ "features.view_image": false,
+ "features.computer_use": false,
"features.multi_agent_v2": false,
web_search: "disabled",
});
- assert.ok(
- invocation.argv.includes('mcp_servers."fixture.catalog".enabled=false'),
- );
+ const preflight = await readJson(fixture.preflightMarkerPath);
+ assertConfigOverrides(preflight.argv, {
+ "mcp_servers.codex-security.command": undefined,
+ });
+ const servers = nativeConfigOverrides(invocation.argv)
+ .map((arg) => parseToml(arg).mcp_servers)
+ .findLast(Boolean);
+ assert.deepEqual(JSON.parse(JSON.stringify(servers)), {
+ "fixture.catalog": { enabled: false },
+ "codex-security": { enabled: false },
+ });
});
}
@@ -2556,7 +2569,9 @@ env_key = "SYNTHETIC_GATEWAY_KEY"`,
nativeConfigOverrides(launch.args).filter(
(override) => !override.startsWith("model_providers="),
),
- nativeConfigOverrides(execution.args),
+ nativeConfigOverrides(execution.args).filter(
+ (override) => !override.startsWith("mcp_servers="),
+ ),
);
}
await Promise.all(
@@ -2617,6 +2632,9 @@ async function testBedrockCredentialsReachWorker(
await writeFile(
path.join(codexHome, `${nativeProfile}.config.toml`),
stringifyToml({
+ mcp_servers: {
+ "profile.catalog": { url: "https://fixture.invalid/mcp" },
+ },
model_providers: { "amazon-bedrock": providerConfig },
}),
);
@@ -2695,6 +2713,19 @@ async function testBedrockCredentialsReachWorker(
model_reasoning_summary: "none",
});
}
+ await executor.compareFindings(
+ "Compare the supplied reports.",
+ workingDirectory,
+ new AbortController().signal,
+ { type: "object", properties: { reviews: { type: "array" } } },
+ );
+ const comparison = await readJson(fixture.markerPath);
+ const servers = nativeConfigOverrides(comparison.argv)
+ .map((arg) => parseToml(arg).mcp_servers)
+ .findLast(Boolean);
+ assert.deepEqual(JSON.parse(JSON.stringify(servers))["profile.catalog"], {
+ enabled: false,
+ });
} finally {
for (const [name, value] of previousEnvironment) {
restoreEnv(name, value);
diff --git a/sdk/typescript/tests-ts/cli-skill-native-config.test.ts b/sdk/typescript/tests-ts/cli-skill-native-config.test.ts
index cc4ca2bb3..d429eb54a 100644
--- a/sdk/typescript/tests-ts/cli-skill-native-config.test.ts
+++ b/sdk/typescript/tests-ts/cli-skill-native-config.test.ts
@@ -543,6 +543,9 @@ test.each(["omitted", "omitted with changed gates", "explicit"] as const)(
await writeCodexConfig(join(sharedHome, "config.toml"), {
model_catalog_json: modelCatalog,
openai_base_url: baseUrl,
+ mcp_servers: {
+ "codex-security": { url: `${baseUrl}/mcp`, enabled: false },
+ },
cli_auth_credentials_store: "file",
features: { plugins: false },
analytics: { enabled: false },