Skip to content
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

Add new sarif formatter #240

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

zendern
Copy link
Contributor

@zendern zendern commented Jun 7, 2021

Working through adding what is needed to do #239.

This pull request makes the following changes:

  • Adds a new formatter... thats it nothing to crazy

It relates to the following issue #s:

cc @bhamail / @DarthHater


How im testing this?

Currently using the https://github.com/sonatype-nexus-community/intentionally-vulnerable-golang-project project. And running my local build against nancy with the -o sarif output option and then dumping to a file and doing some magic incantations necessary for github to be happy. (the action will take care of this later)

go list -json -m all | ../nancy/nancy sleuth -o sarif > analysis-data.sarif
gzip -c analysis-data.sarif | base64 |tr -d '\n' | pbcopy

And then this curl command to send the results to my forked repo above

curl --location --request POST 'https://api.github.com/repos/zendern/intentionally-vulnerable-golang-project/code-scanning/sarifs' \
--header 'Accept: application/vnd.github.v3+json' \
--header 'Authorization: token <your github token>' \
--header 'Content-Type: application/json' \
--data-raw '{
"tool_name": "Sonatype Nancy",
"commit_sha": "d027c0472f6ef91aa9ce50674536c2787ca9863b",
"ref": "refs/heads/master",
"sarif": "<paste in big chunk of sarif here>"
}'

If you want to stitch the above together to check it out on your own repo you should be able to by changing the url in the curl above.


So whats it look like??

So you can poke around here.

https://github.com/zendern/intentionally-vulnerable-golang-project/security/code-scanning?query=tool%3Anancy

List screen

Github alert types can only be of one of the 4 types. [none, note, warning and error]. I have implemented it as follows :

  • CVSS score > 7 == error (Critical and High)
  • Anything less than that == warning (Medium and Low)

Following the lead here

func scoreAssessment(score decimal.Decimal) string {
if score.GreaterThanOrEqual(nine) {
return "Critical"
}
if score.GreaterThanOrEqual(seven) {
return "High"
}
if score.GreaterThanOrEqual(four) {
return "Medium"
}
return "Low"
}

Outstanding question on this would be should Low == Note as far as github code scanning goes or does Warning still make sense to use??

screencapture-github-zendern-intentionally-vulnerable-golang-project-security-code-scanning-2021-06-06-23_10_00

Vulnerability details page

screencapture-github-zendern-intentionally-vulnerable-golang-project-security-code-scanning-22-2021-06-06-23_10_18

Looks wise we can probably maybe do better. Markdown support is available in some fields but does have the caveat of once you throw a newline in there Github collapses it and will make you expand before you get them sweet sweet details.

Also something to note since we do not have full (is transitive deps/actually in go.mod/Gopkg.lock file) I am just pinning the line number of the issue to the first line in the corresponding go.mod/Gopkg.lock file to indicate its a dependency issue. Does this seem reasonable??

What's left outstanding?

  • Implement the stubbed out tests
  • Determine if levels are setup appropriately for CVVS Score -> Github Severity
  • Probably some formatting
  • Test it out using github action

@luigigubello
Copy link

This PR is amazing! It works so fine, I have already written a draft Github Action, please merge it 🚀 (thanks for this PR 🙏 )

name: Sonatype Nancy alpha

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  security:
    runs-on: ubuntu-latest
    steps:
    - name: Check out code into the Go module directory
      uses: actions/checkout@v2

    - name: Set up Go 1.x in order to write go.list file
      uses: actions/setup-go@v2
      with:
        go-version: ^1.15
        
    - name: Configure git for private modules
      env:
        ACTOR: ${{ github.actor }}
        TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
      run: git config --global url."https://${ACTOR}:${TOKEN}@github.com".insteadOf "https://github.com"

    # Generate result.sarif
    - name: Nancy by Zendern
      run: |
        echo $(cd /tmp && git clone --branch sarif-output https://github.com/zendern/nancy.git && cd nancy && go get ./... && go build -o nancy .)
        echo $(go list -json -m all | nancy sleuth -o sarif > results.sarif)

    - name: Upload SARIF file
      uses: github/codeql-action/upload-sarif@v1
      with:
        sarif_file: results.sarif

@sonatypecla
Copy link

sonatypecla bot commented Mar 7, 2022

Thanks for the contribution! Unfortunately we can't verify if the committer(s), Tobi Fuhrimann [email protected], signed the CLA because they have not associated their commits with their GitHub user. Please follow these instructions to associate your commits with your GitHub user. Then sign the Sonatype Contributor License Agreement and this Pull Request will be revalidated.

@sonarcloud
Copy link

sonarcloud bot commented Aug 3, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 3 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add SARIF support
3 participants