OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security
TypeScript ai-securityapplication-securityclicode-scanningcodexcodex-securitycybersecuritydevsecopsnodejsnpmopenaisdksecuritytypescriptvulnerability-scanning
fix(runtime): support reviewed scan approval defaults (#441)
mldangelo-oai55f8c87963f9
diff --git a/SECURITY.md b/SECURITY.mdindex 38507a8ea..98b0de437 100644--- a/SECURITY.md+++ b/SECURITY.md@@ -70,14 +70,18 @@ incomplete coverage.### How scans runEach scan uses the product's `codex_security_scan` filesystem profile and-`approvalPolicy: "never"`. The scan does not request interactive approval or-grant filesystem escalations. Its profile allows reads of the local filesystem-and writes to workspace roots and the selected scan state directory.+automatic approval review. Its baseline profile allows reads of the local+filesystem and writes to workspace roots and the selected scan state directory.+Requests are reviewed automatically without an interactive prompt; approved+requests can grant additional permissions for a specific operation. Set+`approval_policy="never"` to deny all requests instead.Setting `approval_policy`, `approvals_reviewer`, `sandbox_mode`, or permissions-through `--codex` or SDK `codexOverrides` does not replace the scan's approval-policy or make its filesystem profile more restrictive. Separately enforced-host and network restrictions still apply.+through `--codex` or SDK `codexOverrides` cannot replace the automatic reviewer+or baseline filesystem profile. A strict `approval_policy="never"` override,+including one in the selected profile, is preserved. Saved scans retain their+effective approval policy, and older scans remain deny-all when rerun.+Separately enforced host and network restrictions still apply.Scan and workbench subprocesses can inherit your environment. The workbenchremoves `OPENAI_API_KEY` and `CODEX_API_KEY`, but it does not remove everydiff --git a/sdk/typescript/README.md b/sdk/typescript/README.mdindex 1c6b4bf66..459a38b54 100644--- a/sdk/typescript/README.md+++ b/sdk/typescript/README.md@@ -343,7 +343,8 @@ configuration. Each scan starts with a private runtime and these Codexdefaults:```toml-approval_policy = "never"+approval_policy = "on-request"+approvals_reviewer = "auto_review"cli_auth_credentials_store = "auto"model = "gpt-5.6-sol"model_reasoning_effort = "xhigh"@@ -393,8 +394,10 @@ and `features.multi_agent_v2.enabled=false` are incompatible and rejected.`model_reasoning_effort` `--codex` keys; they do not accept general scanruntime overrides.-These overrides do not change the scan's approval policy or filesystem-permissions. See [Local security model](#local-security-model).+These overrides cannot replace the scanner-owned approval reviewer or+filesystem profile. Use `--codex 'approval_policy="never"'` to deny approval+requests instead of reviewing them automatically. See+[Local security model](#local-security-model).### Deep-scan engine configuration@@ -828,13 +831,16 @@ repository, Git installation, configured tools, and other scans under thesame account are not separate security principals.Every scan uses the `codex_security_scan` filesystem profile and-`approvalPolicy: "never"`. Its profile allows reads of the local filesystem and-writes to workspace roots and the selected scan state directory. Scans do not-request interactive approval or grant filesystem escalations. Setting-`approval_policy`, `approvals_reviewer`, `sandbox_mode`, or permissions-through `--codex` or SDK `codexOverrides` does not replace these controls or-make the filesystem profile more restrictive. Independently enforced host and-network restrictions still apply.+automatically reviewed execution approvals. Its baseline profile allows reads+of the local filesystem and writes to workspace roots and the selected scan+state directory. Approval requests are reviewed without an interactive prompt;+approved requests can grant additional permissions for a specific operation.+Use `--codex 'approval_policy="never"'` or a selected profile with that policy+to deny all requests instead. Other `approval_policy`, `approvals_reviewer`,+`sandbox_mode`, or permission overrides cannot replace the reviewer or baseline+filesystem profile. Saved scans retain their effective approval policy; older+saved scans remain deny-all when rerun. Independently enforced host and network+restrictions still apply.Scan and workbench subprocesses can inherit your environment, includingunrelated API tokens and cloud credentials. Start a scan with only thediff --git a/sdk/typescript/src/api.ts b/sdk/typescript/src/api.tsindex fd60107e5..a826fafbc 100644--- a/sdk/typescript/src/api.ts+++ b/sdk/typescript/src/api.ts@@ -30,6 +30,7 @@ import {EXTERNAL_CODEX_PROVIDERS,isExternalModelProvider,mergedCodexConfig,+ scanApprovalPolicy,scanModelConfiguration,scanModelProvider,type CodexSecurityConfig,@@ -136,7 +137,7 @@ interface CodexClientLike {startThread(options: {workingDirectory: string;skipGitRepoCheck: boolean;- approvalPolicy: "never";+ approvalPolicy: "never" | "on-request";}): CodexThreadLike;}@@ -535,6 +536,7 @@ export class CodexSecurity {);}const effectiveConfig = runtime.effectiveConfig ?? requestedConfig;+ const approvalPolicy = scanApprovalPolicy(effectiveConfig);const preflightConfig = scanPreflightCodexConfig(effectiveConfig);if (runtime.configPath !== undefined) {await writeCodexConfig(runtime.configPath, preflightConfig);@@ -802,7 +804,7 @@ export class CodexSecurity {mode,expectation.repositoryRevision,runtime.plugin.version,- preflightConfig,+ { ...preflightConfig, approval_policy: approvalPolicy },options.failureSeverity,knowledgeBase?.sources,options.maxCostUsd,@@ -1047,6 +1049,7 @@ export class CodexSecurity {),config: {...(sdkCodexConfig as NonNullable<CodexOptions["config"]>),+ approvals_reviewer: "auto_review",default_permissions: SCAN_PERMISSION_PROFILE,allow_login_shell: false,responses_api_metadata: {@@ -1058,7 +1061,7 @@ export class CodexSecurity {const thread = codex.startThread({workingDirectory: scanDir,skipGitRepoCheck: true,- approvalPolicy: "never",+ approvalPolicy,});const serializedPaths =normalized.kind === "paths"@@ -2836,6 +2839,7 @@ export function scanRuntimeCodexConfig(stateDirectory: string,protectedCredentialHome?: string,): JsonObject {+ const approvalPolicy = scanApprovalPolicy(config);const hardened = structuredClone(config);delete hardened["sandbox_mode"];delete hardened["approvals_reviewer"];@@ -2855,7 +2859,8 @@ export function scanRuntimeCodexConfig(: {};return {...hardened,- approval_policy: "never",+ approval_policy: approvalPolicy,+ approvals_reviewer: "auto_review",allow_login_shell: false,default_permissions: SCAN_PERMISSION_PROFILE,permissions: {@@ -2880,6 +2885,7 @@ function sharedCredentialCodexConfig(credentialHome: string,): JsonObject {const shared: JsonObject = {+ approval_policy: scanApprovalPolicy(config),features: { plugins: true },};for (const key of [diff --git a/sdk/typescript/src/cli.ts b/sdk/typescript/src/cli.tsindex 57e06a7ec..d660551a6 100644--- a/sdk/typescript/src/cli.ts+++ b/sdk/typescript/src/cli.ts@@ -2837,7 +2837,9 @@ function scanArgumentsFromRecipe(...deepScan.data,archiveExisting: false,codex: [],- codexOverrides: config,+ codexOverrides: Object.hasOwn(config, "approval_policy")+ ? config+ : { ...config, approval_policy: "never" },failOnSeverity: threshold as FailureSeverity | undefined,maxCostUsd,dryRun: false,diff --git a/sdk/typescript/src/config.ts b/sdk/typescript/src/config.tsindex acc98ac2e..27cbddd1b 100644--- a/sdk/typescript/src/config.ts+++ b/sdk/typescript/src/config.ts@@ -52,7 +52,8 @@ export function isExternalModelProvider(}export const DEFAULT_CODEX_CONFIG: Readonly<JsonObject> = {- approval_policy: "never",+ approval_policy: "on-request",+ approvals_reviewer: "auto_review",cli_auth_credentials_store: "auto",model: "gpt-5.6-sol",model_reasoning_effort: "xhigh",@@ -111,6 +112,15 @@ export function scanModelProvider(config: Readonly<JsonObject>): unknown {: config["model_provider"];}+export function scanApprovalPolicy(+ config: Readonly<JsonObject>,+): "never" | "on-request" {+ return config["approval_policy"] === "never" ||+ selectedScanProfile(config)?.["approval_policy"] === "never"+ ? "never"+ : "on-request";+}+function selectedScanProfile(config: Readonly<JsonObject>,): Record<string, JsonValue> | undefined {diff --git a/sdk/typescript/tests-ts/api-preflight-config.test.ts b/sdk/typescript/tests-ts/api-preflight-config.test.tsindex 4629d5321..c4cc0bbfd 100644--- a/sdk/typescript/tests-ts/api-preflight-config.test.ts+++ b/sdk/typescript/tests-ts/api-preflight-config.test.ts@@ -312,7 +312,7 @@ describe("CodexSecurity preflight configuration", () => {const stateDirectory = join(tmpdir(), "codex-security-persistent-state");const original = {approval_policy: "on-request",- approvals_reviewer: "auto_review",+ approvals_reviewer: "user",sandbox_mode: "workspace-write",allow_login_shell: true,default_permissions: "unsafe",@@ -326,7 +326,8 @@ describe("CodexSecurity preflight configuration", () => {};expect(scanRuntimeCodexConfig(original, stateDirectory)).toEqual({- approval_policy: "never",+ approval_policy: "on-request",+ approvals_reviewer: "auto_review",allow_login_shell: false,default_permissions: "codex_security_scan",permissions: {@@ -342,7 +343,7 @@ describe("CodexSecurity preflight configuration", () => {});expect(original).toMatchObject({approval_policy: "on-request",- approvals_reviewer: "auto_review",+ approvals_reviewer: "user",sandbox_mode: "workspace-write",allow_login_shell: true,default_permissions: "unsafe",@@ -368,6 +369,40 @@ describe("CodexSecurity preflight configuration", () => {});});+ test("preserves an explicitly requested strict approval policy", () => {+ const stateDirectory = join(tmpdir(), "codex-security-persistent-state");++ expect(+ scanRuntimeCodexConfig(+ { approval_policy: "never", approvals_reviewer: "user" },+ stateDirectory,+ ),+ ).toMatchObject({+ approval_policy: "never",+ approvals_reviewer: "auto_review",+ default_permissions: "codex_security_scan",+ });+ });++ test("preserves a strict approval policy from the selected profile", () => {+ const stateDirectory = join(tmpdir(), "codex-security-persistent-state");+ const config = {+ approval_policy: "on-request",+ profile: "strict",+ profiles: {+ strict: { approval_policy: "never", model: "profile-model" },+ other: { approval_policy: "on-request" },+ },+ };++ expect(scanRuntimeCodexConfig(config, stateDirectory)).toMatchObject({+ approval_policy: "never",+ approvals_reviewer: "auto_review",+ profiles: { strict: { model: "profile-model" }, other: {} },+ });+ expect(config.profiles.strict.approval_policy).toBe("never");+ });+test("removes execution and permission overrides from every configured profile", () => {const stateDirectory = join(tmpdir(), "codex-security-persistent-state");const original = {@@ -394,7 +429,8 @@ describe("CodexSecurity preflight configuration", () => {const hardened = scanRuntimeCodexConfig(original, stateDirectory);expect(hardened).toMatchObject({- approval_policy: "never",+ approval_policy: "on-request",+ approvals_reviewer: "auto_review",default_permissions: "codex_security_scan",profile: "selected",});diff --git a/sdk/typescript/tests-ts/api.test.ts b/sdk/typescript/tests-ts/api.test.tsindex a8d6233c0..37896482a 100644--- a/sdk/typescript/tests-ts/api.test.ts+++ b/sdk/typescript/tests-ts/api.test.ts@@ -294,6 +294,65 @@ describe("CodexSecurity orchestration", () => {);});+ test.each([+ ["root configuration", { approval_policy: "never" }],+ [+ "selected profile",+ {+ approval_policy: "on-request",+ profile: "strict",+ profiles: {+ strict: { approval_policy: "never", model: "profile-model" },+ },+ },+ ],+ ] as const)(+ "preserves strict approvals from %s in scan threads and saved recipes",+ async (_source, codexOverrides) => {+ const root = await temporaryDirectory();+ const repository = join(root, "repository");+ const codexHome = join(root, "codex-home");+ await Promise.all([mkdir(repository), mkdir(codexHome)]);+ let threadOptions: Record<string, unknown> | undefined;+ let recipe: Record<string, unknown> | undefined;+ const client = new TestClient(+ { codexOverrides },+ {+ environment: {},+ prepareRuntime: async () => preparedRuntime(codexHome),+ resolvePluginPython: async () => "/managed/python",+ repositoryRevision: async () => null,+ runWorkbench: async (_options: unknown, args: readonly string[]) => {+ if (args[0] === "register-cli-scan") {+ recipe = JSON.parse(args[args.indexOf("--recipe-json") + 1]!);+ }+ return mockWorkbench(args);+ },+ createCodex: () => ({+ startThread: (options: Record<string, unknown>) => {+ threadOptions = options;+ return {+ id: null,+ async runStreamed() {+ throw new Error("scan approval policy captured");+ },+ };+ },+ }),+ },+ );++ await expect(+ client.run(repository, { outputDir: join(root, "scan") }),+ ).rejects.toThrow("scan approval policy captured");+ expect(threadOptions).toMatchObject({ approvalPolicy: "never" });+ expect(recipe).toMatchObject({+ config: { approval_policy: "never" },+ });+ await client.close();+ },+ );+test("selects a real-scan target in the active repository layout", async () => {await expect(stat(join(REPOSITORY_ROOT, INTEGRATION_TARGET)),@@ -1905,16 +1964,14 @@ describe("CodexSecurity orchestration", () => {"CODEX_SECURITY_TARGET_SNAPSHOT_DIGEST",);expect((codexOptions as CodexOptions | null)?.config).toMatchObject({+ approvals_reviewer: "auto_review",default_permissions: "codex_security_scan",allow_login_shell: false,});- expect((codexOptions as CodexOptions | null)?.config).not.toHaveProperty(- "approvals_reviewer",- );expect(threadOptions as Record<string, unknown> | null).toEqual({workingDirectory: scanDir,skipGitRepoCheck: true,- approvalPolicy: "never",+ approvalPolicy: "on-request",});expect((codexOptions as CodexOptions | null)?.apiKey).toBeUndefined();expect((codexOptions as CodexOptions | null)?.env).not.toHaveProperty(@@ -1975,7 +2032,7 @@ describe("CodexSecurity orchestration", () => {mode: "standard",repositoryRevision: "deadbeef",pluginVersion: "0.1.0",- config: { model: "replay-model" },+ config: { approval_policy: "on-request", model: "replay-model" },});expect(commands[1]).toEqual(["get-scan-feedback",@@ -4035,6 +4092,7 @@ describe("CodexSecurity orchestration", () => {{pluginPath: PLUGIN_ROOT,codexOverrides: {+ approval_policy: "never",features: { goals: true },projects: {...unrelatedProjects,@@ -4075,6 +4133,7 @@ describe("CodexSecurity orchestration", () => {await readFile(join(codexHome!, "config.toml"), "utf8"),),).toMatchObject({+ approval_policy: "never",permissions: {codex_security_scan: {filesystem: {diff --git a/sdk/typescript/tests-ts/cli-workbench.test.ts b/sdk/typescript/tests-ts/cli-workbench.test.tsindex 591630e7a..ef869db2e 100644--- a/sdk/typescript/tests-ts/cli-workbench.test.ts+++ b/sdk/typescript/tests-ts/cli-workbench.test.ts@@ -809,6 +809,7 @@ describe("CLI workbench", () => {let repository: string | undefined;let options: Record<string, unknown> | undefined;const savedConfig = {+ approval_policy: "on-request",model: "gpt-original",model_reasoning_effort: "high",features: { goals: true },@@ -908,6 +909,48 @@ describe("CLI workbench", () => {}});+ test.each([+ ["legacy", undefined, "never"],+ ["strict", "never", "never"],+ ["reviewed", "on-request", "on-request"],+ ] as const)(+ "preserves %s scan approval policy when rerunning saved scans",+ async (_scenario, savedApprovalPolicy, expectedApprovalPolicy) => {+ let config: CodexSecurityConfig | undefined;+ const savedConfig = {+ model: "gpt-original",+ ...(savedApprovalPolicy === undefined+ ? {}+ : { approval_policy: savedApprovalPolicy }),+ };++ expect(+ await main(+ ["scans", "rerun", "scan-original"],+ capture().stream,+ capture().stream,+ dependencies({+ onConfig: (value) => {+ config = value;+ },+ onWorkbench: () => ({+ recipe: {+ repository: "/original/repository",+ target: { kind: "repository", paths: [] },+ mode: "standard",+ config: savedConfig,+ },+ }),+ }),+ ),+ ).toBe(0);+ expect(config?.codexOverrides).toEqual({+ ...savedConfig,+ approval_policy: expectedApprovalPolicy,+ });+ },+ );+test("preserves workbench failures and does not initialize Codex", async () => {const stderr = capture();let started = false;diff --git a/sdk/typescript/tests-ts/config.test.ts b/sdk/typescript/tests-ts/config.test.tsindex f3fc3fb2d..8951c6d62 100644--- a/sdk/typescript/tests-ts/config.test.ts+++ b/sdk/typescript/tests-ts/config.test.ts@@ -63,13 +63,11 @@ function runPinnedCodex(codexHome: string, arguments_: readonly string[]) {}describe("Codex configuration", () => {- test("never grants scan execution approvals by default", async () => {+ test("automatically reviews scan execution approvals by default", async () => {expect(await mergedCodexConfig({})).toMatchObject({- approval_policy: "never",+ approval_policy: "on-request",+ approvals_reviewer: "auto_review",});- expect(await mergedCodexConfig({})).not.toHaveProperty(- "approvals_reviewer",- );});test("lets Codex honor native and managed credential storage", async () => {