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

fix(reports): normalize invalid code evidence line ranges (#1656)

wj4f656ae4a402
diff --git a/plugins/codex-security/scripts/report_projection.py b/plugins/codex-security/scripts/report_projection.py
index 15485408b..1683bf095 100644
--- a/plugins/codex-security/scripts/report_projection.py
+++ b/plugins/codex-security/scripts/report_projection.py
@@ -406,13 +406,15 @@ def _code_evidence_location(item: dict[str, Any]) -> str:
item = location
path = item.get("path")
start = item.get("startLine")
- end = item.get("endLine", start)
+ end = item.get("endLine")
if not isinstance(path, str) or not path:
return ""
path = _path_label(path)
- if not isinstance(start, int):
+ if not isinstance(start, int) or isinstance(start, bool) or start < 1:
return path
- return f"{path}:{start}" if end == start else f"{path}:{start}-{end}"
+ if not isinstance(end, int) or isinstance(end, bool) or end <= start:
+ return f"{path}:{start}"
+ return f"{path}:{start}-{end}"
def _code_fence(code: str, minimum: int = 3) -> str:
diff --git a/plugins/codex-security/tests/test_finalize_scan_contract.py b/plugins/codex-security/tests/test_finalize_scan_contract.py
index 5eee19329..ed86530fc 100644
--- a/plugins/codex-security/tests/test_finalize_scan_contract.py
+++ b/plugins/codex-security/tests/test_finalize_scan_contract.py
@@ -1602,6 +1602,26 @@ The extraction root is not enforced.
self.assertIn("A traversal input escapes the destination.", report)
self.assertIn(r"archive entry -\> filesystem write", report)
+ @pytest.mark.cross_platform
+ def test_finalize_renders_embedded_evidence_with_null_end_line(self) -> None:
+ self.findings["findings"][0]["validation"] = {
+ "codeEvidence": [
+ {
+ "label": "Source control",
+ "path": "src/evidence.py",
+ "startLine": 37,
+ "endLine": None,
+ "code": "handle(request)",
+ }
+ ]
+ }
+ self.write_scan()
+
+ FINALIZER.finalize_scan(self.scan_dir)
+
+ report = (self.scan_dir / "report.md").read_text(encoding="utf-8")
+ self.assertIn("**Source control** — `src/evidence.py:37`\n", report)
+
@pytest.mark.cross_platform
def test_report_projection_preserves_data_flow_aliases_and_scalar_reachability(self) -> None:
for data_flow_key in ("dataFlow", "data_flow", "dataflow"):
@@ -1751,6 +1771,26 @@ The extraction root is not enforced.
with self.preserving_sealed_findings(findings):
pass
+ @pytest.mark.cross_platform
+ def test_sealed_rerun_renders_legacy_evidence_with_reversed_bounds(self) -> None:
+ self.write_sealed_scan()
+ findings = self.read_json("findings.json")
+ finding = findings["findings"][0]
+ finding["code_evidence"] = [
+ {
+ "id": "legacy-source",
+ "label": "Source control",
+ "location": {"path": "src/evidence.py", "startLine": 48, "endLine": 47},
+ "code": "handle(request)",
+ }
+ ]
+ finding["validation"] = {"evidenceRefs": ["legacy-source"]}
+ with self.preserving_sealed_findings(findings):
+ pass
+
+ report = (self.scan_dir / "report.md").read_text(encoding="utf-8")
+ self.assertIn("**Source control** — `src/evidence.py:48`\n", report)
+
@pytest.mark.cross_platform
def test_sealed_rerun_ignores_malformed_legacy_evidence_rows(self) -> None:
self.write_sealed_scan()
diff --git a/plugins/codex-security/tests/test_report_projection.py b/plugins/codex-security/tests/test_report_projection.py
index 6749ff6ee..a2867b733 100644
--- a/plugins/codex-security/tests/test_report_projection.py
+++ b/plugins/codex-security/tests/test_report_projection.py
@@ -911,3 +911,34 @@ def test_projection_preserves_identifier_text_and_code_path_spelling(
markdown = PROJECTION.build_report_markdown(manifest, findings, coverage)
assert "\\_\\_proto\\_\\_ pollution" in markdown
assert rendered_location in markdown
+
+
+ ("bounds", "rendered_location"),
+ [
+ ({"startLine": 37, "endLine": None}, "`src/evidence.py:37`"),
+ ({"startLine": 48, "endLine": 47}, "`src/evidence.py:48`"),
+ ({"startLine": 59, "endLine": "60"}, "`src/evidence.py:59`"),
+ ({"startLine": 37, "endLine": True}, "`src/evidence.py:37`"),
+ ({"startLine": True, "endLine": 4}, "`src/evidence.py`"),
+ ({"startLine": 0}, "`src/evidence.py`"),
+ ({"startLine": -1}, "`src/evidence.py`"),
+ ],
+)
+def test_projection_normalizes_invalid_legacy_code_evidence_bounds(
+ bounds: dict[str, object], rendered_location: str
+) -> None:
+ manifest, findings, coverage = canonical_documents()
+ finding = findings["findings"][0]
+ finding["validation"] = {"evidenceRefs": ["source"]}
+ finding["code_evidence"] = [
+ {
+ "id": "source",
+ "label": "Source control",
+ "path": "src/evidence.py",
+ **bounds,
+ "code": "handle(request)",
+ }
+ ]
+ markdown = PROJECTION.build_report_markdown(manifest, findings, coverage)
+ assert rendered_location in markdown