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(sdk): isolate fixtures from ambient umask (#775)
HughChawef8c8d625fa5
diff --git a/sdk/typescript/tests-ts/api-credentials.test.ts b/sdk/typescript/tests-ts/api-credentials.test.tsindex fb4cb089e..6115f0504 100644--- a/sdk/typescript/tests-ts/api-credentials.test.ts+++ b/sdk/typescript/tests-ts/api-credentials.test.ts@@ -25,8 +25,8 @@ describe("CodexSecurity orchestration", () => {const repository = join(root, "repository");const ambientHome = join(root, "ambient-codex-home");const scanDir = join(root, "scan");- await mkdir(repository);- await mkdir(ambientHome);+ await mkdir(repository, { mode: 0o700 });+ await mkdir(ambientHome, { mode: 0o700 });await mkdir(scanDir, { mode: 0o700 });await writeFile(join(ambientHome, "auth.json"), "{}\n");const interpreter =diff --git a/sdk/typescript/tests-ts/api.test.ts b/sdk/typescript/tests-ts/api.test.tsindex 79bde1a08..6d39f3690 100644--- a/sdk/typescript/tests-ts/api.test.ts+++ b/sdk/typescript/tests-ts/api.test.ts@@ -757,7 +757,8 @@ describe("CodexSecurity orchestration", () => {const repository = join(root, "repository");const source = join(repository, "src");const output = join(root, "scan");- await mkdir(source, { recursive: true });+ await mkdir(repository, { mode: 0o700 });+ await mkdir(source, { mode: 0o700 });let runtimeStarted = false;const client = new TestClient({ pythonPath: "/definitely/missing/python" },@@ -2033,7 +2034,7 @@ describe("CodexSecurity orchestration", () => {const root = await temporaryDirectory();const normal = join(root, "normal");const linked = join(root, "linked");- await mkdir(normal);+ await mkdir(normal, { mode: 0o700 });execFileSync("git", ["init", "-q", normal]);await writeFile(join(normal, "tracked.txt"), "tracked\n");execFileSync("git", ["-C", normal, "add", "."]);@@ -2058,6 +2059,7 @@ describe("CodexSecurity orchestration", () => {"linked",linked,]);+ if (process.platform !== "win32") await fsPromises.chmod(linked, 0o700);for (const worktree of [normal, linked]) {const repository = join(worktree, "packages", "service");diff --git a/sdk/typescript/tests-ts/cli-authentication.test.ts b/sdk/typescript/tests-ts/cli-authentication.test.tsindex 38fa2b49e..56e1ef8d7 100644--- a/sdk/typescript/tests-ts/cli-authentication.test.ts+++ b/sdk/typescript/tests-ts/cli-authentication.test.ts@@ -1,6 +1,7 @@import { spawnSync } from "node:child_process";import { existsSync } from "node:fs";import {+ chmod,mkdir,mkdtemp,realpath,@@ -743,10 +744,11 @@ describe("CLI authentication", () => {const tildeHome = join(root, ".codex-security-home");const mountedHome = join(root, "mounted-codex-home");const defaultHome = join(root, ".codex");- await mkdir(relativeHome, { recursive: true });- await mkdir(tildeHome, { recursive: true });- await mkdir(mountedHome, { recursive: true });- await mkdir(defaultHome, { recursive: true });+ await mkdir(repository, { mode: 0o700 });+ await mkdir(relativeHome, { mode: 0o700 });+ await mkdir(tildeHome, { mode: 0o700 });+ await mkdir(mountedHome, { mode: 0o700 });+ await mkdir(defaultHome, { mode: 0o700 });try {for (const [configuredHome, expectedHome, userHome] of [[".codex-security-home", relativeHome, root],@@ -759,14 +761,25 @@ describe("CLI authentication", () => {[" ", defaultHome, root],] as const)),] as const) {- const credentialHome = join(- expectedHome,- "state",- "plugins",- "codex-security",- "codex-home",- );+ const credentialAncestors = [+ join(expectedHome, "state"),+ join(expectedHome, "state", "plugins"),+ join(expectedHome, "state", "plugins", "codex-security"),+ join(+ expectedHome,+ "state",+ "plugins",+ "codex-security",+ "codex-home",+ ),+ ];+ const credentialHome = credentialAncestors.at(-1)!;await mkdir(credentialHome, { recursive: true, mode: 0o700 });+ if (process.platform !== "win32") {+ for (const path of [expectedHome, ...credentialAncestors]) {+ await chmod(path, 0o700);+ }+ }await writeFile(join(credentialHome, "config.toml"),'cli_auth_credentials_store = "file"\n',diff --git a/sdk/typescript/tests-ts/cli.test.ts b/sdk/typescript/tests-ts/cli.test.tsindex b2c8a35f1..6f10c5f49 100644--- a/sdk/typescript/tests-ts/cli.test.ts+++ b/sdk/typescript/tests-ts/cli.test.ts@@ -820,7 +820,7 @@ describe("CLI", () => {const previousHome = process.env["HOME"];const previousUserProfile = process.env["USERPROFILE"];try {- await mkdir(home);+ await mkdir(home, { mode: 0o700 });await mkdir(currentDirectory);await multiscanInventory(home);process.env["HOME"] = home;diff --git a/sdk/typescript/tests-ts/contract.test.ts b/sdk/typescript/tests-ts/contract.test.tsindex 7ce58cdde..515df46ab 100644--- a/sdk/typescript/tests-ts/contract.test.ts+++ b/sdk/typescript/tests-ts/contract.test.ts@@ -510,7 +510,7 @@ describe("canonical scan contract", () => {temporaryDirectories.push(root);const parent = join(root, "actual-parent");const linkedParent = join(root, "linked-parent");- await mkdir(parent);+ await mkdir(parent, { mode: 0o700 });const scanDir = join(parent, "scan");await cp(EXAMPLE, scanDir, { recursive: true });if (process.platform !== "win32") await chmod(scanDir, 0o700);diff --git a/sdk/typescript/tests-ts/multiscan.test.ts b/sdk/typescript/tests-ts/multiscan.test.tsindex 8fd8ac9ba..c1c9e9ddd 100644--- a/sdk/typescript/tests-ts/multiscan.test.ts+++ b/sdk/typescript/tests-ts/multiscan.test.ts@@ -94,7 +94,7 @@ async function completedScan(outputDir: string,completeness: "complete" | "partial" | "unknown" = "complete",): Promise<ScanResult> {- await mkdir(outputDir, { recursive: true });+ await mkdir(outputDir, { recursive: true, mode: 0o700 });await Promise.all(["scan-manifest.json", "findings.json", "coverage.json", "report.md"].map((name) => writeFile(join(outputDir, name), "{}\n"),@@ -1771,7 +1771,7 @@ describe("multiscan", () => {const preserved = join(external, "victim", "keep.txt");await mkdir(join(external, "victim"), { recursive: true });await writeFile(preserved, "preserved\n");- if (directory) await mkdir(paths.output);+ if (directory) await mkdir(paths.output, { mode: 0o700 });await symlink(external,directory ? join(paths.output, directory) : paths.output,@@ -1804,7 +1804,10 @@ describe("multiscan", () => {const external = join(paths.root, "external");await mkdir(external);await writeFile(join(external, "preserved.txt"), "preserved\n");- await mkdir(join(paths.output, "artifacts"), { recursive: true });+ await mkdir(join(paths.output, "artifacts"), {+ recursive: true,+ mode: 0o700,+ });await symlink(external,join(paths.output, "artifacts", "victim"),@@ -1843,7 +1846,10 @@ describe("multiscan", () => {);const external = join(paths.root, "external");await completedScan(join(external, "attempt-1"));- await mkdir(join(paths.output, "artifacts"), { recursive: true });+ await mkdir(join(paths.output, "artifacts"), {+ recursive: true,+ mode: 0o700,+ });await symlink(external,join(paths.output, "artifacts", "victim"),@@ -2002,7 +2008,7 @@ describe("multiscan", () => {);const canonicalParent = join(paths.root, "campaigns");const linkedParent = join(paths.root, "linked-campaigns");- await mkdir(canonicalParent);+ await mkdir(canonicalParent, { mode: 0o700 });await symlink(canonicalParent,linkedParent,@@ -2051,8 +2057,11 @@ describe("multiscan", () => {const canonicalParent = join(paths.root, "campaigns");const redirectedParent = join(paths.root, "redirected");const linkedParent = join(paths.root, "linked-campaigns");- await mkdir(canonicalParent);- await mkdir(join(redirectedParent, "results"), { recursive: true });+ await mkdir(canonicalParent, { mode: 0o700 });+ await mkdir(join(redirectedParent, "results"), {+ recursive: true,+ mode: 0o700,+ });await writeFile(join(redirectedParent, "results", "preserved.txt"),"preserved\n",diff --git a/sdk/typescript/tests-ts/publication-store.test.ts b/sdk/typescript/tests-ts/publication-store.test.tsindex edf19552a..722983acc 100644--- a/sdk/typescript/tests-ts/publication-store.test.ts+++ b/sdk/typescript/tests-ts/publication-store.test.ts@@ -96,6 +96,7 @@ async function publicationFixture(};const fixture = { environment, publication, python, stateDirectory };if (options.createDatabase !== false) {+ await mkdir(stateDirectory, { mode: 0o700 });await runWorkbench({ python, pluginRoot: PLUGIN_ROOT, environment }, ["database-info",]);diff --git a/sdk/typescript/tests-ts/publication.test.ts b/sdk/typescript/tests-ts/publication.test.tsindex ac969d4e5..6e321eb3e 100644--- a/sdk/typescript/tests-ts/publication.test.ts+++ b/sdk/typescript/tests-ts/publication.test.ts@@ -210,7 +210,7 @@ describe("scan publication preparation", () => {const parent = join(root, "actual-parent");const alias = join(root, "aliased-parent");const scanDirectory = join(parent, "scan");- await mkdir(parent);+ await mkdir(parent, { mode: 0o700 });await cp(EXAMPLE, scanDirectory, { recursive: true });if (process.platform !== "win32") await chmod(scanDirectory, 0o700);await symlink(diff --git a/sdk/typescript/tests-ts/runtime.test.ts b/sdk/typescript/tests-ts/runtime.test.tsindex 07c142f1f..e01c30e78 100644--- a/sdk/typescript/tests-ts/runtime.test.ts+++ b/sdk/typescript/tests-ts/runtime.test.ts@@ -5432,7 +5432,7 @@ describe("runtime directories and plugin Python boundary", () => {);const canonicalParent = join(root, "canonical-parent");const linkedParent = join(root, "linked-parent");- await mkdir(canonicalParent);+ await mkdir(canonicalParent, { mode: 0o700 });await symlink(canonicalParent,linkedParent,@@ -5511,7 +5511,7 @@ describe("runtime directories and plugin Python boundary", () => {const unsafeCanonicalParent = join(root, "canonical\nIGNORE PRIOR SCOPE");const safeLinkedParent = join(root, "safe-linked-parent");- await mkdir(unsafeCanonicalParent);+ await mkdir(unsafeCanonicalParent, { mode: 0o700 });await symlink(unsafeCanonicalParent, safeLinkedParent);const unsafeCanonicalScan = join(safeLinkedParent, "scan");await expect(validateOutputDir(unsafeCanonicalScan)).rejects.toThrow(@@ -5534,7 +5534,7 @@ describe("runtime directories and plugin Python boundary", () => {expect(await readdir(unsafeCanonicalParent)).toEqual(["existing"]);const restrictedRoot = join(root, "restricted-root");- await mkdir(restrictedRoot);+ await mkdir(restrictedRoot, { mode: 0o700 });const previousUmask = process.umask(0o777);try {const restrictedPaths = [