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(ci): isolate audits and retain exact file identities (#1859)
Michael D'Angelof8377a170c1b
diff --git a/.github/workflows/node-ci.yml b/.github/workflows/node-ci.ymlindex 66ac393ee..0ca7b5828 100644--- a/.github/workflows/node-ci.yml+++ b/.github/workflows/node-ci.yml@@ -133,6 +133,8 @@ jobs:run: pnpm --dir sdk/typescript run format- name: Check MCP formattingrun: pnpm --dir plugins/codex-security/mcp-app exec prettier --check "**/*.{cjs,cts,js,jsx,mjs,mts,ts,tsx}"+ - name: Audit production dependencies+ run: pnpm --dir sdk/typescript run audit:prodnative:needs: classify-changes@@ -168,8 +170,6 @@ jobs:uses: ./.github/actions/download-native- *set-up-typescript-tools- *install-dependencies- - name: Audit production dependencies- run: pnpm --dir sdk/typescript run audit:prod- name: Packworking-directory: sdk/typescriptrun: pnpm pack --pack-destination ../../distdiff --git a/.github/workflows/test-quality.yml b/.github/workflows/test-quality.ymlindex 6fd7690bf..83d13c9a7 100644--- a/.github/workflows/test-quality.yml+++ b/.github/workflows/test-quality.yml@@ -32,7 +32,7 @@ jobs:if: ${{ !cancelled() && (inputs.native-artifacts-ready || needs.native.result == 'success') }}name: ${{ matrix.os }} / ${{ matrix.mode }}runs-on: ${{ matrix.os }}- timeout-minutes: ${{ matrix.os == 'windows-latest' && (matrix.mode == 'baseline' || matrix.mode == 'parallel') && 90 || 30 }}+ timeout-minutes: ${{ matrix.os == 'windows-latest' && 90 || 30 }}env:CODEX_SECURITY_PROPERTY_SEED: ${{ github.event_name == 'pull_request' && 1 || github.run_number }}strategy:diff --git a/sdk/typescript/src/contract.ts b/sdk/typescript/src/contract.tsindex 4530a03b3..54688a9d7 100644--- a/sdk/typescript/src/contract.ts+++ b/sdk/typescript/src/contract.ts@@ -40,7 +40,7 @@ const DOCUMENTS = {const PRODUCER_NAME = "codex-security-plugin";interface CheckedScanFile {path: string;- metadata: Stats;+ metadata: BigIntStats;parents: Array<{ path: string; metadata: Stats }>;}@@ -419,7 +419,7 @@ async function requireCheckedScanFile(parents.push({ path: current, metadata });}const path = join(scanDir, ...parts);- const metadata = await lstat(path);+ const metadata = await lstat(path, { bigint: true });throwIfAborted(signal);if (!metadata.isFile()) {throw new ContractValidationError(@@ -956,7 +956,7 @@ async function openCheckedScanFile(checked.path,constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK,);- const opened = await file.stat();+ const opened = await file.stat({ bigint: true });throwIfAborted(signal);if (!opened.isFile() ||@@ -980,7 +980,7 @@ async function openCheckedScanFile();}}- const current = await lstat(checked.path);+ const current = await lstat(checked.path, { bigint: true });throwIfAborted(signal);if (!current.isFile() ||diff --git a/sdk/typescript/tests-ts/scan-file-identity.test.ts b/sdk/typescript/tests-ts/scan-file-identity.test.tsnew file mode 100644index 000000000..66ffe06d9--- /dev/null+++ b/sdk/typescript/tests-ts/scan-file-identity.test.ts@@ -0,0 +1,90 @@+import { test, expect, spyOn, afterEach } from "bun:test";+import type { BigIntStats, Stats } from "node:fs";+import { mkdir, rename, writeFile, type FileHandle } from "node:fs/promises";+import { join } from "node:path";+import { readScanFile } from "../src/contract.js";+import { createApiTestFixtures } from "./support/temporary-directories.js";+import { runTestInSubprocess } from "./support/test-subprocess.js";++const { temporaryDirectory, cleanup } = createApiTestFixtures();+afterEach(cleanup);++for (const [name, originalId, replacementId] of [+ ["distinct exactly represented identities", 100n, 101n],+ ["distinct identities with equal Number values", 2n ** 60n, 2n ** 60n + 1n],+ ["an unchanged large identity", 2n ** 60n, 2n ** 60n],+] as const) {+ test(`checked scan file preserves ${name}`, async () => {+ const title = `checked scan file preserves ${name}`;+ if (runTestInSubprocess(import.meta.path, title)) return;+ const root = await temporaryDirectory();+ const scanDir = join(root, "scan");+ await mkdir(scanDir, { mode: 0o700 });+ const path = join(scanDir, "document.json");+ await writeFile(path, "original data");+ const files = await import("node:fs/promises");+ const originalLstat = files.lstat;+ const originalRealpath = files.realpath;+ const originalOpen = files.open;+ let replaced = false;+ const handles: FileHandle[] = [];+ const withIdentity = (metadata: Stats | BigIntStats, identity: bigint) => {+ Object.defineProperty(metadata, "ino", {+ value: typeof metadata.ino === "bigint" ? identity : Number(identity),+ });+ return metadata;+ };+ const inspecting = spyOn(files, "lstat").mockImplementation((async (+ ...args: Parameters<typeof originalLstat>+ ) => {+ const metadata = await originalLstat(...args);+ return args[0] === path+ ? withIdentity(metadata, replaced ? replacementId : originalId)+ : metadata;+ }) as typeof originalLstat);+ const resolving = spyOn(files, "realpath").mockImplementation((async (+ ...args: Parameters<typeof originalRealpath>+ ) => {+ const canonical = await originalRealpath(...args);+ if (args[0] === path && !replaced && originalId !== replacementId) {+ await rename(path, `${path}.original`);+ await writeFile(path, "replacement data");+ replaced = true;+ }+ return canonical;+ }) as typeof originalRealpath);+ const opening = spyOn(files, "open").mockImplementation(async (...args) => {+ const file = await originalOpen(...args);+ if (args[0] === path) {+ handles.push(file);+ const originalStat = file.stat.bind(file);+ spyOn(file, "stat").mockImplementation((async (+ ...options: Parameters<typeof originalStat>+ ) =>+ withIdentity(+ await originalStat(...options),+ replaced ? replacementId : originalId,+ )) as typeof originalStat);+ }+ return file;+ });+ try {+ if (originalId === replacementId) {+ expect(+ (await readScanFile(scanDir, "document.json", "fixture")).toString(),+ ).toBe("original data");+ } else {+ await expect(+ readScanFile(scanDir, "document.json", "fixture"),+ ).rejects.toThrow("expected the checked regular file");+ expect(replaced).toBe(true);+ }+ expect(handles).toHaveLength(1);+ expect(handles[0]!.fd).toBe(-1);+ } finally {+ inspecting.mockRestore();+ resolving.mockRestore();+ opening.mockRestore();+ }+ });+}diff --git a/sdk/typescript/tests-ts/skeleton.test.ts b/sdk/typescript/tests-ts/skeleton.test.tsindex 6bff0df27..f44deb473 100644--- a/sdk/typescript/tests-ts/skeleton.test.ts+++ b/sdk/typescript/tests-ts/skeleton.test.ts@@ -428,6 +428,7 @@ describe("TypeScript package skeleton", () => {["Typecheck", "static-checks"],["Check formatting", "static-checks"],["Check MCP formatting", "static-checks"],+ ["Audit production dependencies", "static-checks"],] as const) {expect(jobs[job]!.steps!.filter((step) => step.name === name),