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
[codex-security] Support nested Git repositories in scan snapshots (#116)
ianw-oai9c7634b5d08b
diff --git a/sdk/typescript/_bundled_plugin/scripts/workbench_target.py b/sdk/typescript/_bundled_plugin/scripts/workbench_target.pyindex 9d1ce9c33..c39c9635a 100644--- a/sdk/typescript/_bundled_plugin/scripts/workbench_target.py+++ b/sdk/typescript/_bundled_plugin/scripts/workbench_target.py@@ -143,6 +143,13 @@ def worktree_content_digest_for_context(b"untracked-content",os.fsencode(os.readlink(path)),)+ elif stat.S_ISDIR(metadata.st_mode):+ update_digest_field(digest, b"untracked-kind", b"directory")+ update_digest_field(+ digest,+ b"untracked-content",+ directory_content_digest(path.resolve()).encode(),+ )elif stat.S_ISREG(metadata.st_mode):content_digest = hashlib.sha256()content_size = 0@@ -419,7 +426,13 @@ def copy_git_worktree_files(source: Path, destination: Path, excluded: tuple[Patdestination_path.symlink_to(os.readlink(source_path))elif stat.S_ISREG(metadata.st_mode):shutil.copy2(source_path, destination_path, follow_symlinks=False)- elif not stat.S_ISDIR(metadata.st_mode):+ elif stat.S_ISDIR(metadata.st_mode):+ nested_git_dir = git_output(source_path, "rev-parse", "--absolute-git-dir")+ if nested_git_dir is None:+ raise SystemExit(f"Could not inspect nested Git working tree: {relative}")+ copy_git_worktree_files(source_path, destination_path, excluded)+ (destination_path / ".git").write_text(f"gitdir: {nested_git_dir}\n")+ else:raise SystemExit(f"Unsupported Git working-tree file type: {relative}")copied_target = destination if pathspec == "." else destination / pathspeccopied_target.mkdir(parents=True, exist_ok=True)diff --git a/sdk/typescript/tests-ts/scan-recovery.test.ts b/sdk/typescript/tests-ts/scan-recovery.test.tsindex cf9af4850..d095824f6 100644--- a/sdk/typescript/tests-ts/scan-recovery.test.ts+++ b/sdk/typescript/tests-ts/scan-recovery.test.ts@@ -115,7 +115,7 @@ async function workbench(fixture: ScanFixture, args: readonly string[]) {}async function startDraftScan(- repositoryKind: "directory" | "clean" | "dirty" = "directory",+ repositoryKind: "directory" | "clean" | "dirty" | "nested" = "directory",): Promise<ScanFixture> {const root = await realpath(await mkdtemp(join(tmpdir(), "codex-security-scan-recovery-")),@@ -153,6 +153,15 @@ async function startDraftScan(if (repositoryKind === "dirty") {await writeFile(join(target, "src", "extract.py"), "# changed fixture\n");}+ if (repositoryKind === "nested") {+ const nested = join(target, "nested");+ await mkdir(nested);+ await writeFile(join(nested, "source.py"), "# nested fixture\n");+ const initialized = spawnSync("git", ["init", "--quiet", nested], {+ encoding: "utf8",+ });+ expect(initialized.status, initialized.stderr).toBe(0);+ }}const fixture: ScanFixture = {@@ -246,8 +255,8 @@ describe("malformed scan artifact recovery", () => {});});- test("returns authoritative clean and dirty Git target contracts", async () => {- for (const kind of ["clean", "dirty"] as const) {+ test("returns authoritative clean, dirty, and nested Git target contracts", async () => {+ for (const kind of ["clean", "dirty", "nested"] as const) {const fixture = await startDraftScan(kind);const registration = fixture.registration;const contract = registration["contract"] as {@@ -276,6 +285,31 @@ describe("malformed scan artifact recovery", () => {/^codex-security-snapshot\/v1:sha256:[a-f0-9]{64}$/,);}+ if (kind === "nested") {+ const copied = spawnSync(+ fixture.python,+ [+ "-I",+ "-B",+ "-c",+ [+ "import sys",+ "from pathlib import Path",+ "sys.path.insert(0, sys.argv[1])",+ "import workbench_target as target",+ "source = Path(sys.argv[2])",+ "checkout = target.copy_git_worktree_files(source, Path(sys.argv[3]), ())",+ "git_dir = Path(target.git_output(source, 'rev-parse', '--absolute-git-dir'))",+ "assert target.worktree_content_digest_for_context(checkout, '.', git_dir=git_dir, work_tree=checkout) == target.worktree_content_digest(source)",+ ].join("\n"),+ join(PLUGIN_ROOT, "scripts"),+ fixture.repository,+ join(fixture.stateDir, "checkout"),+ ],+ { encoding: "utf8" },+ );+ expect(copied.status, copied.stderr).toBe(0);+ }}});