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
feat: add verbose security scan diagnostics (#63)
mldangelo-oai7b7e031df81d
diff --git a/README.md b/README.mdindex 6ae20d94e..7d2dcb3f9 100644--- a/README.md+++ b/README.md@@ -19,9 +19,9 @@ npx @openai/codex-security scan . --model gpt-5.6-terra --effort highnpx @openai/codex-security scan . --mode deep --workers 2 --subagents 0 --stop-after-no-new 3 --max-discovery-runs 10```-For CI, set `OPENAI_API_KEY` or `CODEX_API_KEY` instead of signing in. Environment API keys are-passed directly to the current scan and are never stored in Codex's credential-home or system keyring.+For CI, set `OPENAI_API_KEY` or `CODEX_API_KEY` instead of signing in.+Environment API keys are passed directly to the current scan and are never+stored in Codex's credential home or system keyring.Local sign-in honors Codex's configured credential backend, including a systemkeyring required by a managed device. Codex Security keeps login and scan@@ -52,6 +52,18 @@ root cause, reuses saved matches, and identifies new, persisting, reopened,resolved, or unknown findings. Missing findings remain unknown when coverage isincomplete or their original location was not reviewed.+## Verbose diagnostics++Add `--verbose` to print redacted scan diagnostics to stderr:++```bash+npx @openai/codex-security scan . --verbose+```++`CODEX_SECURITY_LOG_LEVEL=debug` also enables diagnostics;+`LOG_LEVEL=debug` is its fallback. JSON results remain on stdout, and+credentials and provider identifiers remain redacted.+## TypeScript SDK```tsdiff --git a/sdk/typescript/README.md b/sdk/typescript/README.mdindex a42b064c4..abbf9f6d5 100644--- a/sdk/typescript/README.md+++ b/sdk/typescript/README.md@@ -180,6 +180,7 @@ npx @openai/codex-security scan /path/to/repository --knowledge-base /path/to/thnpx @openai/codex-security scan /path/to/repository --diff origin/main --jsonnpx @openai/codex-security scan /path/to/repository --output-dir /path/outside/repository/resultsnpx @openai/codex-security scan /path/to/repository --output-dir /path/outside/repository/results --archive-existing+npx @openai/codex-security scan /path/to/repository --verbosenpx @openai/codex-security scan /path/to/repository --dry-runnpx @openai/codex-security scan /path/to/repository --fail-on-severity highnpx @openai/codex-security scan /path/to/repository --max-cost 5@@ -371,6 +372,8 @@ The CLI and SDK recognize the following user-configurable environment:| Variable | Effect || --------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- || `OPENAI_API_KEY`, `CODEX_API_KEY` | Scan authentication; `OPENAI_API_KEY` wins when both are present. |+| `CODEX_SECURITY_LOG_LEVEL` | CLI-only; set to `debug` for redacted diagnostics. |+| `LOG_LEVEL` | CLI-only fallback when `CODEX_SECURITY_LOG_LEVEL` is unset. || `CODEX_SECURITY_STATE_DIR` | Override the private scan-history, workbench, and default artifact directory. || `CODEX_HOME` | Set the ambient Codex home for file-backed sign-in and default state; defaults to `~/.codex`. || `PYTHON` | Select a Python interpreter when `--python` or SDK `pythonPath` is not set. |@@ -406,6 +409,12 @@ token and worker counts, estimated cost, the results directory, and the nextuseful command.Progress and summaries use stderr; structured scan results remain on stdout.+Add `--verbose` or set `CODEX_SECURITY_LOG_LEVEL=debug` to print redacted+lifecycle, authentication, progress, and cost diagnostics to stderr.+`LOG_LEVEL=debug` is used only when `CODEX_SECURITY_LOG_LEVEL` is unset.+Credentials and provider identifiers remain redacted, and structured JSON+results remain on stdout.+Each scan records its model, tokens, and estimated cost in its JSON result,scan history, and bulk-scan receipt. Estimates use[standard API token prices](https://developers.openai.com/api/docs/models/compare),diff --git a/sdk/typescript/src/cli.ts b/sdk/typescript/src/cli.tsindex 34f773d84..c10460560 100644--- a/sdk/typescript/src/cli.ts+++ b/sdk/typescript/src/cli.ts@@ -233,6 +233,7 @@ const DEEP_SCAN_OPTION_SCHEMAS = {interface ScanArguments extends DeepScanOptions {auth?: ScanAuthMode;+ verbose?: boolean;repository?: string;paths: string[];knowledgeBasePaths: string[];@@ -1000,6 +1001,10 @@ export async function main(.describe("Select ChatGPT, OPENAI_API_KEY/CODEX_API_KEY, or automatic authentication.",),+ verbose: z+ .boolean()+ .default(false)+ .describe("Print redacted scan diagnostics to stderr."),path: z.array(optionValue("--path")).default([])@@ -1134,6 +1139,7 @@ export async function main(const outcome = await runScan({auth: options.auth,+ verbose: options.verbose,repository: args.repository,paths: options.path,knowledgeBasePaths: options.knowledgeBase,@@ -2562,6 +2568,17 @@ async function runExport(}}+type VerboseDiagnosticValue = string | number | boolean | null | undefined;++function sanitizeDiagnosticValue(value: unknown): string {+ return redactedErrorMessage(value)+ .replaceAll(+ /(\b(?:tenant(?:[_-]?id)?|org(?:anization)?(?:[_-]?id)?|project(?:[_-]?id)?|(?:x[_-]?)?(?:request|trace|correlation)[_-]?id)\b(?:\\*["'])?\s*[:=]\s*)(?!\[redacted\])(?:(\\*)(['"])(?:(?!(?<!\\)\2\3)(?:\\.|[^\\]))*(?:(?<!\\)\2\3|$)|[^\s"',;&}\]]+)/giu,+ "$1$2$3[redacted]$2$3",+ )+ .replaceAll(/[\u0000-\u001F\u007F\u0085\u2028\u2029]/gu, " ");+}+async function runScan(arguments_: ScanArguments,errorOutput: Writable,@@ -2574,6 +2591,37 @@ async function runScan(let progress: Progress | null = null;let lastWorkerUpdate = "";let phase: string | null = null;+ const configuredLogLevel =+ dependencies.environment["CODEX_SECURITY_LOG_LEVEL"]?.trim() ||+ dependencies.environment["LOG_LEVEL"]?.trim();+ const verbose =+ arguments_.verbose === true ||+ configuredLogLevel?.toLowerCase() === "debug";+ const writeAboveProgress = (write: () => void): void => {+ if (progress === null) {+ write();+ return;+ }+ progress.writeAboveTimer(write);+ };+ const diagnostic = (+ event: string,+ fields: Readonly<Record<string, VerboseDiagnosticValue>> = {},+ ): void => {+ if (!verbose) return;+ const attributes = Object.entries(fields).flatMap(([name, value]) =>+ value === undefined+ ? []+ : [+ `${name}=${JSON.stringify(typeof value === "string" ? sanitizeDiagnosticValue(value) : value)}`,+ ],+ );+ writeAboveProgress(() => {+ errorOutput.write(+ `codex-security: debug: ${event}${attributes.length === 0 ? "" : ` ${attributes.join(" ")}`}\n`,+ );+ });+ };const preparationAbortController = new AbortController();const signalListener = (signal: SignalName) => () => {if (requestedSignal !== null) {@@ -2615,6 +2663,9 @@ async function runScan(null;let result: ScanResult | null = null;let preflight: ScanPreflight | null = null;+ let effectiveModel = DEFAULT_SCAN_MODEL_CONFIGURATION.model;+ let effectiveReasoningEffort =+ DEFAULT_SCAN_MODEL_CONFIGURATION.reasoningEffort;let selectedAuthentication: ScanAuthentication | null = null;let failed = false;let failure: unknown;@@ -2632,6 +2683,12 @@ async function runScan(arguments_.effort,),};+ const selectedProfileName = config.codexOverrides?.["profile"];+ ({ model: effectiveModel, reasoningEffort: effectiveReasoningEffort } =+ scanModelConfiguration({+ ...DEFAULT_CODEX_CONFIG,+ ...config.codexOverrides,+ }));let auth = arguments_.auth;selectedAuthentication = scanAuthentication(dependencies.environment, auth);if (@@ -2669,6 +2726,29 @@ async function runScan();}}+ diagnostic("scan.configuration", {+ cli_version: VERSION,+ bundled_plugin_version: BUNDLED_PLUGIN_VERSION,+ codex_version: CODEX_EXECUTABLE_VERSION,+ codex_sdk_version: CODEX_SDK_VERSION,+ mode: arguments_.mode,+ target:+ arguments_.paths.length > 0+ ? "paths"+ : arguments_.diff !== undefined+ ? "diff"+ : arguments_.workingTree+ ? "working_tree"+ : "repository",+ requested_auth: auth ?? "auto",+ dry_run: arguments_.dryRun,+ profile:+ typeof selectedProfileName === "string"+ ? selectedProfileName+ : undefined,+ model: effectiveModel,+ reasoning_effort: effectiveReasoningEffort,+ });progress = new Progress(errorOutput, dependencies, interactive);const scope = scanScope(arguments_);const runningMessage = (): string =>@@ -2697,6 +2777,15 @@ async function runScan(failureSeverity: arguments_.failOnSeverity,maxCostUsd: arguments_.maxCostUsd,onCost: (cost) => {+ diagnostic("cost.updated", {+ model: cost.model,+ estimated_usd: cost.estimatedUsd,+ input_tokens: cost.inputTokens,+ cached_input_tokens: cost.cachedInputTokens,+ cache_write_input_tokens: cost.cacheWriteInputTokens,+ output_tokens: cost.outputTokens,+ max_cost_usd: arguments_.maxCostUsd,+ });if (arguments_.maxCostUsd === undefined) return;progress?.stopTimer();progress?.stage(@@ -2707,6 +2796,7 @@ async function runScan(}},onOutputArchived: (archiveDir) => {+ diagnostic("scan.output_archived", { archive_dir: archiveDir });progress?.stopTimer();errorOutput.write(`Moved existing results to: ${redactedErrorMessage(archiveDir)}\n`,@@ -2715,9 +2805,19 @@ async function runScan(signal: preparationAbortController.signal,onOutputDirReady: (path) => {scanDir = path;+ diagnostic("scan.output_ready", { scan_dir: path });},onAuthentication: (authentication) => {selectedAuthentication = authentication;+ diagnostic("authentication.selected", {+ requested: auth ?? "auto",+ method: authentication.method,+ source:+ authentication.method === "api_key"+ ? authentication.source+ : undefined,+ verified: authentication.verified,+ });progress?.stopTimer();if (authentication.method === "api_key") {progress?.stage(@@ -2732,10 +2832,17 @@ async function runScan(progress?.startTimer("Preparing scan");},onScanStarted: () => {+ diagnostic("scan.started");progress?.stopTimer();progress?.startTimer(runningMessage());},onReconnect: (attempt, maxAttempts, details) => {+ diagnostic("connection.retry", {+ reason: details?.reason ?? "unknown",+ attempt,+ max_attempts: maxAttempts,+ retry_after_seconds: details?.retryAfterSeconds,+ });progress?.stopTimer();const message =details?.reason === "rate_limit"@@ -2761,7 +2868,19 @@ async function runScan(: `dispatch:${status.phase}:${status.planned}:${status.started}`;if (update === lastWorkerUpdate) return;lastWorkerUpdate = update;- if (status.kind === "dispatch") phase = scanPhase(status.phase);+ if (status.kind === "preflight") {+ diagnostic("worker.preflight", {+ delegation: status.delegation,+ configured_slots: status.configuredSlots,+ });+ } else {+ diagnostic("worker.phase", {+ phase: status.phase,+ planned: status.planned,+ started: status.started,+ });+ phase = scanPhase(status.phase);+ }const message = workerStatusMessage(status);if (message === null || progress === null) return;progress.stopTimer();@@ -2769,14 +2888,22 @@ async function runScan(progress.startTimer(runningMessage());},onWarning: (warning) => {- errorOutput.write(- `codex-security: warning: ${redactedErrorMessage(warning)}\n`,- );+ writeAboveProgress(() => {+ const message = sanitizeDiagnosticValue(warning);+ diagnostic("scan.warning", { message });+ errorOutput.write(`codex-security: warning: ${message}\n`);+ });},onObserverError: (observer, error) => {- errorOutput.write(- `codex-security: warning: ${observer} observer failed: ${redactedErrorMessage(error)}\n`,- );+ writeAboveProgress(() => {+ diagnostic("scan.observer_failed", {+ observer,+ classification: classifyConnectionFailure(error),+ });+ errorOutput.write(+ `codex-security: warning: ${observer} observer failed: ${sanitizeDiagnosticValue(error)}\n`,+ );+ });},};if (arguments_.dryRun) {@@ -2791,16 +2918,29 @@ async function runScan(failure = error;} finally {progress?.stopTimer();- await security?.close().catch((error: unknown) => {- if (!failed) {- failed = true;- failure = error;- }- });+ if (security !== null) {+ diagnostic("runtime.cleanup.started");+ await security.close().then(+ () => diagnostic("runtime.cleanup.completed"),+ (error: unknown) => {+ diagnostic("runtime.cleanup.failed", {+ classification: classifyConnectionFailure(error),+ });+ if (!failed) {+ failed = true;+ failure = error;+ }+ },+ );+ }removeSignalListeners();}if (requestedSignal !== null) {+ diagnostic("scan.interrupted", {+ signal: requestedSignal,+ partial_output: scanDir !== null,+ });return {exitCode: interruptedExit(requestedSignal, scanDir, errorOutput),error:@@ -2814,6 +2954,12 @@ async function runScan(failure instanceof OutputInsideProtectedRootError? redactedErrorMessage(protectedRootErrorMessage(failure)): scanFailureMessage(failure, selectedAuthentication);+ diagnostic("scan.failed", {+ classification: isLocalScanFailure(failure)+ ? "local"+ : classifyConnectionFailure(failure),+ partial_output: scanDir !== null,+ });errorOutput.write(`${message}\n`);if (failure instanceof ScanInterruptedError) {return { exitCode: 2, error: message };@@ -2826,10 +2972,29 @@ async function runScan(return { exitCode: 2, error: message };}if (preflight !== null) {+ const effectivePreflight: ScanPreflight = {+ ...preflight,+ model: effectiveModel,+ reasoningEffort: effectiveReasoningEffort,+ };progress?.stage("Preflight complete");- return { exitCode: 0, data: { dryRun: true, ...preflight } };+ diagnostic("scan.preflight.completed", {+ model: effectivePreflight.model,+ reasoning_effort: effectivePreflight.reasoningEffort,+ method: effectivePreflight.authentication.method,+ source:+ effectivePreflight.authentication.method === "api_key"+ ? effectivePreflight.authentication.source+ : undefined,+ verified: effectivePreflight.authentication.verified,+ });+ return { exitCode: 0, data: { dryRun: true, ...effectivePreflight } };}if (result === null) {+ diagnostic("scan.failed", {+ classification: "unknown",+ message: "Scan completed without a result.",+ });errorOutput.write("scan completed without a result\n");return { exitCode: 2, error: "Scan completed without a result." };}@@ -2855,6 +3020,13 @@ async function runScan(dependencies.environment["NO_COLOR"] === undefined &&dependencies.environment["TERM"] !== "dumb",);+ diagnostic("scan.completed", {+ coverage: result.coverage.completeness,+ findings: result.findings.findings.length,+ scan_id: result.manifest.scan.id,+ estimated_usd: result.cost?.estimatedUsd,+ exit_code: incomplete ? 2 : blockingCount > 0 ? 1 : 0,+ });if (incomplete) {errorOutput.write(threshold === undefined@@ -2920,7 +3092,7 @@ function scanFailureMessage(// appending it. That is deliberate: upstream authentication and authorization// errors can name the organization or project, which must not reach stderr or// the JSON error field.- if (isLocalScanFailure(error)) return redactedErrorMessage(error);+ if (isLocalScanFailure(error)) return sanitizeDiagnosticValue(error);switch (classifyConnectionFailure(error)) {case "unauthorized":return authentication?.method === "api_key"@@ -2940,7 +3112,7 @@ function scanFailureMessage(case "network_error":case "timeout":case "unknown":- return redactedErrorMessage(error);+ return sanitizeDiagnosticValue(error);}}@@ -3246,6 +3418,7 @@ export class Progress {readonly #startedAt: number;readonly #interactive: boolean;#timer: NodeJS.Timeout | null = null;+ #timerMessage: string | null = null;#timerLineActive = false;#cursorHidden = false;@@ -3290,6 +3463,7 @@ export class Progress {() => this.#renderTimer(message),PROGRESS_REFRESH_MILLISECONDS,);+ this.#timerMessage = message;}public stopTimer(): void {@@ -3297,6 +3471,7 @@ export class Progress {this.#dependencies.clearInterval(this.#timer);this.#timer = null;}+ this.#timerMessage = null;if (this.#timerLineActive) {this.#stream.write("\n");this.#timerLineActive = false;@@ -3307,6 +3482,20 @@ export class Progress {}}+ public writeAboveTimer(write: () => void): void {+ const message = this.#timerMessage;+ if (message === null) {+ write();+ return;+ }+ this.stopTimer();+ try {+ write();+ } finally {+ this.startTimer(message);+ }+ }+#line(message: string): string {const elapsedSeconds = this.elapsedSeconds;const minutes = Math.floor(elapsedSeconds / 60);diff --git a/sdk/typescript/src/config.ts b/sdk/typescript/src/config.tsindex 2fa18a6e4..2527ce207 100644--- a/sdk/typescript/src/config.ts+++ b/sdk/typescript/src/config.ts@@ -44,13 +44,31 @@ deepFreezeJson(DEFAULT_CODEX_CONFIG);export function scanModelConfiguration(config: Readonly<JsonObject>,): ScanModelConfiguration {- const model = config["model"];+ const profileName = config["profile"];+ const profiles = config["profiles"];+ const configuredProfile =+ typeof profileName === "string" &&+ isObject(profiles) &&+ Object.hasOwn(profiles, profileName)+ ? profiles[profileName]+ : undefined;+ const selectedProfile = isObject(configuredProfile)+ ? configuredProfile+ : undefined;+ const model =+ selectedProfile !== undefined && Object.hasOwn(selectedProfile, "model")+ ? selectedProfile["model"]+ : config["model"];if (typeof model !== "string" || model.trim().length === 0) {throw new ConfigurationError("The configured Codex model must be a nonempty string.",);}- const reasoningEffort = config["model_reasoning_effort"];+ const reasoningEffort =+ selectedProfile !== undefined &&+ Object.hasOwn(selectedProfile, "model_reasoning_effort")+ ? selectedProfile["model_reasoning_effort"]+ : config["model_reasoning_effort"];if (typeof reasoningEffort !== "string" ||reasoningEffort.trim().length === 0diff --git a/sdk/typescript/tests-ts/api.test.ts b/sdk/typescript/tests-ts/api.test.tsindex 6f11f48bf..ccebb70d7 100644--- a/sdk/typescript/tests-ts/api.test.ts+++ b/sdk/typescript/tests-ts/api.test.ts@@ -40,6 +40,7 @@ import {scanRuntimeCodexConfig,} from "../src/api.js";import { writeCodexConfig, type JsonObject } from "../src/config.js";+import { estimateScanCost, type ScanCost } from "../src/cost.js";import {runWorkbench,setCodexSecurityCredentialLogout,@@ -692,6 +693,45 @@ describe("CodexSecurity orchestration", () => {await client.close();});+ test("reports selected profile model and reasoning during local-only preflight", async () => {+ const root = await temporaryDirectory();+ const repository = join(root, "repository");+ await mkdir(repository);+ let runtimeStarted = false;+ const client = new TestClient(+ {+ codexOverrides: {+ profile: "review",+ model: "gpt-5.6-sol",+ model_reasoning_effort: "low",+ profiles: {+ review: {+ model: "gpt-5.6-terra",+ model_reasoning_effort: "high",+ },+ },+ },+ },+ {+ environment: {},+ prepareRuntime: async () => {+ runtimeStarted = true;+ throw new Error("runtime should not initialize");+ },+ },+ );++ await expect(+ client.preflight(repository, { maxCostUsd: 5 }),+ ).resolves.toMatchObject({+ model: "gpt-5.6-terra",+ reasoningEffort: "high",+ maxCostUsd: 5,+ });+ expect(runtimeStarted).toBe(false);+ await client.close();+ });+test("validates cost limits and pricing before starting a scan", async () => {const root = await temporaryDirectory();const repository = join(root, "repository");@@ -2054,6 +2094,93 @@ describe("CodexSecurity orchestration", () => {}});+ test("uses selected profile pricing for live and persisted scan cost", async () => {+ const root = await temporaryDirectory();+ const repository = join(root, "repository");+ const codexHome = join(root, "codex-home");+ const scanDir = join(root, "scan");+ await mkdir(repository);+ await mkdir(codexHome);+ await mkdir(scanDir, { mode: 0o700 });++ const usage = {+ input_tokens: 10,+ cached_input_tokens: 2,+ output_tokens: 3,+ reasoning_output_tokens: 1,+ };+ const expectedCost = estimateScanCost("gpt-5.6-terra", usage);+ expect(expectedCost).not.toBeNull();+ if (expectedCost === null) throw new Error("Missing selected-model price");++ const costs: ScanCost[] = [];+ const commands: Array<readonly string[]> = [];+ const client = new TestClient(+ {+ codexOverrides: {+ profile: "review",+ model: "gpt-5.6-sol",+ model_reasoning_effort: "low",+ profiles: {+ review: {+ model: "gpt-5.6-terra",+ model_reasoning_effort: "high",+ },+ },+ },+ },+ {+ environment: {},+ prepareRuntime: async () => preparedRuntime(codexHome),+ resolvePluginPython: async () => "/managed/python",+ prepareOutputDir: async () => scanDir,+ repositoryRevision: async () => "deadbeef",+ runWorkbench: async (_options: unknown, args: readonly string[]) => {+ commands.push(args);+ if (args[0] === "register-cli-scan") {+ return mockScanRegistration(args);+ }+ if (args[0] === "get-scan-feedback") {+ return {+ scanId: "scan_example_001",+ targetId: "target_sha256_example",+ falsePositives: [],+ };+ }+ return {};+ },+ createCodex: () => ({+ startThread: () => ({+ id: null,+ async runStreamed() {+ await copyCompletedScan(root);+ return { events: completedEvents() };+ },+ }),+ }),+ },+ );++ const result = await client.run(repository, {+ maxCostUsd: 1,+ onCost: (cost) => costs.push({ ...cost }),+ });++ expect(result.turnResult.model).toBe("gpt-5.6-terra");+ expect(result.cost).toEqual(expectedCost);+ expect(costs).toEqual([expectedCost]);++ const completion = commands.find((args) => args[0] === "complete-scan");+ expect(completion).toBeDefined();+ const costIndex = completion?.indexOf("--cost-json") ?? -1;+ expect(costIndex).toBeGreaterThan(0);+ expect(JSON.parse(completion?.[costIndex + 1] ?? "null")).toEqual(+ expectedCost,+ );++ await client.close();+ });+test("stops and records a scan as soon as its live cost exceeds the limit", async () => {const root = await temporaryDirectory();const repository = join(root, "repository");diff --git a/sdk/typescript/tests-ts/cli.test.ts b/sdk/typescript/tests-ts/cli.test.tsindex 3f4d5879f..c63268899 100644--- a/sdk/typescript/tests-ts/cli.test.ts+++ b/sdk/typescript/tests-ts/cli.test.ts@@ -113,6 +113,7 @@ describe("CLI", () => {stopAfterNoNew: { type: "integer" },maxDiscoveryRuns: { type: "integer" },model: { type: "string" },+ verbose: { type: "boolean" },effort: { enum: ["minimal", "low", "medium", "high", "xhigh"] },failOnSeverity: { enum: ["critical", "high", "medium", "low"] },},@@ -269,6 +270,8 @@ describe("CLI", () => {for (const setting of ["OPENAI_API_KEY","CODEX_API_KEY",+ "CODEX_SECURITY_LOG_LEVEL",+ "LOG_LEVEL","CODEX_SECURITY_STATE_DIR","CODEX_HOME","PYTHON",@@ -299,6 +302,10 @@ describe("CLI", () => {]) {expect(readme).toContain(setting);}+ expect(readme).toMatch(+ /\|\s*`CODEX_SECURITY_LOG_LEVEL`\s*\|\s*CLI-only\b/u,+ );+ expect(readme).toMatch(/\|\s*`LOG_LEVEL`\s*\|\s*CLI-only\b/u);});test("keeps documented runtime and deep-scan defaults accurate", async () => {@@ -1259,6 +1266,84 @@ describe("CLI", () => {expect(timers).toBe(0);});+ test("keeps verbose diagnostics separate from interactive progress", async () => {+ const stdout = capture();+ const stderr = capture(true);+ const result = fakeResult([], "complete", {+ input_tokens: 200,+ cache_write_input_tokens: 100,+ output_tokens: 0,+ });+ const activeTimers = new Set<NodeJS.Timeout>();+ const deps = dependencies({+ environment: { OPENAI_API_KEY: "sk-proj-SYNTHETIC_TTY_SECRET_123" },+ });+ deps.setInterval = () => {+ const timer = {} as NodeJS.Timeout;+ activeTimers.add(timer);+ return timer;+ };+ deps.clearInterval = (timer) => {+ activeTimers.delete(timer);+ };+ deps.createSecurity = () => ({+ run: async (_repository, options) => {+ expect(activeTimers.size).toBe(1);+ options?.onAuthentication?.({+ method: "api_key",+ source: "OPENAI_API_KEY",+ verified: false,+ });+ expect(activeTimers.size).toBe(1);+ options?.onOutputDirReady?.("/tmp/scan");+ expect(activeTimers.size).toBe(1);+ options?.onCost?.(result.cost!);+ expect(activeTimers.size).toBe(1);+ options?.onWarning?.("Recoverable scanner warning");+ expect(activeTimers.size).toBe(1);+ options?.onObserverError?.(+ "onWorkerStatus",+ new Error("Observer temporarily unavailable"),+ );+ expect(activeTimers.size).toBe(1);+ options?.onScanStarted?.();+ expect(activeTimers.size).toBe(1);+ return result;+ },+ close: async () => {},+ preflight: async () => fakePreflight(),+ });++ expect(+ await main(+ ["scan", ".", "--verbose"],+ stdout.stream,+ stderr.stream,+ deps,+ ),+ ).toBe(0);+ const output = stripVTControlCharacters(stderr.text());+ const diagnosticLines = output+ .split(/[\r\n]+/u)+ .filter(+ (line) =>+ line.includes("codex-security: debug:") ||+ line.includes("codex-security: warning:"),+ );+ expect(diagnosticLines.length).toBeGreaterThan(3);+ for (const line of diagnosticLines) {+ expect(+ line.startsWith("codex-security: debug:") ||+ line.startsWith("codex-security: warning:"),+ ).toBe(true);+ }+ expect(output).not.toMatch(+ /\[[0-9:]+\][^\r\n]*codex-security: (?:debug|warning):/u,+ );+ expect(output).not.toContain("SYNTHETIC_TTY_SECRET");+ expect(activeTimers.size).toBe(0);+ });+test("keeps structured scans noninteractive even when stderr is a terminal", async () => {for (const options of [["--json"],@@ -1485,6 +1570,7 @@ describe("CLI", () => {),).toBe(0);expect(help.text()).toContain("Usage: codex-security scan [repository]");+ expect(help.text()).toContain("--verbose");expect(help.text()).toContain("--path <array>");expect(help.text()).toContain("--max-cost <number>");expect(help.text()).toContain("--workers <number>");@@ -1973,173 +2059,1084 @@ describe("CLI", () => {expect(repository).toBe("repo");});- test("reports reconnect progress on stderr and keeps JSON output clean", async () => {+ test("emits verbose scan lifecycle diagnostics without changing JSON output", async () => {const stdout = capture();const stderr = capture();- const deps = dependencies();+ const result = fakeResult(["high"], "complete", {+ input_tokens: 1_250,+ cached_input_tokens: 200,+ output_tokens: 30,+ });+ const deps = dependencies({+ environment: { OPENAI_API_KEY: "sk-proj-SYNTHETIC_VERBOSE_SECRET_123" },+ });deps.createSecurity = () => ({run: async (_repository, options) => {- const callbacks = options as {- onScanStarted?: () => void;- onReconnect?: (attempt: number, maxAttempts: number) => void;- };- callbacks.onScanStarted?.();- callbacks.onReconnect?.(2, 5);- return fakeResult();+ options?.onAuthentication?.({+ method: "api_key",+ source: "OPENAI_API_KEY",+ verified: false,+ });+ options?.onOutputDirReady?.("/tmp/scan");+ options?.onScanStarted?.();+ options?.onWorkerStatus?.({+ kind: "preflight",+ delegation: "available",+ configuredSlots: 8,+ });+ options?.onWorkerStatus?.({+ kind: "dispatch",+ phase: "validation",+ planned: 6,+ started: 3,+ });+ options?.onReconnect?.(2, 5, {+ reason: "rate_limit",+ retryAfterSeconds: 1.2,+ });+ options?.onCost?.(result.cost!);+ return result;},preflight: async () => fakePreflight(),close: async () => {},});expect(- await main(["scan", "--json"], stdout.stream, stderr.stream, deps),+ await main(+ ["scan", ".", "--verbose", "--json"],+ stdout.stream,+ stderr.stream,+ deps,+ ),).toBe(0);- expect(JSON.parse(stdout.text())).toEqual(fakeResult().toJSON());+ expect(JSON.parse(stdout.text())).toEqual(result.toJSON());expect(stderr.text()).toContain(- "Codex connection interrupted; retrying (2/5)",+ `codex-security: debug: scan.configuration cli_version=${JSON.stringify(VERSION)}`,);- expect(stderr.text()).toContain("Running scan");+ expect(stderr.text()).toContain(+ `bundled_plugin_version=${JSON.stringify(BUNDLED_PLUGIN_VERSION)}`,+ );+ expect(stderr.text()).toContain(+ 'codex-security: debug: authentication.selected requested="auto" method="api_key" source="OPENAI_API_KEY" verified=false',+ );+ expect(stderr.text()).toContain(+ 'codex-security: debug: scan.output_ready scan_dir="/tmp/scan"',+ );+ expect(stderr.text()).toContain("codex-security: debug: scan.started");+ expect(stderr.text()).toContain(+ 'codex-security: debug: worker.preflight delegation="available" configured_slots=8',+ );+ expect(stderr.text()).toContain(+ 'codex-security: debug: worker.phase phase="validation" planned=6 started=3',+ );+ expect(stderr.text()).toContain(+ 'codex-security: debug: connection.retry reason="rate_limit" attempt=2 max_attempts=5 retry_after_seconds=1.2',+ );+ expect(stderr.text()).toContain(+ 'codex-security: debug: cost.updated model="gpt-5.6-sol"',+ );+ expect(stderr.text()).toContain(+ 'codex-security: debug: scan.completed coverage="complete" findings=1',+ );+ expect(stderr.text()).toContain(+ "codex-security: debug: runtime.cleanup.started",+ );+ expect(stderr.text()).toContain(+ "codex-security: debug: runtime.cleanup.completed",+ );+ expect(stderr.text()).not.toContain("SYNTHETIC_VERBOSE_SECRET");});- test("renders bounded rate-limit retry details without leaking provider context", async () => {+ test("reports the effective default model and reasoning effort in verbose scan diagnostics", async () => {const stdout = capture();const stderr = capture();- const deps = dependencies();- deps.createSecurity = () => ({- run: async (_repository, options) => {- options?.onScanStarted?.();- options?.onReconnect?.(2, 5, {- reason: "rate_limit",- retryAfterSeconds: 1.2,- });- options?.onReconnect?.(3, 5, { reason: "rate_limit" });- return fakeResult();- },- preflight: async () => fakePreflight(),- close: async () => {},- });expect(- await main(["scan", "--json"], stdout.stream, stderr.stream, deps),+ await main(+ ["scan", ".", "--verbose", "--json"],+ stdout.stream,+ stderr.stream,+ dependencies(),+ ),).toBe(0);expect(JSON.parse(stdout.text())).toEqual(fakeResult().toJSON());- expect(stderr.text()).toContain(- "Rate limit reached; retrying in 1.2s (2/5).",+ const configuration = stderr+ .text()+ .split("\n")+ .find((line) =>+ line.startsWith("codex-security: debug: scan.configuration"),+ );+ expect(configuration).toBeDefined();+ expect(configuration).toContain(+ `model=${JSON.stringify(DEFAULT_SCAN_MODEL_CONFIGURATION.model)}`,+ );+ expect(configuration).toContain(+ `reasoning_effort=${JSON.stringify(DEFAULT_SCAN_MODEL_CONFIGURATION.reasoningEffort)}`,);- expect(stderr.text()).toContain("Rate limit reached; retrying (3/5).");});- test("renders safe reconnect causes without forwarding provider messages", async () => {+ test("includes selected reasoning effort in verbose scan diagnostics", async () => {const stdout = capture();const stderr = capture();- const deps = dependencies();- deps.createSecurity = () => ({- run: async (_repository, options) => {- options?.onReconnect?.(1, 5, { reason: "network" });- options?.onReconnect?.(2, 5, { reason: "authentication" });- options?.onReconnect?.(3, 5, { reason: "authorization" });- return fakeResult();- },- preflight: async () => fakePreflight(),- close: async () => {},- });expect(- await main(["scan", "--json"], stdout.stream, stderr.stream, deps),+ await main(+ ["scan", ".", "--effort", "high", "--verbose", "--json"],+ stdout.stream,+ stderr.stream,+ dependencies(),+ ),).toBe(0);- expect(stderr.text()).toContain("Network connection interrupted; retrying");- expect(stderr.text()).toContain("Authentication interrupted; retrying");- expect(stderr.text()).toContain("Model access interrupted; retrying");expect(JSON.parse(stdout.text())).toEqual(fakeResult().toJSON());+ expect(stderr.text()).toContain(+ "codex-security: debug: scan.configuration",+ );+ expect(stderr.text()).toContain('reasoning_effort="high"');});- test("turns authentication and rate-limit failures into actionable safe messages", async () => {- for (const [message, expected] of [- ["401 invalid API key for org-private", "provide a valid API key"],- ["403 model access denied for org-private", "model access"],- ["429 rate limit reached for org-private", "rate limit"],- ] as const) {- const stdout = capture();- const stderr = capture();- const deps = dependencies();- deps.createSecurity = () => ({- run: async () => {- throw new CodexSecurityError(message);- },- preflight: async () => fakePreflight(),- close: async () => {},- });+ test("reports reasoning effort supplied through legacy --codex overrides", async () => {+ const stdout = capture();+ const stderr = capture();- expect(await main(["scan"], stdout.stream, stderr.stream, deps)).toBe(2);- expect(stderr.text()).toContain(expected);- expect(stderr.text()).not.toContain("org-private");- }+ expect(+ await main(+ [+ "scan",+ ".",+ "--codex",+ 'model_reasoning_effort="high"',+ "--verbose",+ "--json",+ ],+ stdout.stream,+ stderr.stream,+ dependencies(),+ ),+ ).toBe(0);+ expect(JSON.parse(stdout.text())).toEqual(fakeResult().toJSON());+ expect(stderr.text()).toContain('reasoning_effort="high"');});- test("surfaces underlying scanner errors instead of inventing a model outage", async () => {- for (const message of [- "Could not save the Codex Security scan: UNIQUE constraint failed: scans.scan_dir",- "sandbox-exec: sandbox_apply: Operation not permitted during network setup.",- "network failure ECONNRESET while connecting to the model.",- "request timed out while reading the scanner response.",- ]) {+ test("reports effective model and reasoning settings from the selected Codex profile", async () => {+ const scenarios = [+ {+ overrides: [+ 'profile="review"',+ 'model="gpt-5.6-sol"',+ 'model_reasoning_effort="low"',+ 'profiles.review.model="gpt-5.6-terra"',+ 'profiles.review.model_reasoning_effort="high"',+ ],+ model: "gpt-5.6-terra",+ reasoningEffort: "high",+ },+ {+ overrides: [+ 'profile="review"',+ 'model_reasoning_effort="low"',+ 'profiles.review.model="gpt-5.6-terra"',+ ],+ model: "gpt-5.6-terra",+ reasoningEffort: "low",+ },+ {+ overrides: [+ 'profile="review"',+ 'model="gpt-5.6-terra"',+ 'profiles.review.model_reasoning_effort="medium"',+ ],+ model: "gpt-5.6-terra",+ reasoningEffort: "medium",+ },+ ] as const;++ for (const scenario of scenarios) {const stdout = capture();const stderr = capture();- const deps = dependencies();- deps.createSecurity = () => ({- run: async () => {- throw new CodexSecurityError(message);- },- preflight: async () => fakePreflight(),- close: async () => {},- });expect(- await main(["scan", ".", "--json"], stdout.stream, stderr.stream, deps),- ).toBe(2);- expect(stdout.text()).toBe("");- expect(stderr.text()).toContain(`${message}\n`);- expect(stderr.text()).not.toContain("codex-security:");- expect(stderr.text()).not.toContain("model service could not be reached");+ await main(+ [+ "scan",+ ".",+ ...scenario.overrides.flatMap((override) => ["--codex", override]),+ "--verbose",+ "--json",+ ],+ stdout.stream,+ stderr.stream,+ dependencies(),+ ),+ ).toBe(0);+ expect(JSON.parse(stdout.text())).toEqual(fakeResult().toJSON());+ const configuration = stderr+ .text()+ .split("\n")+ .find((line) =>+ line.startsWith("codex-security: debug: scan.configuration"),+ );+ expect(configuration).toBeDefined();+ expect(configuration).toContain('profile="review"');+ expect(configuration).toContain(+ `model=${JSON.stringify(scenario.model)}`,+ );+ expect(configuration).toContain(+ `reasoning_effort=${JSON.stringify(scenario.reasoningEffort)}`,+ );}});- test("reports local input and filesystem failures without connectivity advice", async () => {- // https://github.com/openai/codex-security/issues/36 -- classification- // matches bare words such as "permission denied" anywhere in the message,- // so local failures were reported as credential or connectivity problems- // and their own text was discarded.- const failures: Array<[string, unknown]> = [- [- "EACCES from a read-only TMPDIR",- Object.assign(- new Error(- "EACCES: permission denied, mkdtemp '/tmp/openai-codex-security-home-XXXXXX'",- ),- { code: "EACCES" },- ),- ],- [- "EPERM writing the scan directory",- Object.assign(- new Error("EPERM: operation not permitted, mkdir '/out/scan'"),- { code: "EPERM" },- ),- ],- [- "output directory rejected",- new OutputDirectoryError(- "Scan output directory must not be accessible to other users (chmod 700): /out",- ),- ],- [- "path target naming a 403 directory",- new InvalidTargetError("Path target does not exist: src/403/client.ts"),- ],- [- "git ref naming a forbidden branch",- new InvalidTargetError("unknown Git ref: origin/forbidden-paths"),- ],+ test("reports saved model and reasoning effort for verbose scan reruns", async () => {+ const stdout = capture();+ const stderr = capture();++ expect(+ await main(+ ["scans", "rerun", "scan-original"],+ stdout.stream,+ stderr.stream,+ dependencies({+ environment: { CODEX_SECURITY_LOG_LEVEL: "debug" },+ onWorkbench: () => ({+ recipe: {+ repository: "/original/repository",+ target: { kind: "repository", paths: [] },+ mode: "standard",+ config: {+ model: "gpt-original",+ model_reasoning_effort: "high",+ },+ },+ }),+ }),+ ),+ ).toBe(0);+ expect(stderr.text()).toContain(+ "codex-security: debug: scan.configuration",+ );+ expect(stderr.text()).toContain('model="gpt-original"');+ expect(stderr.text()).toContain('reasoning_effort="high"');+ });++ test("reports selected profile settings for verbose scan reruns", async () => {+ const stdout = capture();+ const stderr = capture();++ expect(+ await main(+ ["scans", "rerun", "scan-original"],+ stdout.stream,+ stderr.stream,+ dependencies({+ environment: { CODEX_SECURITY_LOG_LEVEL: "debug" },+ onWorkbench: () => ({+ recipe: {+ repository: "/original/repository",+ target: { kind: "repository", paths: [] },+ mode: "standard",+ config: {+ profile: "review",+ model: "gpt-5.6-sol",+ model_reasoning_effort: "low",+ profiles: {+ review: {+ model: "gpt-5.6-terra",+ model_reasoning_effort: "high",+ },+ },+ },+ },+ }),+ }),+ ),+ ).toBe(0);+ const configuration = stderr+ .text()+ .split("\n")+ .find((line) =>+ line.startsWith("codex-security: debug: scan.configuration"),+ );+ expect(configuration).toBeDefined();+ expect(configuration).toContain('profile="review"');+ expect(configuration).toContain('model="gpt-5.6-terra"');+ expect(configuration).toContain('reasoning_effort="high"');+ });++ test("enables verbose diagnostics through CODEX_SECURITY_LOG_LEVEL", async () => {+ const stdout = capture();+ const stderr = capture();++ expect(+ await main(+ ["scan", ".", "--json"],+ stdout.stream,+ stderr.stream,+ dependencies({+ environment: { CODEX_SECURITY_LOG_LEVEL: " DeBuG " },+ }),+ ),+ ).toBe(0);+ expect(JSON.parse(stdout.text())).toEqual(fakeResult().toJSON());+ expect(stderr.text()).toContain(+ "codex-security: debug: scan.configuration",+ );+ expect(stderr.text()).toContain("codex-security: debug: scan.started");+ expect(stderr.text()).toContain("codex-security: debug: scan.completed");+ });++ test("accepts Promptfoo-compatible LOG_LEVEL as a verbose fallback", async () => {+ const stdout = capture();+ const stderr = capture();++ expect(+ await main(+ ["scan", ".", "--json"],+ stdout.stream,+ stderr.stream,+ dependencies({+ environment: {+ CODEX_SECURITY_LOG_LEVEL: " ",+ LOG_LEVEL: " DEBUG ",+ },+ }),+ ),+ ).toBe(0);+ expect(JSON.parse(stdout.text())).toEqual(fakeResult().toJSON());+ expect(stderr.text()).toContain(+ "codex-security: debug: scan.configuration",+ );+ expect(stderr.text()).toContain("codex-security: debug: scan.completed");+ });++ test("prefers CODEX_SECURITY_LOG_LEVEL over a shared LOG_LEVEL", async () => {+ const stdout = capture();+ const stderr = capture();++ expect(+ await main(+ ["scan", ".", "--json"],+ stdout.stream,+ stderr.stream,+ dependencies({+ environment: {+ CODEX_SECURITY_LOG_LEVEL: "info",+ LOG_LEVEL: "debug",+ },+ }),+ ),+ ).toBe(0);+ expect(JSON.parse(stdout.text())).toEqual(fakeResult().toJSON());+ expect(stderr.text()).not.toContain("codex-security: debug:");+ });++ test("lets --verbose override non-debug environment log levels", async () => {+ const stdout = capture();+ const stderr = capture();++ expect(+ await main(+ ["scan", ".", "--verbose", "--json"],+ stdout.stream,+ stderr.stream,+ dependencies({+ environment: {+ CODEX_SECURITY_LOG_LEVEL: "error",+ LOG_LEVEL: "warn",+ },+ }),+ ),+ ).toBe(0);+ expect(JSON.parse(stdout.text())).toEqual(fakeResult().toJSON());+ expect(stderr.text()).toContain(+ "codex-security: debug: scan.configuration",+ );+ expect(stderr.text()).toContain("codex-security: debug: scan.completed");+ });++ test("does not emit verbose diagnostics unless explicitly requested", async () => {+ const stdout = capture();+ const stderr = capture();++ expect(+ await main(+ ["scan", ".", "--json"],+ stdout.stream,+ stderr.stream,+ dependencies(),+ ),+ ).toBe(0);+ expect(JSON.parse(stdout.text())).toEqual(fakeResult().toJSON());+ expect(stderr.text()).not.toContain("codex-security: debug:");+ });++ test("keeps verbose dry-run authentication unverified without starting a scan", async () => {+ const stdout = capture();+ const stderr = capture();+ let scanStarted = false;+ const preflight = {+ ...fakePreflight("."),+ authentication: {+ method: "api_key" as const,+ source: "OPENAI_API_KEY" as const,+ verified: false as const,+ },+ };++ expect(+ await main(+ ["scan", ".", "--dry-run", "--verbose", "--json"],+ stdout.stream,+ stderr.stream,+ dependencies({+ environment: {+ OPENAI_API_KEY: "sk-proj-SYNTHETIC_DRY_RUN_SECRET_123",+ },+ preflight,+ onRun: () => {+ scanStarted = true;+ },+ }),+ ),+ ).toBe(0);+ expect(JSON.parse(stdout.text())).toEqual({ dryRun: true, ...preflight });+ expect(stderr.text()).toContain(+ 'codex-security: debug: scan.preflight.completed model="gpt-5.6-sol" reasoning_effort="xhigh" method="api_key" source="OPENAI_API_KEY" verified=false',+ );+ expect(stderr.text()).not.toContain("codex-security: debug: scan.started");+ expect(stderr.text()).not.toContain("SYNTHETIC_DRY_RUN_SECRET");+ expect(scanStarted).toBe(false);+ });++ test("reports selected profile configuration consistently in verbose dry runs", async () => {+ const scenarios = [+ {+ overrides: [+ 'profile="review"',+ 'model="gpt-5.6-sol"',+ 'model_reasoning_effort="low"',+ 'profiles.review.model="gpt-5.6-terra"',+ 'profiles.review.model_reasoning_effort="high"',+ ],+ model: "gpt-5.6-terra",+ reasoningEffort: "high",+ },+ {+ overrides: [+ 'profile="review"',+ 'model_reasoning_effort="low"',+ 'profiles.review.model="gpt-5.6-terra"',+ ],+ model: "gpt-5.6-terra",+ reasoningEffort: "low",+ },+ {+ overrides: [+ 'profile="review"',+ 'model="gpt-5.6-terra"',+ 'profiles.review.model_reasoning_effort="medium"',+ ],+ model: "gpt-5.6-terra",+ reasoningEffort: "medium",+ },+ ] as const;++ for (const scenario of scenarios) {+ const stdout = capture();+ const stderr = capture();++ expect(+ await main(+ [+ "scan",+ ".",+ "--dry-run",+ "--verbose",+ "--json",+ ...scenario.overrides.flatMap((override) => ["--codex", override]),+ ],+ stdout.stream,+ stderr.stream,+ dependencies(),+ ),+ ).toBe(0);+ expect(JSON.parse(stdout.text())).toEqual({+ dryRun: true,+ ...fakePreflight("."),+ model: scenario.model,+ reasoningEffort: scenario.reasoningEffort,+ });++ for (const event of ["scan.configuration", "scan.preflight.completed"]) {+ const diagnostic = stderr+ .text()+ .split("\n")+ .find((line) => line.startsWith(`codex-security: debug: ${event}`));++ expect(diagnostic).toBeDefined();+ expect(diagnostic).toContain(`model=${JSON.stringify(scenario.model)}`);+ expect(diagnostic).toContain(+ `reasoning_effort=${JSON.stringify(scenario.reasoningEffort)}`,+ );+ }+ }+ });++ test("redacts verbose provider failures and excludes private provider context", async () => {+ const stdout = capture();+ const stderr = capture();+ const deps = dependencies({+ environment: { OPENAI_API_KEY: "sk-proj-SYNTHETIC_VERBOSE_KEY_123" },+ });+ deps.createSecurity = () => ({+ run: async () => {+ throw new CodexSecurityError(+ "401 invalid API key for org-private sk-proj-SYNTHETIC_PROVIDER_SECRET_123",+ );+ },+ preflight: async () => fakePreflight(),+ close: async () => {},+ });++ expect(+ await main(+ ["scan", ".", "--verbose", "--json"],+ stdout.stream,+ stderr.stream,+ deps,+ ),+ ).toBe(2);+ expect(stderr.text()).toContain(+ 'codex-security: debug: scan.failed classification="unauthorized"',+ );+ expect(stderr.text()).toContain("OPENAI_API_KEY");+ expect(stderr.text()).not.toContain("org-private");+ expect(stderr.text()).not.toContain("SYNTHETIC_VERBOSE_KEY");+ expect(stderr.text()).not.toContain("SYNTHETIC_PROVIDER_SECRET");+ });++ test("excludes unclassified provider context from verbose failure diagnostics", async () => {+ const stdout = capture();+ const stderr = capture();+ const deps = dependencies();+ deps.createSecurity = () => ({+ run: async () => {+ throw new CodexSecurityError(+ "Provider failed for tenant=tenant-private request_id=req-internal",+ );+ },+ preflight: async () => fakePreflight(),+ close: async () => {},+ });++ expect(+ await main(+ ["scan", ".", "--verbose", "--json"],+ stdout.stream,+ stderr.stream,+ deps,+ ),+ ).toBe(2);++ const failureDiagnostic = stderr+ .text()+ .split("\n")+ .find((line) => line.startsWith("codex-security: debug: scan.failed"));++ expect(failureDiagnostic).toBeDefined();+ expect(failureDiagnostic).toContain('classification="unknown"');+ expect(failureDiagnostic).toContain("partial_output=false");+ expect(failureDiagnostic).not.toContain("tenant-private");+ expect(failureDiagnostic).not.toContain("req-internal");+ expect(stderr.text()).toContain("Provider failed for");+ expect(stderr.text()).not.toContain("tenant-private");+ expect(stderr.text()).not.toContain("req-internal");+ expect(stdout.text()).toBe("");+ });++ test("redacts provider identifier variants in scan failures", async () => {+ const cases = [+ {+ message:+ "Provider failed for TENANT_ID=tenant-private ORGANIZATION_ID=organization-private ORG_ID=org-private PROJECT_ID=project-private project-id=project-hyphen-private",+ identifiers: [+ "tenant-private",+ "organization-private",+ "org-private",+ "project-private",+ "project-hyphen-private",+ ],+ },+ {+ message:+ "Provider failed for x-request-id:req-private Trace-ID=trace-private correlationId=correlation-private",+ identifiers: ["req-private", "trace-private", "correlation-private"],+ },+ {+ message:+ 'Provider failed for {"tenant":"tenant private","organizationId":"organization private","projectId":"project private","requestId":"request private","traceId":"trace private"}',+ identifiers: [+ "tenant private",+ "organization private",+ "project private",+ "request private",+ "trace private",+ ],+ },+ {+ message: `Provider failed for ${JSON.stringify({+ payload: JSON.stringify({+ tenant: 'tenant-"private" suffix',+ organizationId: "org-private",+ projectId: "project-private",+ requestId: "req-private",+ traceId: "trace-private",+ correlationId: "correlation-private",+ }),+ })}`,+ identifiers: [+ "tenant-",+ "private",+ "suffix",+ "org-private",+ "project-private",+ "req-private",+ "trace-private",+ "correlation-private",+ ],+ },+ {+ message: `Provider failed for ${JSON.stringify({+ payload: JSON.stringify({+ nested: JSON.stringify({+ tenant: "tenant-private",+ requestId: "req-private",+ }),+ }),+ })}`,+ identifiers: ["tenant-private", "req-private"],+ },+ {+ message:+ "Provider failed for https://api.example.test?tenant=tenant-private&project=project-private&request_id=req-private",+ identifiers: ["tenant-private", "project-private", "req-private"],+ },+ ];++ for (const { message, identifiers } of cases) {+ for (const verbose of [false, true]) {+ const stdout = capture();+ const stderr = capture();+ const deps = dependencies();+ deps.createSecurity = () => ({+ run: async () => {+ throw new CodexSecurityError(message);+ },+ preflight: async () => fakePreflight(),+ close: async () => {},+ });++ expect(+ await main(+ ["scan", ".", "--json", ...(verbose ? ["--verbose"] : [])],+ stdout.stream,+ stderr.stream,+ deps,+ ),+ ).toBe(2);+ expect(stdout.text()).toBe("");+ expect(stderr.text()).toContain("Provider failed for");+ expect(stderr.text()).toContain("[redacted]");+ for (const identifier of identifiers) {+ expect(stderr.text()).not.toContain(identifier);+ }+ }+ }+ });++ test("redacts provider identifiers from scanner warnings", async () => {+ for (const verbose of [false, true]) {+ const stdout = capture();+ const stderr = capture();+ const deps = dependencies();+ deps.createSecurity = () => ({+ run: async (_repository, options) => {+ options?.onWarning?.(+ 'Provider warning {"organizationId":"organization private","requestId":"request private"} tenant=tenant-private',+ );+ options?.onWarning?.(+ `Provider warning ${JSON.stringify({+ payload: JSON.stringify({+ organizationId: "organization private",+ requestId: "request private",+ }),+ })}`,+ );+ return fakeResult();+ },+ preflight: async () => fakePreflight(),+ close: async () => {},+ });++ expect(+ await main(+ ["scan", ".", "--json", ...(verbose ? ["--verbose"] : [])],+ stdout.stream,+ stderr.stream,+ deps,+ ),+ ).toBe(0);+ expect(JSON.parse(stdout.text())).toEqual(fakeResult().toJSON());+ expect(stderr.text()).toContain(+ "codex-security: warning: Provider warning",+ );+ expect(stderr.text()).toContain("[redacted]");+ expect(stderr.text()).not.toContain("organization private");+ expect(stderr.text()).not.toContain("request private");+ expect(stderr.text()).not.toContain("tenant-private");+ }+ });++ test("prevents Unicode line separators from forging verbose diagnostics", async () => {+ const stdout = capture();+ const stderr = capture();+ const deps = dependencies();+ const separators = "\u0085\u2028\u2029";+ deps.createSecurity = () => ({+ run: async (_repository, options) => {+ options?.onOutputDirReady?.(+ `/tmp/scan${separators}codex-security: debug: forged`,+ );+ options?.onWarning?.(+ `Scanner warning${separators}codex-security: debug: forged`,+ );+ return fakeResult();+ },+ preflight: async () => fakePreflight(),+ close: async () => {},+ });++ expect(+ await main(+ ["scan", ".", "--verbose", "--json"],+ stdout.stream,+ stderr.stream,+ deps,+ ),+ ).toBe(0);+ expect(JSON.parse(stdout.text())).toEqual(fakeResult().toJSON());+ expect(stderr.text()).not.toMatch(/[\u0085\u2028\u2029]/u);++ const diagnostics = stderr+ .text()+ .split("\n")+ .filter((line) => line.startsWith("codex-security: debug:"));++ expect(diagnostics.some((line) => line.includes("scan.output_ready"))).toBe(+ true,+ );+ expect(diagnostics.some((line) => line.includes("scan.warning"))).toBe(+ true,+ );+ for (const diagnostic of diagnostics) {+ expect(diagnostic).not.toMatch(/[\u0085\u2028\u2029]/u);+ expect(diagnostic).not.toMatch(/^codex-security: debug: forged$/u);+ }+ });++ test("redacts verbose output paths and observer diagnostics", async () => {+ const stdout = capture();+ const stderr = capture();+ const deps = dependencies();+ deps.createSecurity = () => ({+ run: async (_repository, options) => {+ options?.onOutputArchived?.(+ "/tmp/archive_sk-proj-SYNTHETIC_ARCHIVE_SECRET_123",+ );+ options?.onOutputDirReady?.(+ "/tmp/scan_sk-proj-SYNTHETIC_OUTPUT_SECRET_123",+ );+ options?.onObserverError?.(+ "onWorkerStatus",+ new Error(`observer failed ${SYNTHETIC_CREDENTIALS}`),+ );+ return fakeResult();+ },+ preflight: async () => fakePreflight(),+ close: async () => {},+ });++ expect(+ await main(+ ["scan", ".", "--verbose", "--json"],+ stdout.stream,+ stderr.stream,+ deps,+ ),+ ).toBe(0);+ expect(JSON.parse(stdout.text())).toEqual(fakeResult().toJSON());+ expect(stderr.text()).toContain(+ 'codex-security: debug: scan.output_archived archive_dir="/tmp/archive_[redacted]"',+ );+ expect(stderr.text()).toContain(+ 'codex-security: debug: scan.output_ready scan_dir="/tmp/scan_[redacted]"',+ );+ expect(stderr.text()).toContain(+ 'codex-security: debug: scan.observer_failed observer="onWorkerStatus"',+ );+ expect(stderr.text()).toContain("[redacted]");+ expect(stderr.text()).not.toContain("SYNTHETIC");+ });++ test("excludes observer failure context from verbose diagnostics", async () => {+ const stdout = capture();+ const stderr = capture();+ const deps = dependencies();+ deps.createSecurity = () => ({+ run: async (_repository, options) => {+ options?.onObserverError?.(+ "onWorkerStatus",+ new Error(+ "Observer failed for tenant=tenant-private request_id=req-internal",+ ),+ );+ return fakeResult();+ },+ preflight: async () => fakePreflight(),+ close: async () => {},+ });++ expect(+ await main(+ ["scan", ".", "--verbose", "--json"],+ stdout.stream,+ stderr.stream,+ deps,+ ),+ ).toBe(0);+ expect(JSON.parse(stdout.text())).toEqual(fakeResult().toJSON());++ const observerDiagnostic = stderr+ .text()+ .split("\n")+ .find((line) =>+ line.startsWith("codex-security: debug: scan.observer_failed"),+ );++ expect(observerDiagnostic).toBeDefined();+ expect(observerDiagnostic).toContain('observer="onWorkerStatus"');+ expect(observerDiagnostic).toContain('classification="unknown"');+ expect(observerDiagnostic).not.toContain("tenant-private");+ expect(observerDiagnostic).not.toContain("req-internal");+ expect(stderr.text()).toContain("Observer failed for");+ expect(stderr.text()).not.toContain("tenant-private");+ expect(stderr.text()).not.toContain("req-internal");+ });++ test("excludes cleanup failure context from verbose diagnostics", async () => {+ const stdout = capture();+ const stderr = capture();++ expect(+ await main(+ ["scan", ".", "--verbose", "--json"],+ stdout.stream,+ stderr.stream,+ dependencies({+ onClose: () => {+ throw new Error(+ "Cleanup failed for tenant=tenant-private request_id=req-internal",+ );+ },+ }),+ ),+ ).toBe(2);++ for (const event of ["runtime.cleanup.failed", "scan.failed"]) {+ const diagnostic = stderr+ .text()+ .split("\n")+ .find((line) => line.startsWith(`codex-security: debug: ${event}`));++ expect(diagnostic).toBeDefined();+ expect(diagnostic).toContain('classification="unknown"');+ expect(diagnostic).not.toContain("tenant-private");+ expect(diagnostic).not.toContain("req-internal");+ }++ expect(stderr.text()).toContain("Cleanup failed for");+ expect(stderr.text()).not.toContain("tenant-private");+ expect(stderr.text()).not.toContain("req-internal");+ expect(stdout.text()).toBe("");+ });++ test("reports reconnect progress on stderr and keeps JSON output clean", async () => {+ const stdout = capture();+ const stderr = capture();+ const deps = dependencies();+ deps.createSecurity = () => ({+ run: async (_repository, options) => {+ const callbacks = options as {+ onScanStarted?: () => void;+ onReconnect?: (attempt: number, maxAttempts: number) => void;+ };+ callbacks.onScanStarted?.();+ callbacks.onReconnect?.(2, 5);+ return fakeResult();+ },+ preflight: async () => fakePreflight(),+ close: async () => {},+ });++ expect(+ await main(["scan", "--json"], stdout.stream, stderr.stream, deps),+ ).toBe(0);+ expect(JSON.parse(stdout.text())).toEqual(fakeResult().toJSON());+ expect(stderr.text()).toContain(+ "Codex connection interrupted; retrying (2/5)",+ );+ expect(stderr.text()).toContain("Running scan");+ });++ test("renders bounded rate-limit retry details without leaking provider context", async () => {+ const stdout = capture();+ const stderr = capture();+ const deps = dependencies();+ deps.createSecurity = () => ({+ run: async (_repository, options) => {+ options?.onScanStarted?.();+ options?.onReconnect?.(2, 5, {+ reason: "rate_limit",+ retryAfterSeconds: 1.2,+ });+ options?.onReconnect?.(3, 5, { reason: "rate_limit" });+ return fakeResult();+ },+ preflight: async () => fakePreflight(),+ close: async () => {},+ });++ expect(+ await main(["scan", "--json"], stdout.stream, stderr.stream, deps),+ ).toBe(0);+ expect(JSON.parse(stdout.text())).toEqual(fakeResult().toJSON());+ expect(stderr.text()).toContain(+ "Rate limit reached; retrying in 1.2s (2/5).",+ );+ expect(stderr.text()).toContain("Rate limit reached; retrying (3/5).");+ });++ test("renders safe reconnect causes without forwarding provider messages", async () => {+ const stdout = capture();+ const stderr = capture();+ const deps = dependencies();+ deps.createSecurity = () => ({+ run: async (_repository, options) => {+ options?.onReconnect?.(1, 5, { reason: "network" });+ options?.onReconnect?.(2, 5, { reason: "authentication" });+ options?.onReconnect?.(3, 5, { reason: "authorization" });+ return fakeResult();+ },+ preflight: async () => fakePreflight(),+ close: async () => {},+ });++ expect(+ await main(["scan", "--json"], stdout.stream, stderr.stream, deps),+ ).toBe(0);+ expect(stderr.text()).toContain("Network connection interrupted; retrying");+ expect(stderr.text()).toContain("Authentication interrupted; retrying");+ expect(stderr.text()).toContain("Model access interrupted; retrying");+ expect(JSON.parse(stdout.text())).toEqual(fakeResult().toJSON());+ });++ test("turns authentication and rate-limit failures into actionable safe messages", async () => {+ for (const [message, expected] of [+ ["401 invalid API key for org-private", "provide a valid API key"],+ ["403 model access denied for org-private", "model access"],+ ["429 rate limit reached for org-private", "rate limit"],+ ] as const) {+ const stdout = capture();+ const stderr = capture();+ const deps = dependencies();+ deps.createSecurity = () => ({+ run: async () => {+ throw new CodexSecurityError(message);+ },+ preflight: async () => fakePreflight(),+ close: async () => {},+ });++ expect(await main(["scan"], stdout.stream, stderr.stream, deps)).toBe(2);+ expect(stderr.text()).toContain(expected);+ expect(stderr.text()).not.toContain("org-private");+ }+ });++ test("surfaces underlying scanner errors instead of inventing a model outage", async () => {+ for (const message of [+ "Could not save the Codex Security scan: UNIQUE constraint failed: scans.scan_dir",+ "sandbox-exec: sandbox_apply: Operation not permitted during network setup.",+ "network failure ECONNRESET while connecting to the model.",+ "request timed out while reading the scanner response.",+ "Local scan failed: project_directory=/tmp/project tenant_count=2 request_index=3.",+ ]) {+ const stdout = capture();+ const stderr = capture();+ const deps = dependencies();+ deps.createSecurity = () => ({+ run: async () => {+ throw new CodexSecurityError(message);+ },+ preflight: async () => fakePreflight(),+ close: async () => {},+ });++ expect(+ await main(["scan", ".", "--json"], stdout.stream, stderr.stream, deps),+ ).toBe(2);+ expect(stdout.text()).toBe("");+ expect(stderr.text()).toContain(`${message}\n`);+ expect(stderr.text()).not.toContain("codex-security:");+ expect(stderr.text()).not.toContain("model service could not be reached");+ }+ });++ test("reports local input and filesystem failures without connectivity advice", async () => {+ // https://github.com/openai/codex-security/issues/36 -- classification+ // matches bare words such as "permission denied" anywhere in the message,+ // so local failures were reported as credential or connectivity problems+ // and their own text was discarded.+ const failures: Array<[string, unknown]> = [+ [+ "EACCES from a read-only TMPDIR",+ Object.assign(+ new Error(+ "EACCES: permission denied, mkdtemp '/tmp/openai-codex-security-home-XXXXXX'",+ ),+ { code: "EACCES" },+ ),+ ],+ [+ "EPERM writing the scan directory",+ Object.assign(+ new Error("EPERM: operation not permitted, mkdir '/out/scan'"),+ { code: "EPERM" },+ ),+ ],+ [+ "output directory rejected",+ new OutputDirectoryError(+ "Scan output directory must not be accessible to other users (chmod 700): /out",+ ),+ ],+ [+ "path target naming a 403 directory",+ new InvalidTargetError("Path target does not exist: src/403/client.ts"),+ ],+ [+ "git ref naming a forbidden branch",+ new InvalidTargetError("unknown Git ref: origin/forbidden-paths"),+ ],["python interpreter unavailable",new PluginPythonUnavailableError(@@ -2161,9 +3158,15 @@ describe("CLI", () => {});expect(- await main(["scan", "."], stdout.stream, stderr.stream, deps),+ await main(+ ["scan", ".", "--verbose"],+ stdout.stream,+ stderr.stream,+ deps,+ ),).toBe(2);expect(stderr.text()).toContain((failure as Error).message);+ expect(stderr.text()).toContain('scan.failed classification="local"');expect(stderr.text()).not.toContain("cannot access the configured model");expect(stderr.text()).not.toContain("Authentication failed");expect(stderr.text()).not.toContain("reached its rate limit");@@ -2487,6 +3490,39 @@ describe("CLI", () => {);});+ test("emits redacted scan warnings in verbose diagnostics", async () => {+ const stdout = capture();+ const stderr = capture();+ const deps = dependencies();+ deps.createSecurity = () => ({+ run: async (_repository, options) => {+ options?.onWarning?.(+ "Repository HEAD changed during the scan: sk-proj-SYNTHETIC_WARNING_SECRET_123",+ );+ return fakeResult();+ },+ close: async () => {},+ preflight: async () => fakePreflight(),+ });++ expect(+ await main(+ ["scan", ".", "--verbose", "--json"],+ stdout.stream,+ stderr.stream,+ deps,+ ),+ ).toBe(0);+ expect(JSON.parse(stdout.text())).toEqual(fakeResult().toJSON());+ expect(stderr.text()).toContain(+ 'codex-security: debug: scan.warning message="Repository HEAD changed during the scan: [redacted]"',+ );+ expect(stderr.text()).toContain(+ "codex-security: warning: Repository HEAD changed during the scan: [redacted]",+ );+ expect(stderr.text()).not.toContain("SYNTHETIC_WARNING_SECRET");+ });+test("reports isolated observer failures without failing the scan", async () => {const stdout = capture();const stderr = capture();@@ -2665,6 +3701,30 @@ describe("CLI", () => {expect(stderr.text()).toContain("Estimated cost: $0.00625 of $0.01 limit");});+ test("includes cache-write tokens in verbose cost diagnostics", async () => {+ const stdout = capture();+ const stderr = capture();+ const result = fakeResult([], "complete", {+ input_tokens: 200,+ cache_write_input_tokens: 200,+ output_tokens: 0,+ });++ expect(result.cost?.cacheWriteInputTokens).toBe(200);+ expect(result.cost?.estimatedUsd).toBeGreaterThan(0);+ expect(+ await main(+ ["scan", ".", "--verbose", "--json"],+ stdout.stream,+ stderr.stream,+ dependencies({ result, costUpdates: [result.cost!] }),+ ),+ ).toBe(0);+ expect(JSON.parse(stdout.text())).toEqual(result.toJSON());+ expect(stderr.text()).toContain("codex-security: debug: cost.updated");+ expect(stderr.text()).toContain("cache_write_input_tokens=200");+ });+test("reports a scan stopped when its live cost exceeds the limit", async () => {const stdout = capture();const stderr = capture();diff --git a/sdk/typescript/tests-ts/config.test.ts b/sdk/typescript/tests-ts/config.test.tsindex a03839f3f..8ab37563c 100644--- a/sdk/typescript/tests-ts/config.test.ts+++ b/sdk/typescript/tests-ts/config.test.ts@@ -4,6 +4,7 @@ import { join } from "node:path";import { afterEach, describe, expect, test } from "bun:test";import { parse } from "smol-toml";import { scanRuntimeCodexConfig } from "../src/api.js";+import { scanModelConfiguration } from "../src/config.js";import {ConfigurationError,DEFAULT_CODEX_CONFIG,@@ -69,6 +70,85 @@ describe("Codex configuration", () => {);});+ test("resolves selected profile model and effort before root settings", async () => {+ const scenarios = [+ {+ overrides: {+ profile: "review",+ model: "gpt-5.6-sol",+ model_reasoning_effort: "low",+ profiles: {+ review: {+ model: "gpt-5.6-terra",+ model_reasoning_effort: "high",+ },+ },+ },+ expected: { model: "gpt-5.6-terra", reasoningEffort: "high" },+ },+ {+ overrides: {+ profile: "review",+ model_reasoning_effort: "low",+ profiles: { review: { model: "gpt-5.6-terra" } },+ },+ expected: { model: "gpt-5.6-terra", reasoningEffort: "low" },+ },+ {+ overrides: {+ profile: "review",+ model: "gpt-5.6-terra",+ profiles: { review: { model_reasoning_effort: "medium" } },+ },+ expected: { model: "gpt-5.6-terra", reasoningEffort: "medium" },+ },+ ] as const;++ for (const scenario of scenarios) {+ const config = await mergedCodexConfig({+ codexOverrides: scenario.overrides,+ });+ expect(scanModelConfiguration(config)).toEqual(scenario.expected);+ }+ });++ test("ignores model overrides from unselected Codex profiles", async () => {+ const config = await mergedCodexConfig({+ codexOverrides: {+ profile: "missing",+ model: "gpt-5.6-sol",+ model_reasoning_effort: "low",+ profiles: {+ other: {+ model: "gpt-5.6-terra",+ model_reasoning_effort: "high",+ },+ },+ },+ });++ expect(scanModelConfiguration(config)).toEqual({+ model: "gpt-5.6-sol",+ reasoningEffort: "low",+ });+ });++ test("rejects invalid model settings from the selected Codex profile", async () => {+ for (const [profile, message] of [+ [{ model: " " }, "model must be a nonempty string"],+ [+ { model_reasoning_effort: " " },+ "reasoning effort must be a nonempty string",+ ],+ ] as const) {+ const config = await mergedCodexConfig({+ codexOverrides: { profile: "review", profiles: { review: profile } },+ });++ expect(() => scanModelConfiguration(config)).toThrow(message);+ }+ });+test("deep-merges native multi-agent v2 defaults", async () => {const merged = await mergedCodexConfig({codexOverrides: {