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): preserve leading backslashes in POSIX home-relative scan paths (#2497)

Michael D'Angelo177dbf50d96c
diff --git a/sdk/typescript/src/targets.ts b/sdk/typescript/src/targets.ts
index 8d5f464a9..5009dd0ff 100644
--- a/sdk/typescript/src/targets.ts
+++ b/sdk/typescript/src/targets.ts
@@ -1016,7 +1016,9 @@ function expandHome(value: string): string {
return homedir();
}
if (value.startsWith("~/") || value.startsWith("~\\")) {
- return resolve(homedir(), value.slice(2).replace(/^[/\\]+/, ""));
+ const separators =
+ sep === "/" && value.startsWith("~/") ? /^\/+/ : /^[/\\]+/;
+ return resolve(homedir(), value.slice(2).replace(separators, ""));
}
return value;
}
diff --git a/sdk/typescript/tests-ts/targets.test.ts b/sdk/typescript/tests-ts/targets.test.ts
index 439f1300e..4a824872a 100644
--- a/sdk/typescript/tests-ts/targets.test.ts
+++ b/sdk/typescript/tests-ts/targets.test.ts
@@ -874,14 +874,19 @@ describe("scan target normalization", () => {
);
});
- test("keeps repeated home separators anchored under the home directory", async () => {
+ test("resolves home-relative scan paths using native separators", async () => {
const root = await mkdtemp(join(tmpdir(), "codex-security-home-"));
temporaryDirectories.track(root);
- const project = join(await realpath(root), "project");
- await mkdir(project);
+ const home = await realpath(root);
+ const names = ["project"];
+ if (process.platform !== "win32") names.push("\\project");
+ for (const name of names) await mkdir(join(home, name));
+ const inputs = names.flatMap((name) =>
+ ["~/", "~//", "~///"].map((prefix) => prefix + name),
+ );
const script = `
const { normalizeRepository } = await import(process.argv[1]);
- for (const value of ["~/project", "~//project", "~///project"]) {
+ for (const value of process.argv.slice(2)) {
console.log(await normalizeRepository(value));
}
`;
@@ -891,6 +896,7 @@ describe("scan target normalization", () => {
"-e",
script,
fileURLToPath(new URL("../src/targets.ts", import.meta.url)),
+ ...inputs,
],
{
encoding: "utf8",
@@ -898,12 +904,9 @@ describe("scan target normalization", () => {
},
);
expect(result.status).toBe(0);
- const canonicalProject = await realpath(project);
- expect(result.stdout.trim().split(/\r?\n/)).toEqual([
- canonicalProject,
- canonicalProject,
- canonicalProject,
- ]);
+ expect(result.stdout.trim().split(/\r?\n/)).toEqual(
+ inputs.map((value) => join(home, value.slice(2))),
+ );
});
});