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(reports): omit excerpts for unknown diff target kinds (#515)
Sylvester Kaczmarekaf973f94224a
diff --git a/plugins/codex-security/scripts/workbench_source_scopes.py b/plugins/codex-security/scripts/workbench_source_scopes.pyindex c3204e826..4fedcd965 100644--- a/plugins/codex-security/scripts/workbench_source_scopes.py+++ b/plugins/codex-security/scripts/workbench_source_scopes.py@@ -275,7 +275,10 @@ def capture_source_scopes(def load_source_scopes(scan: sqlite3.Row, target: Path, requested: list[str]) -> tuple[Path, str, list[dict[str, str]]] | None:- if "diff_target_kind" in scan.keys() and scan["diff_target_kind"] == "working_tree":+ kind = scan["diff_target_kind"] if "diff_target_kind" in scan.keys() else None+ if kind == "working_tree" or (+ "mode" in scan.keys() and scan["mode"] == "diff" and kind not in ("commit", "range")+ ):return Nonesaved = scan["source_scopes_json"] if "source_scopes_json" in scan.keys() else Nonepaths = {PurePosixPath(path).as_posix() for path in requested}diff --git a/plugins/codex-security/tests/test_git_inventory_regressions.py b/plugins/codex-security/tests/test_git_inventory_regressions.pyindex 1de7926f4..7cb3d660d 100644--- a/plugins/codex-security/tests/test_git_inventory_regressions.py+++ b/plugins/codex-security/tests/test_git_inventory_regressions.py@@ -124,6 +124,42 @@ def test_excerpt_uses_target_relative_committed_path(tmp_path: Path) -> None:)[email protected]("captured", [False, True], ids=["legacy-scopes", "saved-scopes"])+ ("mode", "kind", "expected"),+ [+ ("diff", None, None),+ ("diff", "unknown", None),+ ("diff", "working_tree", None),+ ("diff", "commit", "1 fixture"),+ ("diff", "range", "1 fixture"),+ ("standard", None, "1 fixture"),+ ],+)+def test_saved_excerpt_requires_a_known_diff_source(+ tmp_path: Path, mode: str, kind: str | None, expected: str | None, captured: bool+) -> None:+ target = tmp_path / "target"+ revision = initialize_git_repository(target)+ scan = {+ "mode": mode,+ "diff_target_kind": kind,+ "target_revision": revision,+ "target_snapshot_digest": None,+ }+ if captured:+ scopes = load_script("workbench_source_scopes").capture_source_scopes(+ target, (revision, None, 0, 0), ["."]+ )+ scan["source_scopes_json"] = json.dumps(scopes)+ assert (+ load_script("workbench_source_excerpt").finding_source_excerpt(+ scan, target, [{"path": "README.md", "startLine": 1}], ["."]+ )+ == expected+ )++def test_working_tree_excerpt_declines_uncommitted_line_content(tmp_path: Path) -> None:target = tmp_path / "target"initialize_git_repository(target)