Skip to content

Update govulncheck workflow to scan source code #11482

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

Merged
merged 1 commit into from
Aug 11, 2025

Conversation

BagToad
Copy link
Member

@BagToad BagToad commented Aug 8, 2025

Description

Our govulncheck workflow is failing to upload SARIF results to Code Scanning.

image image

See a workflow run here

Explanation and solution

This is happening because we are scanning in binary mode. govulncheck is unable to deduce source code line numbers (location) from the binary. GitHub Code Scanning requires this line number information to accept a SARIF file, otherwise it cannot provide annotations directly on the vulnerable code.

The solution is to have govulncheck run on source files (./...) instead of the built binary in binary mode. This way, govulncheck can find the source code line numbers (location) and include it in the SARIF, making GitHub Code Scanning accept it.

See physicallocationobject for additional reference on this requirement.

Changed govulncheck to run on all source files (./...) instead of the built binary. This fixes uploading to GitHub Code Scanning as the location data will be valid, so it will get accepted.
@Copilot Copilot AI review requested due to automatic review settings August 8, 2025 22:15
@BagToad BagToad requested a review from a team as a code owner August 8, 2025 22:15
@BagToad BagToad requested a review from williammartin August 8, 2025 22:15
@BagToad BagToad temporarily deployed to cli-automation August 8, 2025 22:15 — with GitHub Actions Inactive
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Updates the govulncheck workflow to scan source code instead of binary mode to fix SARIF upload failures to GitHub Code Scanning. The issue was that binary mode scanning cannot provide source code line numbers required by GitHub Code Scanning.

  • Removes binary build step and switches from binary mode to source code scanning
  • Changes govulncheck command to scan ./... (all packages) instead of the built binary
  • Maintains the same SARIF output format for Code Scanning integration

@andyfeller
Copy link
Member

Explanation and solution

This is happening because we are scanning in binary mode. govulncheck is unable to deduce source code line numbers (location) from the binary. GitHub Code Scanning requires this line number information to accept a SARIF file, otherwise it cannot provide annotations directly on the vulnerable code.

The solution is to have govulncheck run on source files (./...) instead of the built binary in binary mode. This way, govulncheck can find the source code line numbers (location) and include it in the SARIF, making GitHub Code Scanning accept it.

Thank you for digging into this and that explanation! ❤️

Relates #11209

Copy link
Member

@andyfeller andyfeller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that explanation, I'm happy to give this a go to see how the changes work versus any concerns I originally had with this mode.

@@ -21,8 +21,7 @@ jobs:
# See https://pkg.go.dev/golang.org/x/vuln/cmd/govulncheck#hdr-Exit_codes for more information on exit codes.
- name: Check Go vulnerabilities
run: |
make
go run golang.org/x/vuln/cmd/govulncheck@d1f380186385b4f64e00313f31743df8e4b89a77 -mode=binary -format sarif bin/gh > gh.sarif
go run golang.org/x/vuln/cmd/govulncheck@d1f380186385b4f64e00313f31743df8e4b89a77 -format sarif ./... > gh.sarif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Do you have any concerns about the other package main executables within the cli/cli code base being included in the scan?

I think this was my only concern previously but it isn't the end of the world especially with this failing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I guess I don't have any problems with scanning that code also. If it becomes a problem, we could filter it out of the SARIF 👍 As of now that code doesn't produce any alerts from running this on my machine.

@BagToad BagToad merged commit 1b083c2 into trunk Aug 11, 2025
11 checks passed
@BagToad BagToad deleted the kw/fix-govulncheck-sarif-upload branch August 11, 2025 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants