-
Notifications
You must be signed in to change notification settings - Fork 10
PR #5: Enhanced SARIF Formatter with Code Flows #395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
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
SafeDep Report SummaryNo dependency changes detected. Nothing to scan. This report is generated by SafeDep Github App |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #395 +/- ##
==========================================
+ Coverage 79.64% 79.76% +0.12%
==========================================
Files 77 78 +1
Lines 7689 7799 +110
==========================================
+ Hits 6124 6221 +97
- Misses 1322 1333 +11
- Partials 243 245 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This was referenced Nov 22, 2025
Owner
Author
This was referenced Nov 22, 2025
Owner
Author
Merge activity
|
- Rich rule metadata with help markdown and CWE references - Code flows for taint path visualization (source → sink) - Related locations for taint sources - Security severity scores for GitHub integration - Rule properties including tags and precision - Builder pattern API matching go-sarif library - Comprehensive tests achieving 97.5% coverage Features: - SARIF 2.1.0 compliance - Deduplicates rules across multiple detections - Supports both taint-local and taint-global detection types - Pattern matches do not include code flows (as expected) - Fallback from RelPath to FilePath for artifact locations Part of output standardization feature (PR #5). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- Replaced old generateSARIFOutput() with output.SARIFFormatter - Uses enriched detections for rich SARIF output with code flows - Removed unused imports (sarif, json, encoding/json) - Skipped obsolete SARIF tests (replaced by output/sarif_formatter_test.go) - Cleaned up unused helper functions in tests Benefits over old implementation: - Code flows for taint path visualization - Related locations for taint sources - Help text with markdown formatting - Security severity scores for GitHub - Rule properties (tags, precision) - Consistent with JSON and CSV formatter pattern All tests passing, linting clean. Part of output standardization feature (PR #5). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
022584e to
495743f
Compare
shivasurya
added a commit
that referenced
this pull request
Nov 22, 2025
## Summary Implements standardized exit codes and the `--fail-on` flag for both `scan` and `ci` commands, enabling selective CI/CD pipeline failures based on security finding severities. ## Changes ### Core Exit Code Logic (`output/exit_code.go`) - **Exit Code Constants**: - `ExitCodeSuccess (0)`: No findings or no --fail-on match - `ExitCodeFindings (1)`: Findings match --fail-on severities - `ExitCodeError (2)`: Configuration or execution errors - **DetermineExitCode()**: Calculates appropriate exit code with error precedence - **ParseFailOn()**: Parses comma-separated severity values - **ValidateSeverities()**: Validates severity names (case-insensitive) - **InvalidSeverityError**: Custom error type for validation failures ### Command Integration - **scan command**: Add --fail-on flag and integrate exit code logic - **ci command**: Add --fail-on flag and integrate exit code logic - Both commands now: - Exit 0 by default (regardless of findings) - Exit 1 only when findings match --fail-on severities - Exit 2 on configuration/execution errors - Support case-insensitive severity validation ### Bug Fixes - Fixed SARIF output always exiting 0 (now respects --fail-on) ## Testing ### Unit Tests (`output/exit_code_test.go`) - 16 tests for `DetermineExitCode()` covering all exit scenarios - 12 tests for `ParseFailOn()` covering edge cases - 13 tests for `ValidateSeverities()` covering validation - All tests verify case-insensitive behavior ### Integration Tests (`cmd/exit_code_integration_test.go`) - Tests actual binary exit codes for both scan and ci commands - Tests all output formats (SARIF, JSON, CSV) - Tests invalid severity handling - Tests case-insensitive severity matching - Requires `INTEGRATION=1` and pre-built binary **Test Results**: All tests passing ✅ ```bash $ gradle testGo ok .../output 0.223s ok .../cmd 0.317s ``` ## Examples ```bash # Default: no exit on findings pathfinder scan --rules rules/ --project . # Exit: 0 (even if vulnerabilities found) # Fail on critical findings pathfinder scan --rules rules/ --project . --fail-on critical # Exit: 1 if critical findings, 0 otherwise # Fail on critical or high findings pathfinder ci --rules rules/ --project . --output sarif --fail-on critical,high # Exit: 1 if critical/high findings, 0 otherwise # Case insensitive pathfinder scan --rules rules/ --project . --fail-on CRITICAL,High,MeDiUm # Exit: 1 if any match # Invalid severity pathfinder scan --rules rules/ --project . --fail-on invalid # Error: invalid severity 'invalid', must be one of: critical, high, medium, low, info ``` ## Migration Notes ### Breaking Changes - **Default behavior changed**: Previously, any findings caused exit 1. Now requires explicit `--fail-on` flag. - **CI/CD pipelines**: Add `--fail-on critical,high` to maintain previous fail-on-findings behavior. ### Non-Breaking - Existing commands without `--fail-on` continue to work (exit 0) - All output formats work identically with exit codes ## Checklist - [x] Core exit code logic implemented - [x] Integrated with scan command - [x] Integrated with ci command - [x] Unit tests (95%+ coverage) - [x] Integration tests - [x] All tests passing - [x] Linter passing - [x] Binary builds successfully - [x] Documentation in commit messages ## Stacked PRs This PR stacks on top of: - PR #5: SARIF Formatter (#395) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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
Implements enhanced SARIF formatter with code flows, related locations, and rich metadata for optimal GitHub Code Scanning integration.
Part of output-standardization tech spec (Stacked PRs)
Changes
New Files
output/sarif_formatter.go(290 lines)output/sarif_formatter_test.go(519 lines)Modified Files
cmd/ci.gogenerateSARIFOutput()with new formattercmd/ci_test.goKey Features
Code Flows
Taint detections automatically include code flows showing the path from source to sink:
{ "codeFlows": [{ "message": {"text": "Taint flow from line 10 to line 20"}, "threadFlows": [{ "locations": [ { "location": {"physicalLocation": {"region": {"startLine": 10}}}, "message": {"text": "Taint source: user_input"} }, { "location": {"physicalLocation": {"region": {"startLine": 20}}}, "message": {"text": "Taint sink: os.system"} } ] }] }] }Help Text with Markdown
Rules include rich help text with CWE references:
Security Severity Scores
GitHub-compatible severity scores for prioritization:
Rule Properties
{ "properties": { "tags": ["security"], "security-severity": "9.0", "precision": "high" } }Benefits over Old Implementation
Testing
Usage Examples
SARIF Output Sample
{ "version": "2.1.0", "runs": [{ "tool": { "driver": { "name": "Code Pathfinder", "version": "0.0.25", "rules": [{ "id": "sql-injection", "name": "SQL Injection", "fullDescription": {"text": "Unsanitized user input flows to SQL query (CWE-89, A03:2021)"}, "helpUri": "https://github.com/shivasurya/code-pathfinder", "defaultConfiguration": {"level": "error"}, "properties": { "tags": ["security"], "security-severity": "9.0", "precision": "high" } }] } }, "results": [{ "ruleId": "sql-injection", "message": {"text": "Unsanitized user input flows to SQL query (sink: execute, confidence: 95%)"}, "locations": [{ "physicalLocation": { "artifactLocation": {"uri": "src/db/queries.py"}, "region": {"startLine": 42, "startColumn": 8} } }], "codeFlows": [...], "relatedLocations": [...] }] }] }Breaking Changes
generateSARIFOutput()function removedStack Status
This PR stacks on:
Next PR:
🤖 Generated with Claude Code