refactor(exporters): improve exported sarif rule and result metadata#7368
refactor(exporters): improve exported sarif rule and result metadata#7368dwisiswant0 wants to merge 2 commits into
Conversation
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
WalkthroughThe PR refactors the SARIF exporter to generate standards-compliant output with enriched metadata and normalized values. The sarif library dependency is bumped to v0.1.0. Export logic now builds structured rule descriptors, result messages, and locations via helper functions, maintains stable rule indexing with integer-keyed mappings, and writes normalized SARIF to file with empty-object pruning enabled. ChangesSARIF Export Validation Enhancement
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Comment |
94fc6ba to
ef5ad99
Compare
|
TODO:
|
ef5ad99 to
8abb99d
Compare
Normalize rule ids and descriptions, attach help text, references and GitHub security properties, and enrich result messages with target, matcher, extractor, extracted values and reproduction details. Keep rule indices stable, generate better artifact locations, mark the invocation successful, and export with normalization and empty-object pruning enabled. Also adapt the exporter to the updated sarif API. Signed-off-by: Dwi Siswanto <git@dw1.io>
8abb99d to
4340c6d
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pkg/reporting/exporters/sarif/sarif.go (1)
510-519: 💤 Low valueConsider adding a guard for small limit values.
If
limitis less than 4, the truncationnormalized[:limit-3]could produce unexpected results (empty string for limit=3) or panic (negative slice index for limit<3). Current usage withmaxDetailValueLength=400is safe, but the function could be made more defensive.🛡️ Optional defensive fix
func normalizeAndTruncate(value string, limit int) string { normalized := normalizeValue(value) if normalized == "" { return "" } - if limit > 0 && len(normalized) > limit { + if limit >= 4 && len(normalized) > limit { return normalized[:limit-3] + "..." } return normalized }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pkg/reporting/exporters/sarif/sarif.go` around lines 510 - 519, normalizeAndTruncate currently assumes limit>=4 when it truncates with normalized[:limit-3] + "...", which can produce empty slices or a negative index for small limits; update normalizeAndTruncate (which calls normalizeValue) to be defensive: if limit <= 0 return normalized (or ""), if limit <= 3 return normalized[:min(len(normalized), limit)] without appending "..." (since there isn’t room), and only when limit >= 4 perform the existing truncation logic (normalized[:limit-3] + "...") after checking len(normalized) > limit.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@pkg/reporting/exporters/sarif/sarif.go`:
- Around line 510-519: normalizeAndTruncate currently assumes limit>=4 when it
truncates with normalized[:limit-3] + "...", which can produce empty slices or a
negative index for small limits; update normalizeAndTruncate (which calls
normalizeValue) to be defensive: if limit <= 0 return normalized (or ""), if
limit <= 3 return normalized[:min(len(normalized), limit)] without appending
"..." (since there isn’t room), and only when limit >= 4 perform the existing
truncation logic (normalized[:limit-3] + "...") after checking len(normalized) >
limit.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: da6405ed-657d-4888-a182-ebabe250f71c
⛔ Files ignored due to path filters (1)
go.sumis excluded by!**/*.sum
📒 Files selected for processing (2)
go.modpkg/reporting/exporters/sarif/sarif.go
Neo - PR Security Review — Did Not CompleteWarning Review Did Not Complete The review process ended without producing a result. This usually means To retry: Push a new commit or comment Comment |
Proposed changes
improve exported sarif rule and result metadata
Normalize rule ids and descriptions, attach help
text, references and GitHub security properties,
and enrich result messages with target, matcher,
extractor, extracted values and reproduction
details.
Keep rule indices stable, generate better artifact
locations, mark the invocation successful, and
export with normalization and empty-object pruning
enabled.
Also adapt the exporter to the updated sarif API.
Closes #7313
Proof
See #7313 (comment)
Checklist
Summary by CodeRabbit
Improvements
Tests
Chores