-
-
Notifications
You must be signed in to change notification settings - Fork 594
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
Generate SARIF File Of Project Vulnerability Findings #3561
Generate SARIF File Of Project Vulnerability Findings #3561
Conversation
If request header `Accept: application/sarif+json` is provided to the GET Finding By Project UUID API, it will now return a SARIF file with the vulnerability findings in that project. SARIF file is generated based on a pebble template Signed-off-by: Aravind Parappil <[email protected]>
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferencesYou may notice some variations in coverage metrics with the latest Coverage engine update. For more details, visit the documentation |
Great work @aravindparappil46! Looking at the generated SARIF, I noticed that you chose to key {
"id": "CVE-2023-6378",
"name": "logback-classic - Deserialization of Untrusted Data",
"shortDescription": {
"text": "A serialization vulnerability in logback receiver component part of logback version 1.4.11 allows an attacker to mount a Denial-Of-Service attack by sending poisoned data."
}
},
{
"id": "CVE-2023-6378",
"name": "logback-core - Deserialization of Untrusted Data",
"shortDescription": {
"text": "A serialization vulnerability in logback receiver component part of logback version 1.4.11 allows an attacker to mount a Denial-Of-Service attack by sending poisoned data."
}
}, Consider removing the component name from the The SARIF validator also appears to prefer
For the
Looking at how Trivy does it, it just sets all fields to OTOH, I'm wondering if we should use logical locations instead? https://github.com/microsoft/sarif-tutorials/blob/main/docs/2-Basics.md#physical-and-logical-locations |
src/test/java/org/dependencytrack/resources/v1/FindingResourceTest.java
Outdated
Show resolved
Hide resolved
Thanks a lot for the detailed feedback @nscuro ! Regarding Regarding I'm done with the above changes in my local branch. Have to work on updating the test and will push soon. |
The rules array in the generated SARIF should contain only unique values, so that the same rule can be referenced by multiple results. Rule name in the SARIF should be PascalCased. Using WordUtils from apache commons library to convert cweName to PascalCase. Set default escape strategy to the Pebble Engine to json, to escape linebreaks and double quotes in vulnerability description. Update test case to assert whole SARIF json. Signed-off-by: Aravind Parappil <[email protected]>
Since fullName is required by Azure DevOps ingestion rules, added it as concatenation of app name and version. shortDescription has been changed to be vulnerability ID and added fullDescription field as the actual vulnerability description (same as Trivy's SARIF) Signed-off-by: Aravind Parappil <[email protected]>
Have pushed the changes. More details in the commit messages :) Here's an updated SARIF sample: The pascal-casing for some CWE names look weird because of characters like hyphens (e.g., One thought I had was whether to conditionally add fields to the |
src/test/java/org/dependencytrack/resources/v1/FindingResourceTest.java
Outdated
Show resolved
Hide resolved
Honestly I don't know 😅 It might make sense to omit fields with empty values, on the other hand it might make sense to have properties consistent across all findings. What's your opinion? |
For the JSON assertion, removed matchers which can be replaced with string literals directly in the expected JSON string Signed-off-by: Aravind Parappil <[email protected]>
Thanks @nscuro ! Have removed the unwanted matchers. For the empty |
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferencesYou may notice some variations in coverage metrics with the latest Coverage engine update. For more details, visit the documentation |
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.
Thanks!
Description
If request header
Accept: application/sarif+json
is provided to the GET Finding By Project UUID API, it will now return a SARIF file with the vulnerability findings in that project.SARIF file is generated based on a pebble template.
Addressed Issue
Closes #909
Additional Details
In the GET
/v1/finding/project/{uuid}
API, added a new Media Typeapplication/sarif+json
to the@Produces
, to indicate the new responseContent-Type
.Added a
sarif.peb
template file to a new directory undertemplates/findings/sarif.peb
Sample
bom.json
and it's resulting.sarif
file is attached below:bom-and-sarif.zip
I have tried to include most of the fields from
Finding.java
into a meaningful field in theSARIF
file based on theSARIF
schema here. Those fields for which I could not find an adequate mapping I have kept under theproperties
object (fields such asepssScore
,severityRank
etc).Have tested the generated
SARIF
files against the validator here with "GitHub Ingestion Rules" enabled as well. Looks like most of the violations are geared towards static analysis results (like,region
,helpUri
etc missing).Feedback Needed
sarif.peb
template is scrutinized so that I am not making any blatant mistakes with the field mappings (fromFinding.java
to theSARIF
schema). Perhaps there are more meaningful fields in the sarif schema that we could possibly assign a finding field to.A picture showing the fields in
Finding.java
and its mapped field on theSARIF
file is shown below. The green comments are the target fields in theSARIF
schema.results.properties
mean that the finding field is added as a key/value pair into theproperties
object of the schema.results.level
field of theSARIF
schema like below:Do let me know in case we need to modify it
Even though we have set
content-disposition
header in the response, I was not able to confirm that a file namedfindings-{{uuid}}.sarif
was indeed being downloaded locally via cURL or Postman testing. It just displays the sarif json on the terminal now. Please let me know in case there is a way to test the actual file download. (I hope we do not have to change the media type to octet stream instead?)For
rules.name
, I have concatenatedfinding.component.name
andfinding.vulnerability.cweName
, hoping that it's more friendly to consume for an end-user. Please do let me know if this needs to be changed.Checklist