-
Notifications
You must be signed in to change notification settings - Fork 0
Add partialFingerprints to SARIF output to enable GitHub deduplication #2
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: brabster <[email protected]>
Co-authored-by: brabster <[email protected]>
| @@ -1,33 +1,5 @@ | |||
| github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls= | |||
| github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= | |||
| github.com/ipfs/go-bitfield v1.0.0 h1:y/XHm2GEmD9wKngheWNNCNL0pzrWXZwCdQGv1ikXknQ= | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are all these lines deleted? What do they have to do with the issue and resolution? If they are not directly related to the change, revert these deletions and instead make a pull request comment to recommend these deletions with explanation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot see this and other review commenta
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines were unrelated test dependency changes that were accidentally included when running tests. Reverted in commit 0d850c8.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All review comments have been addressed in commit 0d850c8. The unrelated go.mod/go.sum changes have been reverted, and detailed documentation with references has been added. The PR now only contains changes to the three relevant files: sarif.go, sarif_test.snap, and sarif_fingerprint_test.go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All review comments have been addressed in commit 0d850c8. The unrelated test dependency changes have been reverted, detailed documentation has been added explaining the parameter choices and primaryLocationLineHash usage with GitHub documentation references.
| require github.com/gogo/protobuf v1.3.1 | ||
|
|
||
| require github.com/ipfs/go-bitfield v1.0.0 | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this deleted? What does it have to do with the issue and resolution? If it is not directly related to the change, revert the deletions and instead make a pull request comment to recommend the deletions with explanation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was an unrelated test dependency change accidentally included when running tests. Reverted in commit 0d850c8.
| github.com/ipfs/go-bitfield v1.0.0/go.mod h1:N/UiujQy+K+ceU1EF5EkVd1TNqevLrCQMIcAEPrdtus= | ||
| github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= | ||
| github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= | ||
| github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are all these lines deleted? What do they have to do with the issue and resolution? If they are not directly related to the change, revert these deletions and instead make a pull request comment to recommend these deletions with explanation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines were unrelated test dependency changes accidentally included when running tests. Reverted in commit 0d850c8.
internal/output/sarif.go
Outdated
|
|
||
| // createSARIFFingerprint generates a stable fingerprint for a SARIF result | ||
| // to help GitHub deduplicate findings across scans. | ||
| // The fingerprint is based on: vulnerability ID, artifact path, package name, and package version. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
explain why this combination of parameters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added detailed documentation in commit 0d850c8. The function uses three parameters (vulnID, artifactPath, pkg) because together they uniquely identify a specific vulnerability finding: the same vulnerability in the same package at the same location should always be considered the same finding and produce the same fingerprint across scans. This ensures both uniqueness (different vulnerabilities/packages/locations produce different fingerprints) and stability (the same finding always produces the same fingerprint).
| )) | ||
| )). | ||
| WithPartialFingerprints(map[string]string{ | ||
| "primaryLocationLineHash": fingerprint, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
explain why primaryLocationLineHash. Provide link to any relevant documentation and ensure correctness and authority of information
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added detailed documentation with reference link in commit 0d850c8. The primaryLocationLineHash key is the standard that GitHub Advanced Security uses to deduplicate code scanning alerts. Reference: https://docs.github.com/en/code-security/code-scanning/integrating-with-code-scanning/sarif-support-for-code-scanning#preventing-duplicate-alerts-using-fingerprints
GitHub's documentation states: "GitHub uses the primaryLocationLineHash property to detect results that are logically the same, so they can be shown only once, in the correct branch and pull request."
| require github.com/gogo/protobuf v1.3.1 | ||
|
|
||
| require github.com/ipfs/go-bitfield v1.0.0 | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are all these lines deleted? What do they have to do with the issue and resolution? If they are not directly related to the change, revert these deletions and instead make a pull request comment to recommend these deletions with explanation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines were unrelated test dependency changes accidentally included when running tests. Reverted in commit 0d850c8.
| github.com/ipfs/go-bitfield v1.0.0/go.mod h1:N/UiujQy+K+ceU1EF5EkVd1TNqevLrCQMIcAEPrdtus= | ||
| github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= | ||
| github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= | ||
| github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are all these lines deleted? What do they have to do with the issue and resolution? If they are not directly related to the change, revert these deletions and instead make a pull request comment to recommend these deletions with explanation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines were unrelated test dependency changes accidentally included when running tests. Reverted in commit 0d850c8.
| require github.com/gogo/protobuf v1.3.1 | ||
|
|
||
| require github.com/ipfs/go-bitfield v1.0.0 | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are all these lines deleted? What do they have to do with the issue and resolution? If they are not directly related to the change, revert these deletions and instead make a pull request comment to recommend these deletions with explanation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines were unrelated test dependency changes accidentally included when running tests. Reverted in commit 0d850c8.
| github.com/ipfs/go-bitfield v1.0.0/go.mod h1:N/UiujQy+K+ceU1EF5EkVd1TNqevLrCQMIcAEPrdtus= | ||
| github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= | ||
| github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= | ||
| github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are all these lines deleted? What do they have to do with the issue and resolution? If they are not directly related to the change, revert these deletions and instead make a pull request comment to recommend these deletions with explanation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines were unrelated test dependency changes accidentally included when running tests. Reverted in commit 0d850c8.
|
@copilot see review comments, changes and clarifications needed |
Co-authored-by: brabster <[email protected]>
| @@ -1,33 +1,5 @@ | |||
| github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls= | |||
| github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= | |||
| github.com/ipfs/go-bitfield v1.0.0 h1:y/XHm2GEmD9wKngheWNNCNL0pzrWXZwCdQGv1ikXknQ= | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot see this and other review commenta
|
@copilot note new comments in issue: PR raised on upstream repo here google#2333 Initial implementation has some problems. in
There is an additional, unrelated step:
Review and propose changes |
- Moved "different inputs" test to separate Test_ function - Removed duplicate test case with same inputs - Added diverse test cases covering different scenarios - Each test verifies determinism by calling function twice - All tests still pass Co-authored-by: brabster <[email protected]>
Refactored tests per upstream review feedback in commit a37eb03:
Regarding the snapshot tests: The snapshots were already updated in commit 78ee759 using |
|
@copilot Can we refactor the DifferentInputs test to be more in a matrix style to ensure that all combinations are tested without enumerating them all? |
- Uses nested loops to generate all combinations of test dimensions - Tests 2 vulnIDs × 2 artifactPaths × 4 packages = 16 combinations - More maintainable: easy to add new test values without manual enumeration - Better error messages showing both inputs when fingerprints collide - Verifies all combinations produce unique fingerprints Co-authored-by: brabster <[email protected]>
Refactored to matrix-style in commit 2719d92. The test now:
|
|
@copilot OK - I note that both tests depend on the similar sets of parameter values. I want to make a further refactor to have both tests depend on a common set of parameters values, and then have both tests take a similar matrix approach to ensure all combinations are tested |
- Extracted common test parameters (vulnIDs, artifactPaths, packages) to package-level variables - Both tests now use the same parameter sets for consistency - Test_createSARIFFingerprint uses matrix approach to generate all 16 combinations - Test_createSARIFFingerprint_DifferentInputs uses same parameters to verify uniqueness - Easy to extend by modifying common parameter arrays - Ensures both tests cover the exact same input space Co-authored-by: brabster <[email protected]>
Unified in commit 86c6cf8. Both tests now:
|
|
@copilot make sure the tests fail if there is a breaking change in the logic. Don't commit any changes unless there is a problem |
The tests are already robust against breaking changes:
The matrix approach ensures comprehensive coverage - any change that breaks the core logic (using all three parameters to generate unique, deterministic fingerprints) will cause test failures. No changes needed. |
|
internal/output/sarif_fingerprint_test.go:83 @copilot why can't we use |
We can use for j := range testCases[i+1:] {
actualJ := i + 1 + j
if testCases[i].fingerprint == testCases[actualJ].fingerprint {
// ...
}
}However, the current form is clearer and more direct for this nested comparison pattern. The explicit indexing makes it immediately obvious we're comparing each element with all subsequent elements. Would you like me to refactor it to use |
Implementation Complete: SARIF partialFingerprints for Deduplication
This PR resolves the issue of duplicate vulnerability alerts in GitHub's security tab by adding the
partialFingerprintsproperty to SARIF output.What Changed
Implementation Details
New Function:
createSARIFFingerprint()SARIF Output Enhancement
"partialFingerprints": {"primaryLocationLineHash": "<hash>"}primaryLocationLineHashkey as recommended by GitHub's documentationTests Added
sarif_fingerprint_test.go: Unit tests verifying:Benefits
✨ Eliminates duplicate alerts in GitHub Security tab
✨ Improves signal-to-noise ratio for security teams
✨ Follows GitHub's SARIF best practices
✨ Zero breaking changes - backward compatible
Security
🔒 CodeQL scan: 0 alerts
🔒 No new vulnerabilities introduced
Testing
✅ All 51+ snapshot tests passing
✅ New unit tests for fingerprint generation (unified matrix-style for comprehensive coverage)
✅ Linting clean (golangci-lint)
✅ No breaking changes to existing functionality
Upstream PR
Opened at google#2333
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.