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): enforce strict scan approval boundaries (#430)
mldangelo-oaid809b6db4222
diff --git a/SECURITY.md b/SECURITY.mdindex 3a8392271..38507a8ea 100644--- a/SECURITY.md+++ b/SECURITY.md@@ -70,14 +70,14 @@ 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. Its-profile allows reads of the local filesystem and writes to workspace roots and-the selected scan state directory.--Setting `approval_policy`, `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.+`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.++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.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 eb86c092c..b33eef9da 100644--- a/sdk/typescript/README.md+++ b/sdk/typescript/README.md@@ -333,6 +333,7 @@ configuration. Each scan starts with a private runtime and these Codexdefaults:```toml+approval_policy = "never"cli_auth_credentials_store = "auto"model = "gpt-5.6-sol"model_reasoning_effort = "xhigh"@@ -697,12 +698,13 @@ 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"`. It can read the local filesystem and write to-workspace roots and the selected scan state directory. Scans do not request-interactive approval. Setting `approval_policy`, `sandbox_mode`, or permissions+`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 permissionsthrough `--codex` or SDK `codexOverrides` does not replace these controls or-make them more restrictive. Independently enforced host and network-restrictions still apply.+make the filesystem profile more restrictive. 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 e56fa145e..9f04dca44 100644--- a/sdk/typescript/src/api.ts+++ b/sdk/typescript/src/api.ts@@ -2787,11 +2787,24 @@ export function scanRuntimeCodexConfig(): JsonObject {const hardened = structuredClone(config);delete hardened["sandbox_mode"];+ delete hardened["approvals_reviewer"];+ const profiles = hardened["profiles"];+ if (isRecord(profiles)) {+ for (const profile of Object.values(profiles)) {+ if (!isRecord(profile)) continue;+ delete profile["approval_policy"];+ delete profile["approvals_reviewer"];+ delete profile["default_permissions"];+ delete profile["permissions"];+ delete profile["sandbox_mode"];+ }+ }const configuredPermissions = isRecord(hardened["permissions"])? hardened["permissions"]: {};return {...hardened,+ approval_policy: "never",allow_login_shell: false,default_permissions: SCAN_PERMISSION_PROFILE,permissions: {diff --git a/sdk/typescript/src/config.ts b/sdk/typescript/src/config.tsindex 0e6d5a730..acc98ac2e 100644--- a/sdk/typescript/src/config.ts+++ b/sdk/typescript/src/config.ts@@ -52,6 +52,7 @@ export function isExternalModelProvider(}export const DEFAULT_CODEX_CONFIG: Readonly<JsonObject> = {+ approval_policy: "never",cli_auth_credentials_store: "auto",model: "gpt-5.6-sol",model_reasoning_effort: "xhigh",diff --git a/sdk/typescript/tests-ts/api-preflight-config.test.ts b/sdk/typescript/tests-ts/api-preflight-config.test.tsindex 772a86481..4629d5321 100644--- a/sdk/typescript/tests-ts/api-preflight-config.test.ts+++ b/sdk/typescript/tests-ts/api-preflight-config.test.ts@@ -311,6 +311,8 @@ describe("CodexSecurity preflight configuration", () => {test("uses a root-read filesystem profile with writable workspace and workbench state", () => {const stateDirectory = join(tmpdir(), "codex-security-persistent-state");const original = {+ approval_policy: "on-request",+ approvals_reviewer: "auto_review",sandbox_mode: "workspace-write",allow_login_shell: true,default_permissions: "unsafe",@@ -324,6 +326,7 @@ describe("CodexSecurity preflight configuration", () => {};expect(scanRuntimeCodexConfig(original, stateDirectory)).toEqual({+ approval_policy: "never",allow_login_shell: false,default_permissions: "codex_security_scan",permissions: {@@ -338,6 +341,8 @@ describe("CodexSecurity preflight configuration", () => {},});expect(original).toMatchObject({+ approval_policy: "on-request",+ approvals_reviewer: "auto_review",sandbox_mode: "workspace-write",allow_login_shell: true,default_permissions: "unsafe",@@ -363,6 +368,49 @@ describe("CodexSecurity preflight configuration", () => {});});+ test("removes execution and permission overrides from every configured profile", () => {+ const stateDirectory = join(tmpdir(), "codex-security-persistent-state");+ const original = {+ profile: "selected",+ profiles: {+ selected: {+ model: "profile-model",+ approval_policy: "on-request",+ approvals_reviewer: "auto_review",+ default_permissions: "unsafe",+ permissions: { unsafe: { filesystem: { ":root": "write" } } },+ sandbox_mode: "danger-full-access",+ },+ other: {+ model_reasoning_effort: "high",+ approval_policy: "untrusted",+ approvals_reviewer: "guardian_subagent",+ default_permissions: "other-unsafe",+ permissions: { "other-unsafe": { filesystem: { ":root": "write" } } },+ sandbox_mode: "workspace-write",+ },+ },+ };++ const hardened = scanRuntimeCodexConfig(original, stateDirectory);+ expect(hardened).toMatchObject({+ approval_policy: "never",+ default_permissions: "codex_security_scan",+ profile: "selected",+ });+ expect(hardened["profiles"]).toEqual({+ selected: { model: "profile-model" },+ other: { model_reasoning_effort: "high" },+ });+ expect(original.profiles.selected).toMatchObject({+ approval_policy: "on-request",+ approvals_reviewer: "auto_review",+ default_permissions: "unsafe",+ permissions: { unsafe: { filesystem: { ":root": "write" } } },+ sandbox_mode: "danger-full-access",+ });+ });+test("preserves configured Responses metadata without persisting scan attribution", () => {const stateDirectory = join(tmpdir(), "codex-security-persistent-state");const credentialHome = join(stateDirectory, "codex-home");diff --git a/sdk/typescript/tests-ts/api.test.ts b/sdk/typescript/tests-ts/api.test.tsindex fd8cc731c..17514bf89 100644--- a/sdk/typescript/tests-ts/api.test.ts+++ b/sdk/typescript/tests-ts/api.test.ts@@ -1908,6 +1908,9 @@ describe("CodexSecurity orchestration", () => {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,diff --git a/sdk/typescript/tests-ts/config.test.ts b/sdk/typescript/tests-ts/config.test.tsindex 6897c4d4d..f3fc3fb2d 100644--- a/sdk/typescript/tests-ts/config.test.ts+++ b/sdk/typescript/tests-ts/config.test.ts@@ -1,4 +1,4 @@-import { mkdtemp, readFile, rm, stat } from "node:fs/promises";+import { mkdir, mkdtemp, readFile, rm, stat } from "node:fs/promises";import { tmpdir } from "node:os";import { join } from "node:path";import { afterEach, describe, expect, test } from "bun:test";@@ -63,6 +63,15 @@ function runPinnedCodex(codexHome: string, arguments_: readonly string[]) {}describe("Codex configuration", () => {+ test("never grants scan execution approvals by default", async () => {+ expect(await mergedCodexConfig({})).toMatchObject({+ approval_policy: "never",+ });+ expect(await mergedCodexConfig({})).not.toHaveProperty(+ "approvals_reviewer",+ );+ });+test("lets Codex honor native and managed credential storage", async () => {expect(DEFAULT_CODEX_CONFIG["cli_auth_credentials_store"]).toBe("auto");expect((await mergedCodexConfig({}))["cli_auth_credentials_store"]).toBe(@@ -326,6 +335,64 @@ describe("Codex configuration", () => {});});+ test("denies writes outside the scan workspace and state directory", async () => {+ const root = await temporaryDirectory();+ const codexHome = join(root, "codex-home");+ const workspace = join(root, "workspace");+ const stateDirectory = join(root, "state");+ await Promise.all(+ [codexHome, workspace, stateDirectory].map((path) => mkdir(path)),+ );+ await writeCodexConfig(+ join(codexHome, "config.toml"),+ scanRuntimeCodexConfig(+ await mergedCodexConfig({}),+ stateDirectory,+ codexHome,+ ),+ );+ const node = Bun.which("node");+ expect(node).not.toBeNull();+ const attemptWrite = (path: string) =>+ runPinnedCodex(codexHome, [+ "sandbox",+ "--config",+ "permissions.codex_security_scan.network.enabled=true",+ "--permission-profile",+ "codex_security_scan",+ "--cd",+ workspace,+ node!,+ "-e",+ "require('node:fs').writeFileSync(process.argv[1], 'probe')",+ path,+ ]);++ const allowed = join(workspace, "inside.txt");+ const permitted = attemptWrite(allowed);+ const outside = join(root, "outside.txt");+ expect(attemptWrite(outside).exitCode).not.toBe(0);+ await expect(stat(outside)).rejects.toMatchObject({ code: "ENOENT" });+ if (permitted.exitCode !== 0) {+ const details = new TextDecoder().decode(permitted.stderr);+ if (+ process.platform === "linux" &&+ /bwrap: (?:setting up uid map: Permission denied|loopback: Failed RTM_NEWADDR: Operation not permitted)/u.test(+ details,+ )+ ) {+ expect(runPinnedCodex(codexHome, ["features", "list"]).exitCode).toBe(+ 0,+ );+ return;+ }+ throw new Error(+ `The pinned Codex CLI rejected an allowed scan write: ${details}`,+ );+ }+ expect(await readFile(allowed, "utf8")).toBe("probe");+ });+test("writes Windows sandbox settings accepted by the pinned Codex CLI", async () => {const root = await temporaryDirectory();const path = join(root, "config.toml");