Harden SARIF output against malformed findings#243
Open
seonghobae wants to merge 1 commit into
Open
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adversarial review of the SARIF renderer found two crashes where one malformed finding sinks the whole report, plus an O(n²):
startLinedidint(f["line"])— external engines (Trivy) emit ranges ("12-14") or"n/a", soValueErrorcrashed the entire render. Now coerced via_safe_line()(bad value → 1).shortDescriptiondidmessage.strip().splitlines()[0]— a whitespace-only message →[]→IndexError. Now_first_line()returns a safe fallback.ruleIndexwaslist(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,_indexnot leaked +ruleIndexstable/deduped.🤖 Generated with Claude Code