OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security
TypeScript ai-securityapplication-securityclicode-scanningcodexcodex-securitycybersecuritydevsecopsnodejsnpmopenaisdksecuritytypescriptvulnerability-scanning
fix(sdk): reject special filesystem path targets before scanning (#1524)
Peterc423dae0d7de
diff --git a/sdk/typescript/src/targets.ts b/sdk/typescript/src/targets.tsindex cb880ff84..5ef7153b1 100644--- a/sdk/typescript/src/targets.ts+++ b/sdk/typescript/src/targets.ts@@ -1,6 +1,6 @@import { isNonEmptyString } from "./value.js";import { execFile as execFileCallback } from "node:child_process";-import { existsSync, realpathSync } from "node:fs";+import { realpathSync, type Stats } from "node:fs";import { lstat, readFile, realpath, stat } from "node:fs/promises";import { homedir } from "node:os";import {@@ -570,11 +570,10 @@ export async function normalizeTarget(const candidate = isAbsolute(expandHome(value))? resolve(expandHome(value)): resolve(root, expandHome(value));- if (!existsSync(candidate)) {- throw new InvalidTargetError(`Path target does not exist: ${value}`);- }+ let metadata: Stats;let canonical: string;try {+ metadata = await abortable(() => stat(candidate), signal);canonical = await abortable(() => realpath(candidate), signal);} catch (error) {throwIfAborted(signal);@@ -582,6 +581,12 @@ export async function normalizeTarget(cause: error,});}+ // Match the bundled scan scope resolver's supported filesystem types.+ if (!metadata.isFile() && !metadata.isDirectory()) {+ throw new InvalidTargetError(+ `Path target is not a regular file or directory: ${value}`,+ );+ }const relativePath = relative(root, canonical);if (relativePathIsOutside(relativePath)) {throw new InvalidTargetError(diff --git a/sdk/typescript/tests-ts/targets.test.ts b/sdk/typescript/tests-ts/targets.test.tsindex f4bf112dd..b7e7b9b86 100644--- a/sdk/typescript/tests-ts/targets.test.ts+++ b/sdk/typescript/tests-ts/targets.test.ts@@ -111,6 +111,12 @@ describe("scan target normalization", () => {test("normalizes repository and path targets", async () => {const repo = await repository();+ const alias = join(repo, "source-link");+ await symlink(+ join(repo, "src"),+ alias,+ process.platform === "win32" ? "junction" : "dir",+ );expect(await normalizeTarget(repo, "repository")).toEqual({kind: "repository",paths: [],@@ -121,6 +127,7 @@ describe("scan target normalization", () => {join(repo, "src", "app.ts"),join(repo, "src"),"src/app.ts",+ alias,]),).toEqual({kind: "paths",@@ -163,14 +170,29 @@ describe("scan target normalization", () => {},);- test("rejects empty and escaping paths", async () => {+ test("rejects empty, missing, and escaping paths", async () => {const repo = await repository();await expect(normalizeTarget(repo, [""])).rejects.toThrow("empty path");+ await expect(normalizeTarget(repo, ["missing.ts"])).rejects.toThrow(+ "Path target does not exist: missing.ts",+ );await expect(normalizeTarget(repo, [join(repo, "..")])).rejects.toThrow("outside the repository",);});+ test.skipIf(process.platform === "win32")(+ "rejects special filesystem targets the scan scope resolver cannot read",+ async () => {+ const repo = await repository();+ const fifo = join(repo, "src", "pending.fifo");+ execFileSync("mkfifo", [fifo]);+ await expect(normalizeTarget(repo, [fifo])).rejects.toThrow(+ "not a regular file or directory",+ );+ },+ );+test.skipIf(process.platform !== "win32")("rejects NTFS alternate streams before runtime initialization",async () => {