Skip to content

Harden SARIF output against malformed findings#243

Open
seonghobae wants to merge 1 commit into
developfrom
sarif-review
Open

Harden SARIF output against malformed findings#243
seonghobae wants to merge 1 commit into
developfrom
sarif-review

Conversation

@seonghobae

Copy link
Copy Markdown
Contributor

Summary

Adversarial review of the SARIF renderer found two crashes where one malformed finding sinks the whole report, plus an O(n²):

  • startLine did int(f["line"]) — external engines (Trivy) emit ranges ("12-14") or "n/a", so ValueError crashed the entire render. Now coerced via _safe_line() (bad value → 1).
  • shortDescription did message.strip().splitlines()[0] — a whitespace-only message → []IndexError. Now _first_line() returns a safe fallback.
  • ruleIndex was list(rules).index(rule_id) — O(n) per result, O(n²) total. Now stored at insert and stripped from the emitted driver rules.

Test plan

  • pytest — 225 passed, incl. 3 new: non-integer lines coerced (not crashed), blank message → fallback shortDescription, _index not leaked + ruleIndex stable/deduped.
  • Module self-check OK.

🤖 Generated with Claude Code

Adversarial review of the SARIF renderer found two "one bad finding sinks the
whole report" crashes and an O(n^2):

- startLine did `int(f["line"])`, but external engines (Trivy) emit ranges
  ("12-14") or "n/a" — ValueError crashed the entire render. Now coerced via
  _safe_line() (bad value -> 1).
- shortDescription did `message.strip().splitlines()[0]`; a whitespace-only
  message -> [] -> IndexError. Now _first_line() returns a safe fallback.
- ruleIndex was `list(rules).index(rule_id)` — O(n) per result, O(n^2) total.
  Now the index is stored at insert and stripped from the emitted driver rules.

Tests: non-integer lines coerced not crashed; blank message gets a fallback
shortDescription; private _index not leaked + ruleIndex stays stable/deduped.
Full suite 225 passed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EywwS2Du8pimW7xqRP3An3
@seonghobae seonghobae enabled auto-merge (squash) July 6, 2026 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant