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): create scan output for long POSIX repository names (#2527)

Michael D'Angelof706261c6cd2
diff --git a/sdk/typescript/src/runtime.ts b/sdk/typescript/src/runtime.ts
index 30ba1a704..dec7b71c9 100644
--- a/sdk/typescript/src/runtime.ts
+++ b/sdk/typescript/src/runtime.ts
@@ -2292,7 +2292,13 @@ async function prepareOutputDirectory(
);
await createWindowsOutputDirectory(created, false);
} else {
- created = await mkdtemp(join(canonicalRoot, `${prefix}-`));
+ try {
+ created = await mkdtemp(join(canonicalRoot, `${prefix}-`));
+ } catch (error) {
+ if (nodeErrorCode(error) !== "ENAMETOOLONG") throw error;
+ // The repository name itself can fill a filesystem component.
+ created = await mkdtemp(join(canonicalRoot, "codex-security-"));
+ }
}
try {
if ((process.umask() & 0o700) !== 0) await chmod(created, 0o700);
diff --git a/sdk/typescript/tests-ts/runtime.test.ts b/sdk/typescript/tests-ts/runtime.test.ts
index b3d8bedda..9ddcd220b 100644
--- a/sdk/typescript/tests-ts/runtime.test.ts
+++ b/sdk/typescript/tests-ts/runtime.test.ts
@@ -6646,6 +6646,23 @@ describe("runtime directories and plugin Python boundary", () => {
},
);
+ testPosix(
+ "creates private scan directories for a maximum-length repository name",
+ async () => {
+ const root = await realpath(await temporaryDirectory());
+ const repositoryName = "r".repeat(255);
+ const outputs = await Promise.all([
+ prepareOutputDir(undefined, repositoryName, root),
+ prepareOutputDir(undefined, repositoryName, root),
+ ]);
+ expect(new Set(outputs).size).toBe(2);
+ for (const output of outputs) {
+ expect(dirname(output)).toBe(root);
+ expect((await stat(output)).mode & 0o777).toBe(0o700);
+ }
+ },
+ );
+
test("validates explicit output directories and creates private temporary paths", async () => {
const root = await temporaryDirectory();
const absent = join(root, "scan");