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(sdk): prefer exact POSIX PATH for trusted executables (#676)

HughChawbc124c3d0176
diff --git a/sdk/typescript/src/trusted-executable.ts b/sdk/typescript/src/trusted-executable.ts
index aa0cac47f..2e410484d 100644
--- a/sdk/typescript/src/trusted-executable.ts
+++ b/sdk/typescript/src/trusted-executable.ts
@@ -23,9 +23,11 @@ export async function resolveTrustedExecutable(
const root = await realpath(protectedRoot).catch(() =>
resolve(protectedRoot),
);
- const path = Object.entries(environment).find(
- ([name]) => name.toUpperCase() === "PATH",
- )?.[1];
+ const path =
+ environment["PATH"] ??
+ Object.entries(environment).find(
+ ([name]) => name.toUpperCase() === "PATH",
+ )?.[1];
const entries: string[] = [];
for (let entry of path?.split(delimiter) ?? []) {
if (
diff --git a/sdk/typescript/tests-ts/trusted-executable.test.ts b/sdk/typescript/tests-ts/trusted-executable.test.ts
index 8c74d8e5a..fb6a8f6d9 100644
--- a/sdk/typescript/tests-ts/trusted-executable.test.ts
+++ b/sdk/typescript/tests-ts/trusted-executable.test.ts
@@ -113,6 +113,33 @@ describe("trusted executable resolution", () => {
});
});
+ test.skipIf(process.platform === "win32")(
+ "prefers the exact POSIX PATH variable over a lowercase path variable",
+ async () => {
+ const root = await temporaryDirectory();
+ const repository = join(root, "repository");
+ const decoy = join(root, "decoy");
+ const trusted = join(root, "trusted");
+ await Promise.all([mkdir(repository), mkdir(decoy), mkdir(trusted)]);
+ await Promise.all([
+ writeFile(join(decoy, "git"), "decoy executable"),
+ writeFile(join(trusted, "git"), "trusted executable"),
+ ]);
+ await chmod(join(trusted, "git"), 0o700);
+
+ await expect(
+ resolveTrustedExecutable(
+ "git",
+ { path: decoy, PATH: trusted },
+ repository,
+ ),
+ ).resolves.toEqual({
+ executable: join(trusted, "git"),
+ environment: { PATH: trusted },
+ });
+ },
+ );
+
test.skipIf(process.platform === "win32")(
"preserves the invocation name of a trusted symlinked executable",
async () => {