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(history): use chronological cutoffs for explicit comparisons (#1774)
Michael D'Angelo0bfdf7229399
diff --git a/plugins/codex-security/scripts/workbench_scan_history.py b/plugins/codex-security/scripts/workbench_scan_history.pyindex e0654d6a7..0f5eacc33 100644--- a/plugins/codex-security/scripts/workbench_scan_history.py+++ b/plugins/codex-security/scripts/workbench_scan_history.py@@ -667,14 +667,14 @@ def compare_scans(for pair in related]if include_matching_inputs:+ after_key = (timestamp_key(after["started_at"]), after["id"])known_scan_ids = {scan["id"]for scan in connection.execute(- "SELECT * FROM scans WHERE status = 'complete' "- "AND (started_at < ? OR (started_at = ? AND id <= ?))",- (after["started_at"], after["started_at"], after["id"]),+ "SELECT id, started_at, target_id, target_path FROM scans WHERE status = 'complete'")- if _same_repository(scan, after)+ if (timestamp_key(scan["started_at"]), scan["id"]) <= after_key+ and _same_repository(scan, after)}excluded_pairs = {(before["id"], after["id"]), (after["id"], before["id"])}known_groups = _known_finding_groups(diff --git a/plugins/codex-security/tests/test_workbench_scan_history.py b/plugins/codex-security/tests/test_workbench_scan_history.pyindex c3b6ed26b..b2cd6eb6c 100644--- a/plugins/codex-security/tests/test_workbench_scan_history.py+++ b/plugins/codex-security/tests/test_workbench_scan_history.py@@ -7,6 +7,7 @@ import sqlite3import subprocessimport sysimport uuid+from argparse import Namespacefrom pathlib import Pathfrom typing import Any@@ -18,6 +19,7 @@ from workbench_test_support import (fail_scan,get_scan,initialize_git_repository,+ load_script,mark_deep_coordinator_succeeded,resume_deep_scan,run_workbench,@@ -1098,6 +1100,97 @@ def test_semantic_scan_comparison_caches_matches_and_exposes_related_findings(assert latest_finding["knownSince"] == known_since+ "timestamps",+ [+ (+ "2026-08-01T03:00:00+02:00",+ "2026-08-01T01:15:00Z",+ "2026-08-01T01:30:00Z",+ "2026-08-01T00:45:00-01:00",+ ),+ (+ "2026-08-01T01:00:00Z",+ "2026-08-01T01:00:00.000001Z",+ "2026-08-01T01:00:00.000002Z",+ "2026-08-01T01:00:00.000003Z",+ ),+ (+ "2026-08-01t03:00:00.000000+02:00",+ "2026-08-01T01:00:00Z",+ "2026-08-01T01:00:00.0Z",+ "2026-08-01T01:00:00.000Z",+ ),+ ],+ ids=["offsets", "microseconds", "equal-instants"],+)+def test_explicit_comparison_uses_chronological_matching_cutoff(+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch, timestamps: tuple[str, ...]+) -> None:+ state_dir = tmp_path / "state"+ repository = tmp_path / "repository"+ repository.mkdir()+ scans = sorted(+ (+ create_cli_scan(+ state_dir, tmp_path / "scans", repository, identity_anchor=f"synthetic-{index}"+ )+ for index in range(4)+ ),+ key=lambda scan: scan["scanId"],+ )+ middle, after, future = scans[1:]+ findings = [get_scan(state_dir, scan["scanId"])["scan"]["findings"][0] for scan in scans]+ for left, right in ((0, 1), (1, 3)):+ save_scan_matches(+ state_dir,+ scans[left],+ scans[right],+ confirmed_match(findings[left]["occurrenceId"], findings[right]["occurrenceId"]),+ )+ with sqlite3.connect(state_dir / "workbench.sqlite3") as connection:+ connection.executemany(+ "UPDATE scans SET started_at = ? WHERE id = ?",+ [(timestamp, scan["scanId"]) for timestamp, scan in zip(timestamps, scans)],+ )+ original = list(connection.iterdump())+ expected = [sorted(finding["findingId"] for finding in findings[:2])]++ for before_scan, after_scan in ((middle, after), (after, middle)):+ compared = compare_scan_pair(+ state_dir, before_scan, after_scan, "--include-matching-inputs"+ )+ assert (compared["beforeScanId"], compared["afterScanId"]) == (+ before_scan["scanId"],+ after_scan["scanId"],+ )+ assert compared["matchingInputs"]["knownFindingGroups"] == expected++ history = load_script("workbench_scan_history")++ def unexpected_git_lookup(*_args: Any) -> str:+ raise AssertionError("Future scans must not trigger repository discovery")++ monkeypatch.setattr(history, "git_output", unexpected_git_lookup)+ with sqlite3.connect(state_dir / "workbench.sqlite3") as connection:+ assert list(connection.iterdump()) == original+ connection.row_factory = sqlite3.Row+ connection.execute(+ "UPDATE scans SET target_id = NULL, target_path = ? WHERE id = ?",+ (str(tmp_path / "future-repository"), future["scanId"]),+ )+ compared = history.compare_scans(+ connection,+ Namespace(before_scan_id=middle["scanId"], after_scan_id=after["scanId"]),+ require_scan=lambda db, scan_id: db.execute(+ "SELECT * FROM scans WHERE id = ?", (scan_id,)+ ).fetchone(),+ read_coverage=lambda _: {},+ include_matching_inputs=True,+ )+ assert compared["matchingInputs"]["knownFindingGroups"] == expected++def test_semantic_scan_matching_backfills_legacy_finding_details(tmp_path: Path) -> None:state_dir = tmp_path / "state"repository = tmp_path / "repository"diff --git a/sdk/typescript/tests-ts/workbench-scan-history.test.ts b/sdk/typescript/tests-ts/workbench-scan-history.test.tsindex 57a4a335f..169556bd5 100644--- a/sdk/typescript/tests-ts/workbench-scan-history.test.ts+++ b/sdk/typescript/tests-ts/workbench-scan-history.test.ts@@ -106,7 +106,7 @@ for index, (scan, repository) in enumerate([('before', 'selected'), ('after', 'selected')]):connection.execute('INSERT INTO scans VALUES (?, NULL, ?, ?, ?)',- (scan, str(Path(sys.argv[2]) / repository), 'complete', str(index)))+ (scan, str(Path(sys.argv[2]) / repository), 'complete', f'2026-08-01T00:00:0{index}Z'))connection.executemany('INSERT INTO finding_occurrences VALUES (?, ?, ?)', [('unrelated-first', 'unrelated-identity-a', 'unrelated-before'),('unrelated-second', 'unrelated-identity-b', 'unrelated-after')