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(runtime): find bundled tools through executable symlinks (#1707)

Michael D'Angelo1a34862a53a5
diff --git a/evals/secret-discovery/test_runtime.mts b/evals/secret-discovery/test_runtime.mts
index e1861517e..302e3e715 100644
--- a/evals/secret-discovery/test_runtime.mts
+++ b/evals/secret-discovery/test_runtime.mts
@@ -202,6 +202,7 @@ test("the SDK executable override preserves bundled tools at the child boundary"
const executable = join(directory, "bin", "codex");
const tools = join(directory, "codex-path");
await mkdir(dirname(executable));
+ await writeFile(executable, "synthetic executable; never launched\n");
await mkdir(tools);
const inherited = {
Path: [tools, join(directory, "other tools"), tools].join(delimiter),
diff --git a/plugins/codex-security/mcp-app/tests/deep_scan_executable_alias_cases.ts b/plugins/codex-security/mcp-app/tests/deep_scan_executable_alias_cases.ts
new file mode 100644
index 000000000..c15a08826
--- /dev/null
+++ b/plugins/codex-security/mcp-app/tests/deep_scan_executable_alias_cases.ts
@@ -0,0 +1,138 @@
+import assert from "node:assert/strict";
+import { mkdir, readFile, symlink, writeFile } from "node:fs/promises";
+import path from "node:path";
+import type { DeepWorkerParentSandbox } from "../src/deep-scan/parent-sandbox.js";
+import type { CodexSdkWorkerExecutor as WorkerExecutor } from "../src/deep-scan/executor.js";
+import { readJson } from "./support/json.ts";
+
+export async function testConcurrentWorkerExecutableAliases({
+ CodexSdkWorkerExecutor,
+ fakeCodexFixture,
+ parentSandbox,
+ bundledCodexSdkEnvironment,
+ assertConfigOverrides,
+ assertReadOnlyWorkerPolicy,
+}: {
+ CodexSdkWorkerExecutor: typeof WorkerExecutor;
+ fakeCodexFixture: () => Promise<{
+ root: string;
+ executablePath: string;
+ markerPath: string;
+ preflightMarkerPath: string;
+ }>;
+ parentSandbox: DeepWorkerParentSandbox;
+ bundledCodexSdkEnvironment: (
+ command: string,
+ environment: Record<string, string>,
+ ) => Record<string, string>;
+ assertConfigOverrides: (
+ args: readonly string[],
+ values: Record<string, string>,
+ ) => void;
+ assertReadOnlyWorkerPolicy: (args: readonly string[]) => void;
+}) {
+ const saved = [
+ "CODEX_CLI_PATH",
+ "CODEX_HOME",
+ "CODEX_SECURITY_CONFIG_PATH",
+ "CODEX_SECURITY_DEEP_SCAN_CONFIG_PATH",
+ "FAKE_CODEX_MARKER",
+ "PATH",
+ ].map((name) => [name, process.env[name]] as const);
+ try {
+ const scans = [];
+ for (const index of [0, 1]) {
+ const fixture = await fakeCodexFixture();
+ const bin = path.join(fixture.root, "vendor", "bin");
+ const tools = path.join(fixture.root, "vendor", "codex-path");
+ const command = path.join(bin, "codex");
+ const alias = path.join(fixture.root, "codex-alias");
+ const launcherMarker = path.join(fixture.root, "launcher.txt");
+ const promptPath = path.join(fixture.root, "prompt.md");
+ const configPath = path.join(fixture.root, "config.toml");
+ const summary = index === 0 ? "concise" : "none";
+ await mkdir(bin, { recursive: true });
+ await mkdir(tools);
+ const quoted = [
+ launcherMarker,
+ process.execPath,
+ fixture.executablePath,
+ ].map((value) => `'${value.replaceAll("'", `'"'"'`)}'`);
+ await writeFile(
+ command,
+ `#!/bin/sh\nprintf '%s' "$0" > ${quoted[0]}\nexec ${quoted[1]} ${quoted[2]} "$@"\n`,
+ { mode: 0o755 },
+ );
+ await writeFile(
+ path.join(tools, "rg"),
+ `#!/bin/sh\nprintf 'synthetic search ${index}\\n'\n`,
+ { mode: 0o755 },
+ );
+ await symlink(command, alias);
+ await writeFile(promptPath, "CAPTURE_SYNTHETIC_RG");
+ await writeFile(configPath, `model_reasoning_summary = "${summary}"\n`);
+ scans.push({
+ fixture,
+ tools,
+ alias,
+ launcherMarker,
+ promptPath,
+ configPath,
+ summary,
+ executor: new CodexSdkWorkerExecutor({
+ parentSandbox,
+ }),
+ });
+ }
+ delete process.env.CODEX_SECURITY_DEEP_SCAN_CONFIG_PATH;
+ for (const kind of ["discovery", "dedup"] as const) {
+ for (const resumeThreadId of [undefined, "resumed-thread"]) {
+ await Promise.all(
+ scans.map((scan) => {
+ Object.assign(
+ process.env,
+ bundledCodexSdkEnvironment(scan.alias, {
+ PATH: "",
+ CODEX_CLI_PATH: scan.alias,
+ CODEX_HOME: scan.fixture.root,
+ CODEX_SECURITY_CONFIG_PATH: scan.configPath,
+ FAKE_CODEX_MARKER: scan.fixture.markerPath,
+ }),
+ );
+ return scan.executor.run({
+ promptPath: scan.promptPath,
+ workingDirectory: scan.fixture.root,
+ kind,
+ resumeThreadId,
+ subagents: 0,
+ signal: new AbortController().signal,
+ });
+ }),
+ );
+ for (const [index, scan] of scans.entries()) {
+ const preflight = await readJson(scan.fixture.preflightMarkerPath);
+ const invocation = await readJson(scan.fixture.markerPath);
+ assert.equal(await readFile(scan.launcherMarker, "utf8"), scan.alias);
+ assert.equal(invocation.bundledTool, `synthetic search ${index}`);
+ assert.equal(invocation.runtimeEnvironment.PATH, scan.tools);
+ assert.equal(preflight.gitEnvironment.PATH, scan.tools);
+ assert.equal(invocation.codexHome, scan.fixture.root);
+ assert.equal(preflight.codexHome, scan.fixture.root);
+ assert.equal(
+ invocation.argv.includes("resume"),
+ resumeThreadId !== undefined,
+ );
+ assertConfigOverrides(invocation.argv, {
+ model_reasoning_summary: scan.summary,
+ });
+ assertReadOnlyWorkerPolicy(invocation.argv);
+ }
+ }
+ }
+ } finally {
+ for (const [name, value] of saved) {
+ if (value === undefined) delete process.env[name];
+ else process.env[name] = value;
+ }
+ }
+}
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 131b5d74a..1fe577624 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
@@ -35,6 +35,7 @@ import type {
CodexWorkerRequest,
DeepScanWorkerKind,
} from "../src/deep-scan/types.js";
+import { testConcurrentWorkerExecutableAliases } from "./deep_scan_executable_alias_cases.ts";
import { testDeepScanContextSnapshots } from "./deep_scan_context_snapshot_cases.ts";
const executorSource = new URL("../src/deep-scan/executor.ts", import.meta.url);
@@ -136,6 +137,14 @@ try {
await testRuntimePermissionProfileFallbackStopsAndDiscards();
await testWorkerLaunchesWithoutGlobalCodex();
await testPreflightBindsExecutableAndHomeBeforeChangingCwd();
+ await testConcurrentWorkerExecutableAliases({
+ CodexSdkWorkerExecutor,
+ fakeCodexFixture,
+ parentSandbox: trustedParentSandbox,
+ bundledCodexSdkEnvironment,
+ assertConfigOverrides,
+ assertReadOnlyWorkerPolicy,
+ });
await testSdkInvocationAndThreadCapture();
await testBedrockCredentialsReachWorker();
await testBedrockCredentialsReachWorker("oidc");
diff --git a/sdk/typescript/src/codex-sdk-environment.ts b/sdk/typescript/src/codex-sdk-environment.ts
index 38a59508e..714c4d661 100644
--- a/sdk/typescript/src/codex-sdk-environment.ts
+++ b/sdk/typescript/src/codex-sdk-environment.ts
@@ -11,7 +11,7 @@ export function bundledCodexSdkEnvironment(
let toolsDirectory: string;
try {
toolsDirectory = join(
- dirname(realpathSync.native(dirname(command))),
+ dirname(dirname(realpathSync.native(command))),
"codex-path",
);
if (!statSync(toolsDirectory).isDirectory()) return environment;
diff --git a/sdk/typescript/tests-ts/api.test.ts b/sdk/typescript/tests-ts/api.test.ts
index bc0bd29c5..d8addd22b 100644
--- a/sdk/typescript/tests-ts/api.test.ts
+++ b/sdk/typescript/tests-ts/api.test.ts
@@ -7474,6 +7474,7 @@ describe("CodexSecurity orchestration", () => {
const inheritedTools = join(root, "operator-tools");
await mkdir(bundledTools, { recursive: true });
await mkdir(dirname(executable));
+ await writeFile(executable, "synthetic executable; never launched\n");
await mkdir(inheritedTools);
const originalPlatform = Object.getOwnPropertyDescriptor(
process,
diff --git a/sdk/typescript/tests-ts/provider-profile.test.ts b/sdk/typescript/tests-ts/provider-profile.test.ts
index 486f6ef4a..2c2b46bab 100644
--- a/sdk/typescript/tests-ts/provider-profile.test.ts
+++ b/sdk/typescript/tests-ts/provider-profile.test.ts
@@ -7,6 +7,7 @@ import {
readFile,
readdir,
stat,
+ symlink,
writeFile,
} from "node:fs/promises";
import { join, sep } from "node:path";
@@ -347,34 +348,41 @@ console.log(JSON.stringify({ type: "item.completed", item: {
console.log(JSON.stringify({ type: "turn.completed", usage: { input_tokens: 1, output_tokens: 1 } }));
process.exit(0);`,
);
- const configured = `${bin}${sep}.${sep}${executable}`;
- const environment = {
- ...(process.env["SystemRoot"] === undefined
- ? {}
- : { SystemRoot: process.env["SystemRoot"] }),
- PATH: "",
- CODEX_HOME: root,
- CODEX_CLI_PATH: configured,
- NODE_OPTIONS: `--import=${pathToFileURL(script).href}`,
- };
- const original = { ...environment };
- const client = await createProfileCodex(
- { env: environment },
- "synthetic-profile",
- );
- for (const resumed of [false, true]) {
- const thread = resumed
- ? client.resumeThread("synthetic-thread")
- : client.startThread();
- const result = await thread.run("synthetic prompt");
- expect(JSON.parse(result.finalResponse)).toEqual({
- path: tools,
- configured,
- search: "synthetic bundled search",
- resumed,
- });
+ const aliases = [`${bin}${sep}.${sep}${executable}`];
+ if (process.platform !== "win32") {
+ const alias = join(root, "codex-alias");
+ await symlink(join(bin, executable), alias);
+ aliases.push(alias);
+ }
+ for (const configured of aliases) {
+ const environment = {
+ ...(process.env["SystemRoot"] === undefined
+ ? {}
+ : { SystemRoot: process.env["SystemRoot"] }),
+ PATH: "",
+ CODEX_HOME: root,
+ CODEX_CLI_PATH: configured,
+ NODE_OPTIONS: `--import=${pathToFileURL(script).href}`,
+ };
+ const original = { ...environment };
+ const client = await createProfileCodex(
+ { env: environment },
+ "synthetic-profile",
+ );
+ for (const resumed of [false, true]) {
+ const thread = resumed
+ ? client.resumeThread("synthetic-thread")
+ : client.startThread();
+ const result = await thread.run("synthetic prompt");
+ expect(JSON.parse(result.finalResponse)).toEqual({
+ path: tools,
+ configured,
+ search: "synthetic bundled search",
+ resumed,
+ });
+ }
+ expect(environment).toEqual(original);
}
- expect(environment).toEqual(original);
});
test("private profiles retain providers for native required and inherited selection", async () => {