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
test: reuse SDK runtime and repository fixtures (#1448)
mldangelo-oai0d7fefab5747
diff --git a/sdk/typescript/tests-ts/build-plugin.test.ts b/sdk/typescript/tests-ts/build-plugin.test.tsindex 5747763fd..79044d16c 100644--- a/sdk/typescript/tests-ts/build-plugin.test.ts+++ b/sdk/typescript/tests-ts/build-plugin.test.ts@@ -135,13 +135,6 @@ describe("bundled plugin build", () => {"plugin-files.json",await readFile(join(plugin, "plugin-files.json"), "utf8"),);- for (const name of ["codex_profile.mjs", "codex_profile.d.mts"]) {- await writeFixture(- source,- `scripts/${name}`,- await readFile(join(plugin, "scripts", name), "utf8"),- );- }const platformSource = join(source, "native", "platform.mts");await writeFile(platformSource,diff --git a/sdk/typescript/tests-ts/runtime.test.ts b/sdk/typescript/tests-ts/runtime.test.tsindex ae54c090c..2c847c974 100644--- a/sdk/typescript/tests-ts/runtime.test.ts+++ b/sdk/typescript/tests-ts/runtime.test.ts@@ -43,7 +43,6 @@ import { createInterface } from "node:readline";import { setImmediate as nextTurn } from "node:timers/promises";import { promisify } from "node:util";import { fileURLToPath } from "node:url";-import { brotliDecompressSync } from "node:zlib";import { afterEach, describe, expect, mock, spyOn, test } from "bun:test";import { strToU8, zipSync } from "fflate";import { build } from "esbuild";@@ -98,7 +97,7 @@ import {streamWindowsCredentialAclDescriptors,} from "../src/runtime.js";import { inspectTrustedExecutable } from "../src/trusted-executable.js";-import { PLUGIN_ROOT } from "./plugin-root.js";+import { loadBundledRuntime, PLUGIN_ROOT } from "./plugin-root.js";import { runTestInSubprocess } from "./support/test-subprocess.js";import {lowerUuid7Turn,@@ -152,6 +151,20 @@ function windowsTestCommand(},);}++function windowsUserSid() {+ const identity = windowsTestCommand("whoami.exe", [+ "/user",+ "/fo",+ "csv",+ "/nh",+ ]);+ expect(identity.status).toBe(0);+ const sid = /"(S-1-(?:\d+-)*\d+)"\s*$/u.exec(identity.stdout)?.[1];+ expect(sid).toBeDefined();+ return sid;+}+function inspectWindowsTestAcl(statements: string[],environment: NodeJS.ProcessEnv,@@ -346,12 +359,7 @@ describe("plugin runtime preparation", () => {});test("derives distinct finding identities from canonical candidate IDs", async () => {- const parts = await Promise.all(- ["000", "001"].map((part) =>- readFile(join(PLUGIN_ROOT, "mcp", `server.mjs.br.part-${part}`)),- ),- );- const runtime = brotliDecompressSync(Buffer.concat(parts)).toString("utf8");+ const runtime = await loadBundledRuntime();const source =/function buildFindings\(findings, mode\) \{[\s\S]*?\n\}/u.exec(runtime,@@ -4748,15 +4756,7 @@ describe("runtime directories and plugin Python boundary", () => {const root = await temporaryDirectory();const state = join(root, "state");await mkdir(state);- const user = windowsTestCommand("whoami.exe", [- "/user",- "/fo",- "csv",- "/nh",- ]);- expect(user.status).toBe(0);- const sid = /"(S-1-(?:\d+-)*\d+)"\s*$/u.exec(user.stdout)?.[1];- expect(sid).toBeDefined();+ const sid = windowsUserSid();const configured = windowsTestCommand("icacls.exe", [state,"/inheritance:r",@@ -4883,15 +4883,7 @@ describe("runtime directories and plugin Python boundary", () => {const root = await temporaryDirectory();const state = join(root, "state");await mkdir(state);- const identity = windowsTestCommand("whoami.exe", [- "/user",- "/fo",- "csv",- "/nh",- ]);- expect(identity.status).toBe(0);- const sid = /"(S-1-(?:\d+-)*\d+)"\s*$/u.exec(identity.stdout)?.[1];- expect(sid).toBeDefined();+ const sid = windowsUserSid();for (const ancestor of [root, state]) {const owned = windowsTestCommand("icacls.exe", [ancestor,@@ -4943,15 +4935,7 @@ describe("runtime directories and plugin Python boundary", () => {await writeFile(auth, '{"token":"synthetic-root"}\n');await writeFile(nestedAuth, '{"token":"synthetic-nested"}\n');- const identity = windowsTestCommand("whoami.exe", [- "/user",- "/fo",- "csv",- "/nh",- ]);- expect(identity.status).toBe(0);- const sid = /"(S-1-(?:\d+-)*\d+)"\s*$/u.exec(identity.stdout)?.[1];- expect(sid).toBeDefined();+ const sid = windowsUserSid();for (const credential of [auth, nestedAuth]) {const unsafe = windowsTestCommand("icacls.exe", [diff --git a/sdk/typescript/tests-ts/targets.test.ts b/sdk/typescript/tests-ts/targets.test.tsindex b7e7b9b86..42e184d0f 100644--- a/sdk/typescript/tests-ts/targets.test.ts+++ b/sdk/typescript/tests-ts/targets.test.ts@@ -60,6 +60,27 @@ function git(repo: string, ...args: string[]): string {return execFileSync("git", args, { cwd: repo, encoding: "utf8" }).trim();}+function validateCommittedDiffWithCredentialConfig(repo: string) {+ return spawnSync(+ process.execPath,+ [+ "-e",+ "const { DiffTarget, normalizeTarget, validateCommittedDiffCheckout } = await import(process.argv[1]); const target = await normalizeTarget(process.argv[2], DiffTarget.refs({ base: 'HEAD' })); await validateCommittedDiffCheckout(process.argv[2], target);",+ fileURLToPath(new URL("../src/targets.ts", import.meta.url)),+ repo,+ ],+ {+ encoding: "utf8",+ env: {+ ...process.env,+ GIT_CONFIG_COUNT: "1",+ GIT_CONFIG_KEY_0: "http.extraHeader",+ GIT_CONFIG_VALUE_0: "SYNTHETIC_GIT_CREDENTIAL",+ },+ },+ );+}+async function createRepositoryGitShim(directory: string,marker: string,@@ -381,24 +402,7 @@ describe("scan target normalization", () => {await chmod(hook, 0o700);git(repo, "config", "core.fsmonitor", hook);- const result = spawnSync(- process.execPath,- [- "-e",- "const { DiffTarget, normalizeTarget, validateCommittedDiffCheckout } = await import(process.argv[1]); const target = await normalizeTarget(process.argv[2], DiffTarget.refs({ base: 'HEAD' })); await validateCommittedDiffCheckout(process.argv[2], target);",- fileURLToPath(new URL("../src/targets.ts", import.meta.url)),- repo,- ],- {- encoding: "utf8",- env: {- ...process.env,- GIT_CONFIG_COUNT: "1",- GIT_CONFIG_KEY_0: "http.extraHeader",- GIT_CONFIG_VALUE_0: "SYNTHETIC_GIT_CREDENTIAL",- },- },- );+ const result = validateCommittedDiffWithCredentialConfig(repo);expect(result.status).toBe(0);expect(existsSync(leaked)).toBe(false);@@ -433,24 +437,7 @@ describe("scan target normalization", () => {);await utimes(join(repo, "src", "app.ts"), new Date(0), new Date(0));- const result = spawnSync(- process.execPath,- [- "-e",- "const { DiffTarget, normalizeTarget, validateCommittedDiffCheckout } = await import(process.argv[1]); const target = await normalizeTarget(process.argv[2], DiffTarget.refs({ base: 'HEAD' })); await validateCommittedDiffCheckout(process.argv[2], target);",- fileURLToPath(new URL("../src/targets.ts", import.meta.url)),- repo,- ],- {- encoding: "utf8",- env: {- ...process.env,- GIT_CONFIG_COUNT: "1",- GIT_CONFIG_KEY_0: "http.extraHeader",- GIT_CONFIG_VALUE_0: "SYNTHETIC_GIT_CREDENTIAL",- },- },- );+ const result = validateCommittedDiffWithCredentialConfig(repo);expect(result.status).toBe(0);expect(existsSync(executed)).toBe(true);