Skip to content

OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security

test: share completed scan fixtures (#1620)

Michael D'Angelo68ddbdce0c9e
diff --git a/.github/workflows/action-ci.yml b/.github/workflows/action-ci.yml
index a0b4a367f..bd68ed263 100644
--- a/.github/workflows/action-ci.yml
+++ b/.github/workflows/action-ci.yml
@@ -5,6 +5,7 @@ on:
paths:
- action.yml
- github-action/**
+ - plugins/codex-security/examples/completed-scan/**
- .github/workflows/action-ci.yml
pull_request: *action-changes
workflow_dispatch:
diff --git a/github-action/tests/fixtures.ts b/github-action/tests/fixtures.ts
new file mode 100644
index 000000000..aaf953a29
--- /dev/null
+++ b/github-action/tests/fixtures.ts
@@ -0,0 +1,13 @@
+import { cp, readFile, writeFile } from 'node:fs/promises';
+import { join } from 'node:path';
+
+export async function copyCompletedScan(destination: string): Promise<void> {
+ await cp(new URL('./fixtures/completed-scan/', import.meta.url), destination, { recursive: true });
+ for (const name of ['scan-manifest.json', 'findings.json', 'coverage.json']) {
+ await cp(new URL(`../../plugins/codex-security/examples/completed-scan/${name}`, import.meta.url), join(destination, name));
+ }
+ const manifestPath = join(destination, 'scan-manifest.json');
+ const manifest = JSON.parse(await readFile(manifestPath, 'utf8'));
+ Object.assign(manifest.scan.target, { kind: 'git_revision', revision: 'a'.repeat(40) });
+ await writeFile(manifestPath, JSON.stringify(manifest));
+}
diff --git a/github-action/tests/fixtures/completed-scan/coverage.json b/github-action/tests/fixtures/completed-scan/coverage.json
deleted file mode 100644
index deba18fa3..000000000
--- a/github-action/tests/fixtures/completed-scan/coverage.json
+++ /dev/null
@@ -1,22 +0,0 @@
-{
- "documentType": "codex-security.coverage",
- "schemaVersion": "1.0",
- "scanId": "scan_example_001",
- "mode": "repository",
- "completeness": "complete",
- "inventoryStrategy": "repository",
- "includePaths": [
- "."
- ],
- "excludePaths": [],
- "surfaces": [
- {
- "id": "surface_archive_extraction",
- "label": "Archive extraction",
- "disposition": "reported",
- "receiptRefs": []
- }
- ],
- "explicitExclusions": [],
- "deferred": []
-}
diff --git a/github-action/tests/fixtures/completed-scan/findings.json b/github-action/tests/fixtures/completed-scan/findings.json
deleted file mode 100644
index fc0ef605d..000000000
--- a/github-action/tests/fixtures/completed-scan/findings.json
+++ /dev/null
@@ -1,57 +0,0 @@
-{
- "documentType": "codex-security.findings",
- "schemaVersion": "1.0",
- "scanId": "scan_example_001",
- "findings": [
- {
- "findingId": "csf_852f90d6e1177502ff113d4a",
- "occurrenceId": "occ_e79cb19591e696572a1c22be",
- "ruleId": "path-traversal.archive-extraction",
- "identity": {
- "anchor": "archive-entry-write-without-containment"
- },
- "fingerprints": {
- "algorithm": "codex-security/v1",
- "primary": "codex-security/v1:sha256:990a4a6a2ec18440dd47eac4d7256c0ee2c02db1b43104720cab3cbe9db706ca"
- },
- "title": "Unsafe archive extraction can escape the output directory",
- "summary": "An attacker-controlled path reaches a filesystem write without containment validation.",
- "severity": {
- "level": "high",
- "score": 8.1,
- "scoringSystem": "CVSS:3.1"
- },
- "confidence": {
- "level": "high",
- "rationale": "Direct source trace reaches the filesystem write without a containment check."
- },
- "taxonomy": {
- "category": "path-traversal",
- "cwe": [
- "CWE-22"
- ]
- },
- "locations": [
- {
- "path": "src/extract.py",
- "startLine": 41,
- "endLine": 44,
- "role": "sink"
- }
- ],
- "remediation": "Normalize destinations and reject entries that escape the extraction root.",
- "validation": null,
- "attackPath": null,
- "remediationTests": [
- "Assert that extracting an archive entry named `../escape.txt` fails without writing outside the extraction root."
- ],
- "preventiveControls": [
- "Route all archive extraction through one helper that normalizes and validates destination paths."
- ],
- "provenance": {
- "source": "local_plugin"
- },
- "extensions": {}
- }
- ]
-}
diff --git a/github-action/tests/fixtures/completed-scan/scan-manifest.json b/github-action/tests/fixtures/completed-scan/scan-manifest.json
deleted file mode 100644
index addd80c4b..000000000
--- a/github-action/tests/fixtures/completed-scan/scan-manifest.json
+++ /dev/null
@@ -1,43 +0,0 @@
-{
- "documentType": "codex-security.scan-manifest",
- "schemaVersion": "1.0",
- "scan": {
- "id": "scan_example_001",
- "producer": {
- "name": "codex-security-plugin",
- "version": "0.1.0"
- },
- "status": "completed",
- "startedAt": "2026-05-31T18:00:00Z",
- "completedAt": "2026-05-31T18:09:00Z",
- "sealedAt": "2026-05-31T18:09:00Z",
- "target": {
- "kind": "git_revision",
- "targetId": "target_sha256_example",
- "displayName": "example/repo",
- "remote": "https://github.com/example/repo",
- "revision": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
- "snapshotDigest": "codex-security-snapshot/v1:sha256:ed88f96a4c1a06603a41b3f261f59c3de2555c367ef6ad3bb8b9e483495d34eb"
- },
- "scope": {
- "includePaths": [
- "."
- ],
- "excludePaths": []
- },
- "coverageRef": "coverage.json",
- "findingsRef": "findings.json",
- "artifacts": [
- {
- "path": "findings.json",
- "sha256": "a6dc4521d6478828224fbafc33585401a47bfeb0e56e07b5d2886e8a29937f2f",
- "mediaType": "application/json"
- },
- {
- "path": "coverage.json",
- "sha256": "d55b9b98d48323b4659dfee6531ec83ec538f2084325412b7188bf85ad68b01b",
- "mediaType": "application/json"
- }
- ]
- }
-}
diff --git a/github-action/tests/main.test.ts b/github-action/tests/main.test.ts
index 176de4437..8e87ccc54 100644
--- a/github-action/tests/main.test.ts
+++ b/github-action/tests/main.test.ts
@@ -1,6 +1,6 @@
import { test, type TestContext } from 'node:test';
import assert from 'node:assert/strict';
-import { cp, mkdir, mkdtemp, readFile, realpath, rm, writeFile } from 'node:fs/promises';
+import { mkdir, mkdtemp, readFile, realpath, rm, writeFile } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { basename, join } from 'node:path';
import { execFileSync } from 'node:child_process';
@@ -11,6 +11,7 @@ import { INPUT_NAMES } from '../src/inputs.js';
import { gitEnvironment } from '../src/targets.js';
import type { Runtime } from '../src/runtime.js';
import type { ProcessResult } from '../src/process.js';
+import { copyCompletedScan } from './fixtures.js';
type Scenario = 'schedule' | 'pr' | 'policy-pr';
const inputKey = (name: string): string => `INPUT_${name.toUpperCase()}`;
@@ -95,7 +96,7 @@ async function harness(t: TestContext, scenario: Scenario = 'schedule') {
let capturedArgs: readonly string[] = [];
let capturedEnvironment: NodeJS.ProcessEnv = {};
async function reports(): Promise<void> {
- await cp(new URL('./fixtures/completed-scan/', import.meta.url), runtime.resultsDirectory, { recursive: true });
+ await copyCompletedScan(runtime.resultsDirectory);
const manifestPath = join(runtime.resultsDirectory, 'scan-manifest.json');
const coveragePath = join(runtime.resultsDirectory, 'coverage.json');
const sarifPath = join(runtime.resultsDirectory, 'exports/results.sarif');
diff --git a/github-action/tests/results.test.ts b/github-action/tests/results.test.ts
index 38cb1c405..eeb8685d6 100644
--- a/github-action/tests/results.test.ts
+++ b/github-action/tests/results.test.ts
@@ -1,16 +1,17 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
-import { cp, mkdtemp, readFile, writeFile, rm, realpath, symlink, link } from 'node:fs/promises';
+import { mkdtemp, readFile, writeFile, rm, realpath, symlink, link } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { execFileSync } from 'node:child_process';
import { analyzeResults, readReportFile, type ResultOptions } from '../src/results.js';
import { collectReports } from '../src/artifacts.js';
+import { copyCompletedScan } from './fixtures.js';
async function fixture(t: { after(fn: () => Promise<void>): void }): Promise<ResultOptions> {
const root = await realpath(await mkdtemp(join(tmpdir(), 'codex-results-test-')));
t.after(() => rm(root, { recursive: true, force: true }));
- await cp(new URL('./fixtures/completed-scan/', import.meta.url), root, { recursive: true });
+ await copyCompletedScan(root);
const document = async (name: string) => JSON.parse(await readFile(join(root, name), 'utf8'));
return {
resultsDirectory: root, scannedSha: 'a'.repeat(40), exitCode: 0, publishable: true,
diff --git a/plugins/codex-security/tests/test_finalize_scan_contract.py b/plugins/codex-security/tests/test_finalize_scan_contract.py
index d6365cd14..1919dc4e9 100644
--- a/plugins/codex-security/tests/test_finalize_scan_contract.py
+++ b/plugins/codex-security/tests/test_finalize_scan_contract.py
@@ -50,9 +50,9 @@ class FinalizeScanContractTest(ScanFixtureTestCase):
self.coverage["scanId"] = "scan_001"
self.coverage["includePaths"] = ["src/"]
- def write_sealed_scan(self) -> None:
+ def write_sealed_scan(self) -> tuple[dict, dict, dict]:
self.write_scan()
- FINALIZER.finalize_scan(self.scan_dir)
+ return FINALIZER.finalize_scan(self.scan_dir)
def compatible_finding(self, findings: dict) -> dict:
original = copy.deepcopy(findings)
diff --git a/plugins/codex-security/tests/test_portable_artifact_paths.py b/plugins/codex-security/tests/test_portable_artifact_paths.py
index afcf00842..85278b9f8 100644
--- a/plugins/codex-security/tests/test_portable_artifact_paths.py
+++ b/plugins/codex-security/tests/test_portable_artifact_paths.py
@@ -17,8 +17,7 @@ def scan_case():
def test_rejects_case_aliases_for_sealed_artifacts(scan_case) -> None:
- scan_case.write_scan()
- FINALIZER.finalize_scan(scan_case.scan_dir)
+ scan_case.write_sealed_scan()
manifest = scan_case.read_json("scan-manifest.json")
artifact = copy.deepcopy(manifest["scan"]["artifacts"][0])
artifact["path"] = artifact["path"].upper()
@@ -45,8 +44,7 @@ def test_rejects_case_aliases_for_sealed_artifacts(scan_case) -> None:
],
)
def test_rejects_windows_ambiguous_artifact_paths(scan_case, path: str) -> None:
- scan_case.write_scan()
- FINALIZER.finalize_scan(scan_case.scan_dir)
+ scan_case.write_sealed_scan()
manifest = scan_case.read_json("scan-manifest.json")
manifest["scan"]["artifacts"].append(
{"path": path, "sha256": "0" * 64, "mediaType": "text/plain"}
@@ -62,6 +60,5 @@ def test_preserves_unix_valid_source_paths(scan_case) -> None:
scan_case.coverage["includePaths"] = [source]
scan_case.coverage["surfaces"][0]["paths"] = [source]
scan_case.findings["findings"][0]["locations"][0]["path"] = source
- scan_case.write_scan()
- _, findings, _ = FINALIZER.finalize_scan(scan_case.scan_dir)
+ _, findings, _ = scan_case.write_sealed_scan()
assert findings["findings"][0]["locations"][0]["path"] == source