Skip to content

OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security

fix(windows): grant scan workers explicit source read access (#2545)

Michael D'Angelo337dd60c9623
diff --git a/plugins/codex-security/.mcp.json b/plugins/codex-security/.mcp.json
index ca6334d1f..f34c00d49 100644
--- a/plugins/codex-security/.mcp.json
+++ b/plugins/codex-security/.mcp.json
@@ -48,6 +48,7 @@
"CODEX_SECURITY_DEEP_SCAN_CONFIG_PATH",
"CODEX_SECURITY_SCAN_DIR",
"CODEX_SECURITY_PLUGIN_ROOT",
+ "CODEX_SECURITY_REPOSITORY",
"CODEX_SECURITY_SCAN_ROOT",
"CODEX_SECURITY_STATE_DIR",
"CODEX_SECURITY_SURFACE",
diff --git a/plugins/codex-security/mcp-app/src/deep-scan/executor.ts b/plugins/codex-security/mcp-app/src/deep-scan/executor.ts
index 7686d9f66..d212d18e9 100644
--- a/plugins/codex-security/mcp-app/src/deep-scan/executor.ts
+++ b/plugins/codex-security/mcp-app/src/deep-scan/executor.ts
@@ -612,6 +612,8 @@ function workerPermissionProfile(
]);
if (sandbox.pluginReadRoot !== undefined)
filesystem.set(sandbox.pluginReadRoot, { ".": "read" });
+ if (sandbox.sourceReadRoot !== undefined)
+ filesystem.set(sandbox.sourceReadRoot, { ".": "read" });
for (const path of [...sandbox.filesystemDenies, ...literalDenies])
filesystem.set(path, "deny");
const pointDenies = literalDenies.filter((path) => /[*?[\]]/u.test(path));
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.ts
index 21e30a2c7..f4d065ac5 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
@@ -15,6 +15,8 @@ export type DeepWorkerParentSandbox = {
readonly literalFilesystemDenies?: readonly string[];
/** Windows needs the parent's named read root for the selected plugin. */
readonly pluginReadRoot?: string;
+ /** Preserve the selected source's named read root for Windows ACL setup. */
+ readonly sourceReadRoot?: string;
readonly globScanMaxDepth?: number;
};
@@ -24,6 +26,9 @@ export function resolveDeepWorkerParentSandbox(
pluginRoot = process.platform === "win32"
? process.env.CODEX_SECURITY_PLUGIN_ROOT
: undefined,
+ sourceRoot = process.platform === "win32"
+ ? process.env.CODEX_SECURITY_REPOSITORY
+ : undefined,
): DeepWorkerParentSandbox {
const state = trustedSandboxState(extra);
@@ -57,6 +62,7 @@ export function resolveDeepWorkerParentSandbox(
const filesystemDenies: string[] = [];
const literalFilesystemDenies: string[] = [];
let pluginReadRoot: string | undefined;
+ let sourceReadRoot: string | undefined;
for (const value of filesystem.entries) {
const entry = record(value);
if (!entry || !isKnownFilesystemAccess(entry.access)) {
@@ -103,14 +109,23 @@ export function resolveDeepWorkerParentSandbox(
);
}
literalFilesystemDenies.push(path.path);
- } else if (
- entry.access === "read" &&
- pluginRoot !== undefined &&
- isAbsolute(path.path) &&
- relative(toNamespacedPath(path.path), toNamespacedPath(pluginRoot)) ===
- ""
- ) {
- pluginReadRoot = path.path;
+ } else if (entry.access === "read" && isAbsolute(path.path)) {
+ if (
+ pluginRoot !== undefined &&
+ relative(
+ toNamespacedPath(path.path),
+ toNamespacedPath(pluginRoot),
+ ) === ""
+ )
+ pluginReadRoot = path.path;
+ if (
+ sourceRoot !== undefined &&
+ relative(
+ toNamespacedPath(path.path),
+ toNamespacedPath(sourceRoot),
+ ) === ""
+ )
+ sourceReadRoot = path.path;
}
} else if (path.type === "glob_pattern") {
if (!isNonEmptyString(path.pattern)) {
@@ -150,6 +165,7 @@ export function resolveDeepWorkerParentSandbox(
return {
filesystemDenies,
...(pluginReadRoot === undefined ? {} : { pluginReadRoot }),
+ ...(sourceReadRoot === undefined ? {} : { sourceReadRoot }),
...(literalFilesystemDenies.length ? { literalFilesystemDenies } : {}),
...(globScanMaxDepth !== undefined ? { globScanMaxDepth } : {}),
};
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.ts
index f29cbcde4..f7712ba2d 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
@@ -1655,8 +1655,13 @@ env_key = "SYNTHETIC_GATEWAY_KEY"`,
index === 0
? path.join(fixture.root, `plugin-${index}`)
: undefined;
+ const sourceReadRoot = path.join(
+ fixture.root,
+ `private source [${index}]`,
+ );
const parentSandbox = {
pluginReadRoot,
+ sourceReadRoot,
filesystemDenies: [
...trustedParentSandboxWithDenials.filesystemDenies,
...(nestedReceipts ? [] : [workerUsageDirectory]),
@@ -1725,6 +1730,7 @@ env_key = "SYNTHETIC_GATEWAY_KEY"`,
...deniedWorkerPermissionProfile,
filesystem: {
...deniedWorkerPermissionProfile.filesystem,
+ [sourceReadRoot]: { ".": "read" },
...(pluginReadRoot === undefined
? {}
: { [pluginReadRoot]: { ".": "read" } }),
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.ts
index 59fa601b4..baca98f42 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
@@ -18,6 +18,35 @@ const pinnedReadOnly = {
};
const stagedPlugin = path.resolve("bundled plugin [fixture]");
+const selectedSource = path.resolve("private source [fixture]");
+for (const access of ["read", "write"] as const) {
+ assert.deepEqual(
+ resolveDeepWorkerParentSandbox(
+ restricted([
+ rootRead,
+ { path: { type: "path", path: selectedSource }, access },
+ {
+ path: { type: "path", path: path.dirname(selectedSource) },
+ access: "read",
+ },
+ {
+ path: {
+ type: "path",
+ path: path.join(selectedSource, "config.toml"),
+ },
+ access: "deny",
+ },
+ ]),
+ stagedPlugin,
+ selectedSource,
+ ),
+ {
+ filesystemDenies: [],
+ literalFilesystemDenies: [path.join(selectedSource, "config.toml")],
+ ...(access === "read" ? { sourceReadRoot: selectedSource } : {}),
+ },
+ );
+}
assert.deepEqual(
resolveDeepWorkerParentSandbox(
restricted([
diff --git a/plugins/codex-security/mcp-app/tests/test_mcp_app_smoke.ts b/plugins/codex-security/mcp-app/tests/test_mcp_app_smoke.ts
index 348794eba..d5230e1c8 100644
--- a/plugins/codex-security/mcp-app/tests/test_mcp_app_smoke.ts
+++ b/plugins/codex-security/mcp-app/tests/test_mcp_app_smoke.ts
@@ -119,6 +119,7 @@ assert.deepEqual(
"CODEX_SECURITY_DEEP_SCAN_CONFIG_PATH",
"CODEX_SECURITY_SCAN_DIR",
"CODEX_SECURITY_PLUGIN_ROOT",
+ "CODEX_SECURITY_REPOSITORY",
"CODEX_SECURITY_SCAN_ROOT",
"CODEX_SECURITY_STATE_DIR",
"CODEX_SECURITY_SURFACE",
diff --git a/sdk/typescript/src/api.ts b/sdk/typescript/src/api.ts
index 4807bb6aa..6955d4999 100644
--- a/sdk/typescript/src/api.ts
+++ b/sdk/typescript/src/api.ts
@@ -1341,6 +1341,9 @@ export class CodexSecurity {
const validationPermissions = {
...scanPermissions,
filesystem: {
+ ...(process.platform === "win32"
+ ? { [inputs.repository]: { ".": "read" } }
+ : {}),
...(scanPermissions["filesystem"] as JsonObject),
":workspace_roots": "read",
...(runtime.deepScanConfigPath === undefined ||
@@ -1977,7 +1980,10 @@ export class CodexSecurity {
: [runtime.deepScanConfigPath]),
...inputs.gitMetadataPaths,
],
- await codexExecutableReadPaths(this.#codexCommand().command),
+ [
+ ...(process.platform === "win32" ? policyReadRoots : []),
+ ...(await codexExecutableReadPaths(this.#codexCommand().command)),
+ ],
ambientHome,
);
const { codex } = await this.#createSessionCodex(
@@ -4758,15 +4764,24 @@ export class CodexSecurity {
environment[SAFETY_IDENTIFIER_ENV] = session.safetyIdentifier;
}
const sdkCodexConfig = structuredCodexConfig(config ?? sessionConfig);
+ // Windows configures sandbox ACL access for named roots, including private sources.
+ const sourceReadRoot =
+ process.platform === "win32" && command === "scan"
+ ? runtimePaths["CODEX_SECURITY_REPOSITORY"]
+ : undefined;
// This snapshot outlives a Deep Scan when the client reuses its runtime.
if (
runtime.deepScanConfigPath !== undefined ||
- pluginReadRoot !== undefined
+ pluginReadRoot !== undefined ||
+ sourceReadRoot !== undefined
) {
configOverrides = [
`permissions.${SCAN_PERMISSION_PROFILE}.filesystem=${inlineToml({
":root": "read",
":workspace_roots": "write",
+ ...(sourceReadRoot !== undefined
+ ? { [sourceReadRoot]: { ".": "read" } }
+ : {}),
...(pluginReadRoot === undefined
? {}
: { [pluginReadRoot]: { ".": "read" } }),
@@ -7013,7 +7028,7 @@ export function scanRuntimeCodexConfig(
function policyFilesystemPermissions(
deniedPaths: readonly string[] = [],
- codexPaths: readonly string[] = [],
+ readPaths: readonly string[] = [],
ambientHome?: string,
): JsonObject {
const filesystem: JsonObject = {
@@ -7021,7 +7036,7 @@ function policyFilesystemPermissions(
[process.platform === "win32" ? ":root" : ":minimal"]: "read",
":workspace_roots": "read",
// Linux's sandbox re-executes Codex, including installations outside /usr.
- ...Object.fromEntries(codexPaths.map((path) => [path, { ".": "read" }])),
+ ...Object.fromEntries(readPaths.map((path) => [path, { ".": "read" }])),
// A scoped "." keeps native permission paths literal, including glob characters.
...Object.fromEntries(deniedPaths.map((path) => [path, { ".": "deny" }])),
};
diff --git a/sdk/typescript/src/runtime.ts b/sdk/typescript/src/runtime.ts
index 67092898b..de319933a 100644
--- a/sdk/typescript/src/runtime.ts
+++ b/sdk/typescript/src/runtime.ts
@@ -3164,15 +3164,12 @@ async function pluginRuntimeProjection(
}
const environment = server["env_vars"];
if (environment !== undefined && !Array.isArray(environment)) return;
- if (
- !Array.isArray(environment) ||
- !environment.includes("CODEX_SECURITY_PLUGIN_ROOT")
- ) {
- server["env_vars"] = [
- ...(Array.isArray(environment) ? environment : []),
- "CODEX_SECURITY_PLUGIN_ROOT",
- ];
- }
+ server["env_vars"] = [
+ ...(environment ?? []),
+ ...["CODEX_SECURITY_PLUGIN_ROOT", "CODEX_SECURITY_REPOSITORY"].filter(
+ (name) => !environment?.includes(name),
+ ),
+ ];
const files: PluginRuntimeProjection["files"] = new Map();
server["command"] =
server["command"] === "./scripts/launch_codex_security_mcp.cmd"
diff --git a/sdk/typescript/tests-ts/api-policy.test.ts b/sdk/typescript/tests-ts/api-policy.test.ts
index 04ee1263a..20e8bbe17 100644
--- a/sdk/typescript/tests-ts/api-policy.test.ts
+++ b/sdk/typescript/tests-ts/api-policy.test.ts
@@ -302,6 +302,14 @@ describe("CodexSecurity policy API", () => {
filesystem: {
[process.platform === "win32" ? ":root" : ":minimal"]: "read",
":workspace_roots": "read",
+ ...(process.platform === "win32"
+ ? Object.fromEntries(
+ f.threads[0]!.additionalDirectories!.map((path) => [
+ path,
+ { ".": "read" },
+ ]),
+ )
+ : {}),
...Object.fromEntries(
readPaths.map((path) => [path, { ".": "read" }]),
),
diff --git a/sdk/typescript/tests-ts/api-runtime-storage.test.ts b/sdk/typescript/tests-ts/api-runtime-storage.test.ts
index 8f01a3e3a..31d65dddc 100644
--- a/sdk/typescript/tests-ts/api-runtime-storage.test.ts
+++ b/sdk/typescript/tests-ts/api-runtime-storage.test.ts
@@ -160,6 +160,10 @@ test.each(["ready", "denied", "canceled"])(
"filesystem"
] as Record<string, unknown>;
expect(roots[dirname(profileFile)]).toEqual({ ".": "deny" });
+ if (process.platform === "win32" && operation !== "validation")
+ expect(roots[await realpath(repository)]).toEqual({
+ ".": "read",
+ });
if (process.platform === "win32" && operation !== "validation") {
const staged = options.env!["CODEX_SECURITY_PLUGIN_ROOT"]!;
expect(dirname(staged)).toBe(protectedDirectory!);
diff --git a/sdk/typescript/tests-ts/api-validation.test.ts b/sdk/typescript/tests-ts/api-validation.test.ts
index f9e69d86b..10c5d5dd3 100644
--- a/sdk/typescript/tests-ts/api-validation.test.ts
+++ b/sdk/typescript/tests-ts/api-validation.test.ts
@@ -225,6 +225,9 @@ describe("CodexSecurity finding validation", () => {
permissions: {
codex_security_validation: {
filesystem: {
+ ...(process.platform === "win32"
+ ? { [options.repositoryPath]: { ".": "read" } }
+ : {}),
":root": "read",
":workspace_roots": "read",
...credentialDenies,
diff --git a/sdk/typescript/tests-ts/runtime-mcp-source-environment.test.ts b/sdk/typescript/tests-ts/runtime-mcp-source-environment.test.ts
new file mode 100644
index 000000000..ad855e2a6
--- /dev/null
+++ b/sdk/typescript/tests-ts/runtime-mcp-source-environment.test.ts
@@ -0,0 +1,122 @@
+import { afterEach, expect, test } from "bun:test";
+import { spawnSync } from "node:child_process";
+import { mkdir, readFile, writeFile } from "node:fs/promises";
+import { join } from "node:path";
+import { fileURLToPath } from "node:url";
+import { createMarketplace } from "../src/runtime.js";
+import { createApiTestFixtures } from "./support/temporary-directories.js";
+
+const { temporaryDirectory, cleanup } = createApiTestFixtures();
+afterEach(cleanup);
+const pluginRoot = fileURLToPath(
+ new URL("../../../plugins/codex-security/", import.meta.url),
+);
+const parentSandbox = new URL(
+ "../../../plugins/codex-security/mcp-app/src/deep-scan/parent-sandbox.ts",
+ import.meta.url,
+).href;
+
+test.each(["bundled", "legacy projection", "declared projection"])(
+ "%s forwards each scan's repository through the MCP environment",
+ async (configuration) => {
+ const root = await temporaryDirectory();
+ let manifest = join(pluginRoot, ".mcp.json");
+ if (configuration !== "bundled") {
+ const selected = join(root, "selected plugin");
+ await mkdir(join(selected, ".codex-plugin"), { recursive: true });
+ await writeFile(
+ join(selected, ".codex-plugin", "plugin.json"),
+ JSON.stringify({ name: "codex-security", version: "1.2.3" }),
+ );
+ await writeFile(
+ join(selected, ".mcp.json"),
+ JSON.stringify({
+ mcpServers: {
+ "codex-security": {
+ command: "./scripts/launch_codex_security_mcp",
+ env_vars:
+ configuration === "declared projection"
+ ? ["CODEX_SECURITY_PLUGIN_ROOT", "CODEX_SECURITY_REPOSITORY"]
+ : [],
+ },
+ },
+ }),
+ );
+ const marketplace = await createMarketplace(join(root, "home"), selected);
+ manifest = join(marketplace, "plugins", "codex-security", ".mcp.json");
+ }
+ const mcp = JSON.parse(await readFile(manifest, "utf8"));
+ const allowed: string[] = mcp.mcpServers["codex-security"].env_vars;
+ expect(
+ allowed.filter((name) => name === "CODEX_SECURITY_REPOSITORY"),
+ ).toHaveLength(1);
+
+ for (const scan of ["fresh", "resumed"]) {
+ const source = join(root, `${scan} source [fixture]`);
+ const credentials = join(source, "config.toml");
+ const parentEnvironment = {
+ CODEX_SECURITY_PLUGIN_ROOT: pluginRoot,
+ CODEX_SECURITY_REPOSITORY: source,
+ SYNTHETIC_UNDECLARED_VALUE: "ambient fixture",
+ };
+ // Model the native MCP allowlist, then inspect the actual child process.
+ const environment = Object.fromEntries(
+ Object.entries(parentEnvironment).filter(([name]) =>
+ allowed.includes(name),
+ ),
+ );
+ const entries = [
+ { path: { type: "special", value: { kind: "root" } }, access: "read" },
+ { path: { type: "path", path: source }, access: "read" },
+ { path: { type: "path", path: credentials }, access: "deny" },
+ ];
+ const extra = {
+ _meta: {
+ "codex/sandbox-state-meta": {
+ permissionProfile: {
+ type: "managed",
+ file_system: { type: "restricted", entries },
+ },
+ },
+ },
+ };
+ const child = spawnSync(
+ process.execPath,
+ [
+ "--eval",
+ `import { resolveDeepWorkerParentSandbox } from ${JSON.stringify(parentSandbox)};
+const extra = JSON.parse(process.argv[1]);
+const inherited = resolveDeepWorkerParentSandbox(extra);
+extra._meta["codex/sandbox-state-meta"].permissionProfile.file_system.entries.splice(1, 1);
+console.log(JSON.stringify({
+ repository: process.env.CODEX_SECURITY_REPOSITORY,
+ ambient: process.env.SYNTHETIC_UNDECLARED_VALUE,
+ inherited,
+ withoutNamedGrant: resolveDeepWorkerParentSandbox(extra),
+}));`,
+ JSON.stringify(extra),
+ ],
+ {
+ env: { SystemRoot: process.env["SystemRoot"], ...environment },
+ encoding: "utf8",
+ windowsHide: true,
+ },
+ );
+ expect(child.error).toBeUndefined();
+ expect(child.stderr).toBe("");
+ expect(child.status).toBe(0);
+ expect(JSON.parse(child.stdout)).toEqual({
+ repository: source,
+ inherited: {
+ filesystemDenies: [],
+ literalFilesystemDenies: [credentials],
+ ...(process.platform === "win32" ? { sourceReadRoot: source } : {}),
+ },
+ withoutNamedGrant: {
+ filesystemDenies: [],
+ literalFilesystemDenies: [credentials],
+ },
+ });
+ }
+ },
+);
diff --git a/sdk/typescript/tests-ts/runtime.test.ts b/sdk/typescript/tests-ts/runtime.test.ts
index 00686838d..b46f16610 100644
--- a/sdk/typescript/tests-ts/runtime.test.ts
+++ b/sdk/typescript/tests-ts/runtime.test.ts
@@ -1047,7 +1047,7 @@ for await (const line of createInterface({ input: process.stdin })) {
const result = request.method === "initialize"
? { protocolVersion: request.params.protocolVersion, capabilities: { tools: {} }, serverInfo: { name: "synthetic-launcher", version: "1" } }
: request.method === "tools/list"
- ? { tools: [{ name: "probe", description: "Reports test launcher details.", _meta: { launch: { pluginRoot, args: process.argv.slice(2), execArgv: process.execArgv, cwd: process.cwd(), entry: process.argv[1] } }, inputSchema: { type: "object", properties: {} } }] }
+ ? { tools: [{ name: "probe", description: "Reports test launcher details.", _meta: { launch: { pluginRoot, repository: process.env.CODEX_SECURITY_REPOSITORY, ambient: process.env.SYNTHETIC_UNDECLARED_VALUE, args: process.argv.slice(2), execArgv: process.execArgv, cwd: process.cwd(), entry: process.argv[1] } }, inputSchema: { type: "object", properties: {} } }] }
: request.method === "resources/list" ? { resources: [] }
: request.method === "resources/templates/list" ? { resourceTemplates: [] }
: {};
@@ -1125,12 +1125,11 @@ for await (const line of createInterface({ input: process.stdin })) {
cwd: mcp.mcpServers["codex-security"].cwd,
startup_timeout_sec:
mcp.mcpServers["codex-security"].startup_timeout_sec,
- env_vars: declaredRoot
- ? mcp.mcpServers["codex-security"].env_vars
- : [
- ...mcp.mcpServers["codex-security"].env_vars,
- "CODEX_SECURITY_PLUGIN_ROOT",
- ],
+ env_vars: [
+ ...mcp.mcpServers["codex-security"].env_vars,
+ ...(declaredRoot ? [] : ["CODEX_SECURITY_PLUGIN_ROOT"]),
+ "CODEX_SECURITY_REPOSITORY",
+ ],
});
expect(
JSON.parse(await readFile(join(selected, ".mcp.json"), "utf8")),
@@ -1156,6 +1155,11 @@ for await (const line of createInterface({ input: process.stdin })) {
...environment,
CODEX_HOME: home,
CODEX_SQLITE_HOME: sqliteHome,
+ CODEX_SECURITY_REPOSITORY: join(
+ root,
+ pluginRoot === second ? "second source" : "first source",
+ ),
+ SYNTHETIC_UNDECLARED_VALUE: "ambient fixture",
...(pluginRoot === undefined
? {}
: { CODEX_SECURITY_PLUGIN_ROOT: pluginRoot }),
@@ -1219,6 +1223,10 @@ for await (const line of createInterface({ input: process.stdin })) {
});
const details = server.tools.probe._meta.launch;
expect(details.pluginRoot).toBe(await realpath(pluginRoot));
+ expect(details.repository).toBe(
+ join(root, pluginRoot === second ? "second source" : "first source"),
+ );
+ expect(details.ambient).toBeUndefined();
expect(details.args).toEqual(argumentsAfterEntry);
expect(details.cwd).toBe(
process.platform === "win32"
@@ -2292,7 +2300,11 @@ for await (const line of createInterface({ input: process.stdin })) {
command: "./scripts/launch_codex_security_mcp_sdk",
args: ["--stdio", "synthetic argument"],
cwd: ".",
- env_vars: ["CODEX_HOME", "CODEX_SECURITY_PLUGIN_ROOT"],
+ env_vars: [
+ "CODEX_HOME",
+ "CODEX_SECURITY_PLUGIN_ROOT",
+ "CODEX_SECURITY_REPOSITORY",
+ ],
});
expect(
(await stat(join(staged, "scripts", "launch_codex_security_mcp")))