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: avoid overlapping Deep Scan worker sandbox denies (#2416)
Michael D'Angelo3aa36e216501
diff --git a/plugins/codex-security/mcp-app/src/deep-scan/executor.ts b/plugins/codex-security/mcp-app/src/deep-scan/executor.tsindex 424c0fa96..5341a19b1 100644--- a/plugins/codex-security/mcp-app/src/deep-scan/executor.ts+++ b/plugins/codex-security/mcp-app/src/deep-scan/executor.ts@@ -157,15 +157,8 @@ export class CodexSdkWorkerExecutor implements CodexWorkerExecutor {);}const workerProfile = workerPermissionProfile(- request.workerUsageDirectory- ? {- ...parentSandbox,- literalFilesystemDenies: [- ...(parentSandbox.literalFilesystemDenies ?? []),- request.workerUsageDirectory,- ],- }- : parentSandbox,+ parentSandbox,+ request.workerUsageDirectory,);const originalCwd = process.cwd();const childEnv = await snapshotWorkerEnvironment();@@ -609,12 +602,33 @@ function workerSubagentConfig(subagents: number, inheritedFeatures: unknown) {};}-function workerPermissionProfile(sandbox: DeepWorkerParentSandbox) {+function workerPermissionProfile(+ sandbox: DeepWorkerParentSandbox,+ workerUsageDirectory?: string,+) {+ const literalDenies = sandbox.literalFilesystemDenies ?? [];const filesystem = new Map<string, string | Record<string, string>>([[":root", "read"],- ...sandbox.filesystemDenies.map((key): [string, string] => [key, "deny"]),+ ...[...sandbox.filesystemDenies, ...literalDenies].map(+ (key): [string, string] => [key, "deny"],+ ),]);- for (const literal of sandbox.literalFilesystemDenies ?? []) {+ const pointDenies = literalDenies.filter((path) => /[*?[\]]/u.test(path));+ // Bubblewrap cannot mount a second mask inside a directory it already hid.+ if (+ workerUsageDirectory &&+ (process.platform !== "linux" ||+ !literalDenies.some(+ (path) =>+ workerUsageDirectory === path ||+ workerUsageDirectory.startsWith(+ path.endsWith(sep) ? path : `${path}${sep}`,+ ),+ ))+ ) {+ pointDenies.push(workerUsageDirectory);+ }+ for (const literal of pointDenies) {if (sandbox.filesystemDenies.includes(literal)) {const root = parse(literal).root;const scope = filesystem.get(root);diff --git a/plugins/codex-security/mcp-app/src/deep-scan/parent-sandbox.ts b/plugins/codex-security/mcp-app/src/deep-scan/parent-sandbox.tsindex e2356dd17..46bf5fc9f 100644--- a/plugins/codex-security/mcp-app/src/deep-scan/parent-sandbox.ts+++ b/plugins/codex-security/mcp-app/src/deep-scan/parent-sandbox.ts@@ -7,12 +7,12 @@ export const CODEX_SANDBOX_STATE_META_CAPABILITY = "codex/sandbox-state-meta";export type DeepWorkerParentSandbox = {/**- * Validated path and glob keys copied into the worker's stricter root-read+ * Validated glob keys copied into the worker's stricter root-read* profile. Grants are intentionally not transported because Deep Scan* workers never inherit parent write access.*/readonly filesystemDenies: readonly string[];- /** Literal paths with glob characters retain native point-deny semantics. */+ /** Preserve literal paths separately from glob patterns. */readonly literalFilesystemDenies?: readonly string[];readonly globScanMaxDepth?: number;};@@ -97,10 +97,7 @@ export function resolveDeepWorkerParentSandbox("a parent filesystem denial path cannot be preserved",);}- (hasGlobMetacharacters(path.path)- ? literalFilesystemDenies- : filesystemDenies- ).push(path.path);+ literalFilesystemDenies.push(path.path);}} else if (path.type === "glob_pattern") {if (!isNonEmptyString(path.pattern)) {@@ -245,10 +242,6 @@ function isValidSpecialPath(value: Record<string, unknown>): boolean {return false;}-function hasGlobMetacharacters(value: string): boolean {- return value.includes("*") || value.includes("?") || value.includes("[");-}-function unsupportedParentSandbox(reason: string): DeepScanNonRetryableError {return new DeepScanNonRetryableError(`Deep Scan cannot safely start a read-only worker: ${reason}.`,diff --git a/plugins/codex-security/mcp-app/tests/test_deep_scan_executor.ts b/plugins/codex-security/mcp-app/tests/test_deep_scan_executor.tsindex 22fd182b1..d164fef4e 100644--- a/plugins/codex-security/mcp-app/tests/test_deep_scan_executor.ts+++ b/plugins/codex-security/mcp-app/tests/test_deep_scan_executor.ts@@ -1639,16 +1639,17 @@ env_key = "SYNTHETIC_GATEWAY_KEY"`,? undefined: path.join(codexHome, `${nativeProfile}.config.toml`);const literalDeniedPath = `/repo/literal.key"\\雪\u007f-${index}`;+ const nestedReceipts = index === 0;const workerUsageDirectory = path.join(- fixture.root,- `state-${index}`,- "codex-home",+ nestedReceipts ? codexHome : `${codexHome}-sibling`,"worker-usage",`scan-${index}`,);+ const receiptRoot = path.parse(workerUsageDirectory).root;const parentSandbox = {filesystemDenies: [...trustedParentSandboxWithDenials.filesystemDenies,+ ...(nestedReceipts ? [] : [workerUsageDirectory]),],literalFilesystemDenies: [...trustedParentSandboxWithDenials.literalFilesystemDenies,@@ -1716,8 +1717,21 @@ env_key = "SYNTHETIC_GATEWAY_KEY"`,...deniedWorkerPermissionProfile.filesystem,[deepPath]: { ".": "deny" },[codexHome]: { ".": "deny" },- [workerUsageDirectory]: { ".": "deny" },- [literalDeniedPath]: { ".": "deny" },+ ...(!nestedReceipts || process.platform !== "linux"+ ? { [workerUsageDirectory]: { ".": "deny" } }+ : {}),+ ...(nestedReceipts+ ? {}+ : {+ [receiptRoot]: {+ ...(receiptRoot === "/"+ ? deniedWorkerPermissionProfile.filesystem["/"]+ : {}),+ [workerUsageDirectory.slice(receiptRoot.length)]:+ "deny",+ },+ }),+ [literalDeniedPath]: "deny",},},provider,diff --git a/plugins/codex-security/mcp-app/tests/test_deep_scan_parent_sandbox.ts b/plugins/codex-security/mcp-app/tests/test_deep_scan_parent_sandbox.tsindex f7ad9ca67..2af8faaec 100644--- a/plugins/codex-security/mcp-app/tests/test_deep_scan_parent_sandbox.ts+++ b/plugins/codex-security/mcp-app/tests/test_deep_scan_parent_sandbox.ts@@ -88,12 +88,8 @@ assert.deepEqual(),),{- filesystemDenies: [- "/repo/.env",- "/repo/.secrets",- "/repo-a/**/.env",- "/repo-b/**/*.pem",- ],+ filesystemDenies: ["/repo-a/**/.env", "/repo-b/**/*.pem"],+ literalFilesystemDenies: ["/repo/.env", "/repo/.secrets"],globScanMaxDepth: 3,},);diff --git a/plugins/codex-security/mcp-app/tests/test_deep_scan_stdio_lifecycle.ts b/plugins/codex-security/mcp-app/tests/test_deep_scan_stdio_lifecycle.tsindex 303f9d358..759ec571b 100644--- a/plugins/codex-security/mcp-app/tests/test_deep_scan_stdio_lifecycle.ts+++ b/plugins/codex-security/mcp-app/tests/test_deep_scan_stdio_lifecycle.ts@@ -55,7 +55,7 @@ async function testDeepScanStdioLifecycle() {const targetPath = path.join(fixtureRoot, "target");const failedTargetPath = path.join(fixtureRoot, "failed-target");const expiredTargetPath = path.join(fixtureRoot, "expired-target");- const stateDir = path.join(fixtureRoot, "state");+ const stateDir = path.join(fixtureRoot, "state]");const codexHome = path.join(fixtureRoot, "codex [home]");const installedPluginRoot = path.join(codexHome, "plugins", "installed");const runtimeConfigPath = path.join(fixtureRoot, "active-config.toml");@@ -121,6 +121,10 @@ async function testDeepScanStdioLifecycle() {entries: [...parentSandbox.permissionProfile.file_system.entries,{ path: { type: "path", path: codexHome }, access: "deny" },+ {+ path: { type: "path", path: path.join(stateDir, "codex-home") },+ access: "deny",+ },],},},@@ -1672,12 +1676,32 @@ function assertReadOnlyWorkerInvocation(const overrides = args.filter((arg) =>arg.startsWith("permissions.codex_security_deep_scan_worker="),);+ const credentialHome = path.join(stateDirectory, "codex-home");+ const workerUsageDirectory = path.join(+ credentialHome,+ "worker-usage",+ scanId,+ );+ const filesystem = {+ ":root": "read",+ [deniedHome]: { ".": "deny" },+ [credentialHome]: { ".": "deny" },+ ...(process.platform === "linux"+ ? {}+ : { [workerUsageDirectory]: { ".": "deny" } }),+ };assert.deepEqual(- overrides.map((value) => parseToml(value)),+ overrides.map((value) => JSON.parse(JSON.stringify(parseToml(value)))),[- parseToml(- `permissions.codex_security_deep_scan_worker={extends=":read-only",filesystem={":root"="read",${JSON.stringify(deniedHome)}={"."="deny"},${JSON.stringify(path.join(stateDirectory, "codex-home", "worker-usage", scanId))}={"."="deny"}},network={enabled=false}}`,- ),+ {+ permissions: {+ codex_security_deep_scan_worker: {+ extends: ":read-only",+ filesystem,+ network: { enabled: false },+ },+ },+ },],);}