Fail the job when a scan does not complete - #139
Open
alimony wants to merge 1 commit into
Open
Conversation
The scanner steps run under continue-on-error because osv-scanner exits non-zero when it finds vulnerabilities and the reporter step is what decides whether to fail the job. That also swallows a scan that failed outright, and those two cases are not distinguishable from the step outcome alone. A scan that fails writes no results file, and osv-reporter treats a missing --new file as "no vulnerabilities found" and exits 0. So anything that stops the scanner from completing produces a green check and an empty Code Scanning upload rather than a build failure. In osv-scanner-reusable-pr.yml the new-code scan runs against the contents of the pull request, so a change that crashes the scanner passes as a clean diff. Check that a scanner step which reported failure actually produced its results file, and fail the job if it did not. A scan that exits non-zero because it found vulnerabilities still writes the file, so the reporter keeps its role of applying --fail-on-vuln, and a repository with no lockfiles still exits 0 and is unaffected.
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.
Both reusable workflows run the scanner under
continue-on-error: true, becauseosv-scannerexits non-zero when it finds vulnerabilities and theosv-reporterstep is what decides whether to fail the job:osv-scanner-action/.github/workflows/osv-scanner-reusable.yml
Lines 94 to 111 in 9fd1bcc
That also swallows a scan that failed outright, and the step outcome alone cannot distinguish the two — both are just
failure. The consequence is that the fail/pass decision is made from a results file that a failed scan never wrote, andosv-reportertreats a missing--newfile as "no vulnerabilities found" and exits 0.So anything that stops the scanner from completing produces a green check and an empty Code Scanning upload instead of a build failure. The existing
Error troubleshooterstep doesn't catch it: the reporter still writes an emptyresults.sarif, so the artifact upload succeeds.Measured
Replaying
osv-scanner-reusable.ymlstep for step against the images it pins (ghcr.io/google/osv-scanner-action:v2.3.8). "Poisoned" is the same lockfile as "vulnerable" plus one entry that crashes the npm parser ({"version": "npm:"}, google/osv-scalibr#2331):results.jsonOnly the last row changes. Before, the poisoned repo reports
No issues found, uploads 0 findings to Code Scanning, and merges green while carrying the same dependencies that fail the build one row above.osv-scanner-reusable-pr.ymlis the more exposed of the two, since its new-code scan runs against the contents of the pull request. With a clean base and a PR head carrying vulnerable dependencies plus the crash entry:The fix
Give the scanner steps ids and check that a step which reported
failureactually produced its results file; fail the job if it didn't.This keeps every legitimate path intact:
--fail-on-vulnand the diffing in the PR workflow is untouched;exit_code_redirect.shremaps 128 to 0 — so the guard'sif:never fires and osv-scanner-action 2.0.0 errors if no lockfiles found #65's behaviour is preserved;Not reformatted with Prettier: both files already differ from
.prettierrc.jsononmain, so running it would bury the change in an unrelated diff.Disclosure
Reported to Google's OSS VRP first (issue 536144722). Closed as not meeting the bar for a security bug, with an explicit invitation to file publicly, which is what this is.