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(windows): preserve sandbox override compatibility (#96)
mldangelo-oaib26d4c3b2d87
diff --git a/sdk/typescript/src/config.ts b/sdk/typescript/src/config.tsindex db6a4be88..adf712a47 100644--- a/sdk/typescript/src/config.ts+++ b/sdk/typescript/src/config.ts@@ -72,9 +72,40 @@ export async function mergedCodexConfig(const overrides = cloneJson(config.codexOverrides ?? {});validateOverrides(overrides);validateNativeMultiAgentV2Overrides(overrides);+ normalizeLegacyWindowsSandboxOverride(overrides);+ const profiles = overrides["profiles"];+ if (isObject(profiles)) {+ for (const profile of Object.values(profiles)) {+ if (isObject(profile)) {+ normalizeLegacyWindowsSandboxOverride(profile);+ }+ }+ }return deepMerge(cloneJson(DEFAULT_CODEX_CONFIG), overrides);}+function normalizeLegacyWindowsSandboxOverride(overrides: JsonObject): void {+ const features = overrides["features"];+ if (!isObject(features)) {+ return;+ }+ const elevated = features["elevated_windows_sandbox"];+ if (typeof elevated !== "boolean") {+ return;+ }+ const windows = overrides["windows"];+ if (+ windows !== undefined &&+ (!isObject(windows) || Object.hasOwn(windows, "sandbox"))+ ) {+ return;+ }+ overrides["windows"] = {+ ...(isObject(windows) ? windows : {}),+ sandbox: elevated ? "elevated" : "unelevated",+ };+}+export async function writeCodexConfig(path: string,config: JsonObject,diff --git a/sdk/typescript/tests-ts/config.test.ts b/sdk/typescript/tests-ts/config.test.tsindex 3e1e5c1df..cdfa1ec38 100644--- a/sdk/typescript/tests-ts/config.test.ts+++ b/sdk/typescript/tests-ts/config.test.ts@@ -3,9 +3,11 @@ import { tmpdir } from "node:os";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 {ConfigurationError,DEFAULT_CODEX_CONFIG,+ type JsonObject,mergedCodexConfig,writeCodexConfig,} from "../src/index.js";@@ -26,6 +28,39 @@ async function temporaryDirectory(): Promise<string> {return path;}+function runPinnedCodex(codexHome: string, arguments_: readonly string[]) {+ const node = Bun.which("node");+ if (node === null) {+ throw new Error("The pinned Codex CLI requires Node.js.");+ }+ const environment: NodeJS.ProcessEnv = {+ ...process.env,+ CODEX_HOME: codexHome,+ };+ delete environment["OPENAI_API_KEY"];+ delete environment["CODEX_API_KEY"];+ return Bun.spawnSync(+ [+ node,+ join(+ import.meta.dir,+ "..",+ "node_modules",+ "@openai",+ "codex",+ "bin",+ "codex.js",+ ),+ ...arguments_,+ ],+ {+ env: environment,+ stdout: "pipe",+ stderr: "pipe",+ },+ );+}+describe("Codex configuration", () => {test("deep-merges native multi-agent v2 defaults", async () => {const merged = await mergedCodexConfig({@@ -49,6 +84,183 @@ describe("Codex configuration", () => {expect(merged["windows"]).toEqual({ sandbox: "elevated" });});+ test("preserves legacy elevated Windows sandbox overrides", async () => {+ const merged = await mergedCodexConfig({+ codexOverrides: {+ features: { elevated_windows_sandbox: true },+ },+ });++ expect(merged).toMatchObject({+ features: { elevated_windows_sandbox: true },+ windows: { sandbox: "elevated" },+ });+ });++ test("projects legacy elevated Windows overrides into selected profiles", async () => {+ const merged = await mergedCodexConfig({+ codexOverrides: {+ profile: "elevated",+ profiles: {+ elevated: {+ features: { elevated_windows_sandbox: true },+ },+ },+ },+ });++ expect(merged).toMatchObject({+ windows: { sandbox: "unelevated" },+ profiles: {+ elevated: {+ features: { elevated_windows_sandbox: true },+ windows: { sandbox: "elevated" },+ },+ },+ });+ });++ test("allows selected profiles to override root elevated sandbox defaults", async () => {+ const merged = await mergedCodexConfig({+ codexOverrides: {+ features: { elevated_windows_sandbox: true },+ profile: "restricted",+ profiles: {+ restricted: {+ features: { elevated_windows_sandbox: false },+ },+ },+ },+ });++ expect(merged).toMatchObject({+ windows: { sandbox: "elevated" },+ profiles: {+ restricted: {+ features: { elevated_windows_sandbox: false },+ windows: { sandbox: "unelevated" },+ },+ },+ });+ });++ test("gives profile-local Windows sandbox overrides precedence", async () => {+ const merged = await mergedCodexConfig({+ codexOverrides: {+ profile: "restricted",+ profiles: {+ restricted: {+ features: { elevated_windows_sandbox: true },+ windows: { sandbox: "unelevated" },+ },+ },+ },+ });++ expect(merged).toMatchObject({+ profiles: {+ restricted: {+ features: { elevated_windows_sandbox: true },+ windows: { sandbox: "unelevated" },+ },+ },+ });+ });++ test("gives explicit Windows sandbox overrides precedence", async () => {+ const merged = await mergedCodexConfig({+ codexOverrides: {+ features: { elevated_windows_sandbox: true },+ windows: { sandbox: "unelevated" },+ },+ });++ expect(merged).toMatchObject({+ features: { elevated_windows_sandbox: true },+ windows: { sandbox: "unelevated" },+ });+ });++ test("retains the Windows sandbox in the hardened scan profile", async () => {+ const stateDirectory = join(tmpdir(), "codex-security-windows-state");+ const merged = await mergedCodexConfig({});++ expect(scanRuntimeCodexConfig(merged, stateDirectory)).toMatchObject({+ windows: { sandbox: "unelevated" },+ default_permissions: "codex_security_scan",+ permissions: {+ codex_security_scan: {+ filesystem: {+ ":root": "read",+ ":workspace_roots": "write",+ [stateDirectory]: "write",+ },+ },+ },+ });+ });++ test("writes Windows sandbox settings accepted by the pinned Codex CLI", async () => {+ const root = await temporaryDirectory();+ const path = join(root, "config.toml");+ await writeCodexConfig(path, await mergedCodexConfig({}));++ expect(parse(await readFile(path, "utf8"))).toMatchObject({+ windows: { sandbox: "unelevated" },+ });++ const result = runPinnedCodex(root, ["features", "list"]);+ expect(result.exitCode).toBe(0);+ expect(result.stdout.length).toBeGreaterThan(0);+ });++ test("writes selected profile sandbox settings accepted by the pinned Codex CLI", async () => {+ const root = await temporaryDirectory();+ const path = join(root, "config.toml");+ const config = await mergedCodexConfig({+ codexOverrides: {+ profile: "elevated",+ profiles: {+ elevated: {+ features: { elevated_windows_sandbox: true },+ },+ },+ },+ });+ const nativeConfig = structuredClone(config);+ delete nativeConfig["profile"];+ delete nativeConfig["profiles"];+ const profileConfig = (config["profiles"] as JsonObject)[+ "elevated"+ ] as JsonObject;+ const profilePath = join(root, "elevated.config.toml");+ await writeCodexConfig(path, nativeConfig);+ await writeCodexConfig(profilePath, profileConfig);++ expect(parse(await readFile(path, "utf8"))).toMatchObject({+ windows: { sandbox: "unelevated" },+ });+ expect(parse(await readFile(profilePath, "utf8"))).toMatchObject({+ features: { elevated_windows_sandbox: true },+ windows: { sandbox: "elevated" },+ });++ const result = runPinnedCodex(root, [+ "--profile",+ "elevated",+ "mcp",+ "list",+ "--json",+ ]);+ if (result.exitCode !== 0) {+ throw new Error(+ `The pinned Codex CLI rejected the selected Windows sandbox profile: ${new TextDecoder().decode(result.stderr)}`,+ );+ }+ expect(result.exitCode).toBe(0);+ expect(result.stdout.length).toBeGreaterThan(0);+ });+test("rejects prototype-bearing override keys", async () => {for (const key of ["__proto__", "constructor", "prototype"]) {await expect(@@ -73,6 +285,7 @@ describe("Codex configuration", () => {test("keeps exported default configuration deeply immutable", async () => {expect(Object.isFrozen(DEFAULT_CODEX_CONFIG)).toBe(true);expect(Object.isFrozen(DEFAULT_CODEX_CONFIG["features"])).toBe(true);+ expect(Object.isFrozen(DEFAULT_CODEX_CONFIG["windows"])).toBe(true);expect(Object.isFrozen((DEFAULT_CODEX_CONFIG["features"] as Record<string, unknown>)[