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

refactor: simplify scan configuration processing (#1459)

mldangelo-oaid4a4eaf31537
diff --git a/plugins/codex-security/mcp-app/src/deep-scan/coordinator.ts b/plugins/codex-security/mcp-app/src/deep-scan/coordinator.ts
index 5b73449bb..88879e99a 100644
--- a/plugins/codex-security/mcp-app/src/deep-scan/coordinator.ts
+++ b/plugins/codex-security/mcp-app/src/deep-scan/coordinator.ts
@@ -662,8 +662,7 @@ export class DeepScanCoordinator {
let lastReplaceableFailure:
Extract<DiscoveryOutcome, { status: "failed" }> | undefined;
- const errorLimit =
- config.stopAfterConsecutiveErrors ?? config.stopAfterNoNew;
+ const errorLimit = config.stopAfterConsecutiveErrors;
let reducerFailures = persistedReducerFailureStreak(
this.state.persistedWorkers ?? [],
);
diff --git a/plugins/codex-security/scripts/config_preflight.py b/plugins/codex-security/scripts/config_preflight.py
index 15338627f..bbcb55885 100644
--- a/plugins/codex-security/scripts/config_preflight.py
+++ b/plugins/codex-security/scripts/config_preflight.py
@@ -268,12 +268,10 @@ def project_trust_level(
def project_config_paths(project_root: Path, cwd: Path) -> list[Path]:
relative = cwd.relative_to(project_root)
- directories = [project_root]
- current = project_root
- for part in relative.parts:
- current /= part
- directories.append(current)
- return [directory / ".codex" / "config.toml" for directory in directories]
+ return [
+ project_root / directory / ".codex" / "config.toml"
+ for directory in reversed((relative, *relative.parents))
+ ]
def discover_config_paths(
diff --git a/plugins/codex-security/scripts/deep_scan_config.py b/plugins/codex-security/scripts/deep_scan_config.py
index b1f2c7862..d03e63b1d 100644
--- a/plugins/codex-security/scripts/deep_scan_config.py
+++ b/plugins/codex-security/scripts/deep_scan_config.py
@@ -4,7 +4,6 @@ from __future__ import annotations
import argparse
import json
-import math
import os
import sys
from pathlib import Path
@@ -124,11 +123,7 @@ def require_integer(value: object, label: str, *, minimum: int) -> int:
def require_positive_number(value: object, label: str) -> int | float:
if isinstance(value, bool) or not isinstance(value, (int, float)):
raise SystemExit(f"{label} must be a positive finite number no greater than 96.")
- try:
- finite = math.isfinite(value)
- except OverflowError:
- finite = False
- if not finite or value <= 0 or value > MAX_TIME_HOURS:
+ if not 0 < value <= MAX_TIME_HOURS:
raise SystemExit(f"{label} must be a positive finite number no greater than 96.")
return value
diff --git a/plugins/codex-security/tests/test_workbench_deep_scan.py b/plugins/codex-security/tests/test_workbench_deep_scan.py
index 47c0f9d42..e2e0ff185 100644
--- a/plugins/codex-security/tests/test_workbench_deep_scan.py
+++ b/plugins/codex-security/tests/test_workbench_deep_scan.py
@@ -1872,7 +1872,9 @@ def test_invalid_discovery_error_threshold_fails_before_scan_creation(
assert connection.execute("SELECT COUNT(*) FROM scans").fetchone() == (0,)
[email protected]("invalid_hours", ("0", "-0.5", "true", '"2"', "nan", "inf", "96.5"))
+ "invalid_hours", ("0", "-0.5", "true", '"2"', "nan", "inf", "96.5", "9" * 400)
+)
def test_invalid_discovery_time_limit_fails_before_scan_creation(
tmp_path: Path, invalid_hours: str
) -> None:
diff --git a/sdk/typescript/src/config.ts b/sdk/typescript/src/config.ts
index d4ab296e3..ee4b71f9d 100644
--- a/sdk/typescript/src/config.ts
+++ b/sdk/typescript/src/config.ts
@@ -235,16 +235,59 @@ export async function mergedCodexConfig(
validateOverrideKeys(config.codexOverrides ?? {});
const overrides = structuredClone(config.codexOverrides ?? {});
validateOverrides(overrides);
- validateNativeMultiAgentV2Overrides(overrides);
- normalizeLegacyWindowsSandboxOverride(overrides);
- const profiles = overrides["profiles"];
- if (isObject(profiles)) {
- for (const profile of Object.values(profiles)) {
- if (isObject(profile)) {
- normalizeLegacyWindowsSandboxOverride(profile);
- }
+ const agents = overrides["agents"];
+ if (isObject(agents) && "max_threads" in agents) {
+ throw new ConfigurationError(
+ "The selected Codex Security plugin requires native multi-agent v2; " +
+ "agents.max_threads is a legacy v1 setting. Use " +
+ "features.multi_agent_v2.max_concurrent_threads_per_session instead.",
+ );
+ }
+ const features = overrides["features"];
+ if (isObject(features) && "multi_agent_v2" in features) {
+ const multiAgentV2 = features["multi_agent_v2"];
+ if (!isObject(multiAgentV2)) {
+ throw new ConfigurationError(
+ "The selected Codex Security plugin requires native multi-agent v2; " +
+ "features.multi_agent_v2 must remain a table with enabled = true.",
+ );
+ }
+ if ("enabled" in multiAgentV2 && multiAgentV2["enabled"] !== true) {
+ throw new ConfigurationError(
+ "The selected Codex Security plugin requires native multi-agent v2; " +
+ "features.multi_agent_v2.enabled cannot be disabled.",
+ );
}
}
+
+ const profiles = Object.entries(
+ (overrides["profiles"] ?? {}) as Record<string, JsonObject>,
+ );
+ for (const [name, profile] of profiles) {
+ const profileAgents = profile["agents"];
+ if (isObject(profileAgents) && "max_threads" in profileAgents) {
+ throw new ConfigurationError(
+ `The selected Codex Security plugin requires native multi-agent v2; profile ${name} agents.max_threads is a legacy v1 setting.`,
+ );
+ }
+ const profileFeatures = profile["features"];
+ if (!isObject(profileFeatures) || !("multi_agent_v2" in profileFeatures)) {
+ continue;
+ }
+ const profileV2 = profileFeatures["multi_agent_v2"];
+ if (
+ !isObject(profileV2) ||
+ ("enabled" in profileV2 && profileV2["enabled"] !== true)
+ ) {
+ throw new ConfigurationError(
+ `The selected Codex Security plugin requires native multi-agent v2; profile ${name} features.multi_agent_v2 cannot be disabled.`,
+ );
+ }
+ }
+ normalizeLegacyWindowsSandboxOverride(overrides);
+ for (const [, profile] of profiles) {
+ normalizeLegacyWindowsSandboxOverride(profile);
+ }
const defaults: JsonObject = structuredClone(DEFAULT_CODEX_CONFIG);
if (scanModelProvider(overrides) === "amazon-bedrock") {
// Bedrock models can reject reasoning.summary before the scan starts.
@@ -378,64 +421,6 @@ function validateOverrides(overrides: JsonObject): void {
}
}
-function validateNativeMultiAgentV2Overrides(overrides: JsonObject): void {
- const agents = overrides["agents"];
- if (isObject(agents) && "max_threads" in agents) {
- throw new ConfigurationError(
- "The selected Codex Security plugin requires native multi-agent v2; " +
- "agents.max_threads is a legacy v1 setting. Use " +
- "features.multi_agent_v2.max_concurrent_threads_per_session instead.",
- );
- }
- const features = overrides["features"];
- if (isObject(features)) {
- if ("multi_agent_v2" in features) {
- const multiAgentV2 = features["multi_agent_v2"];
- if (!isObject(multiAgentV2)) {
- throw new ConfigurationError(
- "The selected Codex Security plugin requires native multi-agent v2; " +
- "features.multi_agent_v2 must remain a table with enabled = true.",
- );
- }
- if ("enabled" in multiAgentV2 && multiAgentV2["enabled"] !== true) {
- throw new ConfigurationError(
- "The selected Codex Security plugin requires native multi-agent v2; " +
- "features.multi_agent_v2.enabled cannot be disabled.",
- );
- }
- }
- }
-
- const profiles = overrides["profiles"];
- if (!isObject(profiles)) {
- return;
- }
- for (const [name, profile] of Object.entries(profiles)) {
- if (!isObject(profile)) {
- continue;
- }
- const profileAgents = profile["agents"];
- if (isObject(profileAgents) && "max_threads" in profileAgents) {
- throw new ConfigurationError(
- `The selected Codex Security plugin requires native multi-agent v2; profile ${name} agents.max_threads is a legacy v1 setting.`,
- );
- }
- const profileFeatures = profile["features"];
- if (!isObject(profileFeatures) || !("multi_agent_v2" in profileFeatures)) {
- continue;
- }
- const profileV2 = profileFeatures["multi_agent_v2"];
- if (
- !isObject(profileV2) ||
- ("enabled" in profileV2 && profileV2["enabled"] !== true)
- ) {
- throw new ConfigurationError(
- `The selected Codex Security plugin requires native multi-agent v2; profile ${name} features.multi_agent_v2 cannot be disabled.`,
- );
- }
- }
-}
-
export function mergeCodexOverrides(
base: JsonObject,
overrides: JsonObject,