fix: harden SARIF for GitHub Code Scanning#326
Conversation
📝 WalkthroughWalkthroughSARIF output is enhanced with rule metadata collection, computed partial fingerprints, and improved URI handling to improve GitHub Code Scanning compatibility. Rule metadata is aggregated from findings, fingerprints are computed from finding identity and location, and the complete rules array is emitted in the SARIF driver section with each result mapped by index. ChangesSARIF Rule Metadata and Fingerprints
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@src/report/sarif.rs`:
- Around line 30-36: The current branch handling paths uses normalized,
is_windows_drive_absolute, and encoded to build file:// URIs but doesn't treat
UNC paths correctly; add a branch that detects UNC-style absolute paths (when
normalized starts with "//") before the existing starts_with('/') check and
produce a host-based URI like file://server/path by stripping the leading
double-slash from encoded (or otherwise removing exactly one of the leading
slashes) so the output is "file://{host_and_path}" rather than "file:////...";
keep the existing is_windows_drive_absolute handling unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 1457cf76-2dc0-45dd-97b5-c0684c36bb49
📒 Files selected for processing (2)
src/report/sarif.rstests/integration.rs
| if normalized.starts_with('/') { | ||
| format!("file://{encoded}") | ||
| } else if is_windows_drive_absolute(normalized) { | ||
| format!("file:///{encoded}") | ||
| } else { | ||
| encoded | ||
| } |
There was a problem hiding this comment.
Handle UNC absolute paths as host-based file:// URIs.
UNC paths (e.g., \\server\share\app.js) normalize to //server/share/app.js, but this branch emits file:////server/... instead of file://server/..., which can break downstream path resolution.
🔧 Proposed fix + regression test
fn path_to_uri(path: &str) -> String {
@@
- if normalized.starts_with('/') {
+ if normalized.starts_with("//") {
+ // UNC path: //server/share/file -> file://server/share/file
+ format!("file:{encoded}")
+ } else if normalized.starts_with('/') {
format!("file://{encoded}")
} else if is_windows_drive_absolute(normalized) {
format!("file:///{encoded}")
@@
fn absolute_paths_emit_file_uris() {
assert_eq!(path_to_uri("/tmp/app.js"), "file:///tmp/app.js");
assert_eq!(path_to_uri("C:\\tmp\\app.js"), "file:///C:/tmp/app.js");
+ assert_eq!(
+ path_to_uri("\\\\server\\share\\app.js"),
+ "file://server/share/app.js"
+ );
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if normalized.starts_with('/') { | |
| format!("file://{encoded}") | |
| } else if is_windows_drive_absolute(normalized) { | |
| format!("file:///{encoded}") | |
| } else { | |
| encoded | |
| } | |
| if normalized.starts_with("//") { | |
| // UNC path: //server/share/file -> file://server/share/file | |
| format!("file:{encoded}") | |
| } else if normalized.starts_with('/') { | |
| format!("file://{encoded}") | |
| } else if is_windows_drive_absolute(normalized) { | |
| format!("file:///{encoded}") | |
| } else { | |
| encoded | |
| } |
🤖 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 `@src/report/sarif.rs` around lines 30 - 36, The current branch handling paths
uses normalized, is_windows_drive_absolute, and encoded to build file:// URIs
but doesn't treat UNC paths correctly; add a branch that detects UNC-style
absolute paths (when normalized starts with "//") before the existing
starts_with('/') check and produce a host-based URI like file://server/path by
stripping the leading double-slash from encoded (or otherwise removing exactly
one of the leading slashes) so the output is "file://{host_and_path}" rather
than "file:////..."; keep the existing is_windows_drive_absolute handling
unchanged.
Summary:
Verified current gaps:
Skipped:
Validation:
Closes #311
Summary by CodeRabbit
New Features
Tests