fix: set SARIF helpUri to vulnerability advisory URL#3351
Open
will-bates11 wants to merge 1 commit intoanchore:mainfrom
Open
fix: set SARIF helpUri to vulnerability advisory URL#3351will-bates11 wants to merge 1 commit intoanchore:mainfrom
will-bates11 wants to merge 1 commit intoanchore:mainfrom
Conversation
The helpUri field on each SARIF rule was hardcoded to https://github.com/anchore/grype regardless of the vulnerability being reported. This means tooling that surfaces helpUri (e.g. GitHub Code Scanning) links users back to the Grype repository instead of the actual advisory. Fix: add a helpURI() helper that resolves the best available link in priority order: 1. Vulnerability.DataSource (e.g. NVD or GHSA direct link) 2. First entry in Vulnerability.URLs 3. Fall back to https://github.com/anchore/grype if neither is set Add Test_helpURI covering all three resolution paths. Fixes anchore#2874
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.
Problem
Every rule in the SARIF output has
helpUrihardcoded tohttps://github.com/anchore/grype, regardless of which vulnerability is being reported. Tools that surfacehelpUri, such as GitHub Code Scanning, link users back to the Grype repository instead of the actual advisory for that CVE or GHSA.Reported in #2874.
Fix
Add a
helpURI()helper inpresenter.gothat resolves the best available link for a vulnerability in priority order:Vulnerability.DataSource, the direct advisory link (e.g.https://nvd.nist.gov/vuln/detail/CVE-…orhttps://github.com/advisories/GHSA-…)Vulnerability.URLs[0], first reference URL if no DataSource is sethttps://github.com/anchore/grype, fallback when neither field is populatedThe
sarifRules()function already computes alinkstring using the same source fields for the help text body;helpURI()applies the same priority to populate thehelpUrifield with the raw URL.Tests
Added
Test_helpURIwith four subtests covering all resolution paths: DataSource takes precedence over URLs, first URL used when no DataSource, DataSource-only, and the no-data fallback.Fixes #2874