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): allow safe relative executable PATH entries (#408)

mldangelo-oai3c93e746b9ab
diff --git a/sdk/typescript/src/trusted-executable.ts b/sdk/typescript/src/trusted-executable.ts
index e45b1bd42..5a0729cf0 100644
--- a/sdk/typescript/src/trusted-executable.ts
+++ b/sdk/typescript/src/trusted-executable.ts
@@ -20,7 +20,7 @@ export async function resolveTrustedExecutable(
)?.[1];
const entries: string[] = [];
for (const entry of path?.split(delimiter) ?? []) {
- if (entry.length === 0 || !isAbsolute(entry)) continue;
+ if (entry.length === 0) continue;
const canonical = await realpath(entry).catch(() => null);
if (canonical === null || isWithin(root, canonical)) continue;
if (!entries.includes(canonical)) entries.push(canonical);
diff --git a/sdk/typescript/tests-ts/runtime.test.ts b/sdk/typescript/tests-ts/runtime.test.ts
index 4aed2ca7f..3bb9daa31 100644
--- a/sdk/typescript/tests-ts/runtime.test.ts
+++ b/sdk/typescript/tests-ts/runtime.test.ts
@@ -4677,7 +4677,7 @@ describe("runtime directories and plugin Python boundary", () => {
PATH: [
unsafeBin,
linkedBin,
- "node_modules/.bin",
+ relative(process.cwd(), unsafeBin),
"",
trustedBin,
].join(delimiter),
diff --git a/sdk/typescript/tests-ts/trusted-executable.test.ts b/sdk/typescript/tests-ts/trusted-executable.test.ts
index 34db45018..f1e06baac 100644
--- a/sdk/typescript/tests-ts/trusted-executable.test.ts
+++ b/sdk/typescript/tests-ts/trusted-executable.test.ts
@@ -9,7 +9,7 @@ import {
writeFile,
} from "node:fs/promises";
import { tmpdir } from "node:os";
-import { basename, delimiter, dirname, join } from "node:path";
+import { basename, delimiter, dirname, join, relative } from "node:path";
import { fileURLToPath } from "node:url";
import { afterEach, describe, expect, test } from "bun:test";
import { resolveTrustedExecutable } from "../src/trusted-executable.js";
@@ -77,6 +77,42 @@ async function resolveWindowsExecutable(
}
describe("trusted executable resolution", () => {
+ test("accepts safe relative PATH entries without trusting repository links", async () => {
+ const root = await temporaryDirectory();
+ const repository = join(root, "repository");
+ const unsafe = join(repository, "bin");
+ const linked = join(root, "linked");
+ const trusted = join(root, "trusted");
+ const executable = process.platform === "win32" ? "git.exe" : "git";
+ await Promise.all([mkdir(unsafe, { recursive: true }), mkdir(trusted)]);
+ await Promise.all([
+ writeFile(join(unsafe, executable), "untrusted executable"),
+ writeFile(join(trusted, executable), "trusted executable"),
+ ]);
+ await chmod(join(trusted, executable), 0o700);
+ await symlink(
+ unsafe,
+ linked,
+ process.platform === "win32" ? "junction" : "dir",
+ );
+
+ expect(
+ await resolveTrustedExecutable(
+ "git",
+ {
+ PATH: ["", unsafe, linked, trusted]
+ .map((entry) => (entry ? relative(process.cwd(), entry) : entry))
+ .join(delimiter),
+ KEEP: "ok",
+ },
+ repository,
+ ),
+ ).toEqual({
+ executable: join(trusted, executable),
+ environment: { KEEP: "ok", PATH: trusted },
+ });
+ });
+
test.skipIf(process.platform === "win32")(
"preserves the invocation name of a trusted symlinked executable",
async () => {