diff --git a/.github/workflows/osv-scanner.yml b/.github/workflows/osv-scanner.yml index 48b485c55fd..e5a983b1bca 100644 --- a/.github/workflows/osv-scanner.yml +++ b/.github/workflows/osv-scanner.yml @@ -14,7 +14,11 @@ name: OSV-Scanner # code patterns in PR diffs) by covering the orthogonal "currently-pinned # dep became known-vulnerable" case. # -# Uses Google's officially-recommended reusable workflow, pinned by SHA. +# Steps below are inlined from Google's officially-recommended reusable +# workflow (google/osv-scanner-action/.github/workflows/osv-scanner-reusable.yml), +# rather than called via `uses:` so we can set a `timeout-minutes` in the +# degenerate case where this job hangs. + # Findings land in the repo's Security tab (Code Scanning > OSV-Scanner). # fail-on-vuln is disabled so the job does not block merges on pre-existing # vulnerabilities in pinned deps that we may need to patch deliberately. @@ -24,11 +28,11 @@ on: schedule: # Weekly scan against main — catches CVEs published after merge for # deps that haven't changed since. - - cron: "0 9 * * 1" + - cron: '0 9 * * 1' workflow_dispatch: permissions: - # Required by the reusable workflow to upload SARIF to the Security tab. + # Required to upload SARIF file to CodeQL. See: https://github.com/github/codeql-action/issues/2117 actions: read contents: read security-events: write @@ -36,12 +40,62 @@ permissions: jobs: scan: name: Scan lockfiles - uses: google/osv-scanner-action/.github/workflows/osv-scanner-reusable.yml@9a498708959aeaef5ef730655706c5a1df1edbc2 # v2.3.8 - with: - # Scan explicit lockfiles rather than recursing, so we only look at - # the three sources of truth and skip vendored / test / worktree dirs. - scan-args: |- - --lockfile=uv.lock - --lockfile=package-lock.json - --lockfile=website/package-lock.json - fail-on-vuln: false + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false + + - name: 'Run scanner' + uses: google/osv-scanner-action/osv-scanner-action@9a498708959aeaef5ef730655706c5a1df1edbc2 # v2.3.8 + with: + # Scan explicit lockfiles rather than recursing, so we only look at + # the three sources of truth and skip vendored / test / worktree dirs. + scan-args: |- + --output=results.json + --format=json + --lockfile=uv.lock + --lockfile=package-lock.json + --lockfile=website/package-lock.json + continue-on-error: true + + - name: 'Run osv-scanner-reporter' + uses: google/osv-scanner-action/osv-reporter-action@9a498708959aeaef5ef730655706c5a1df1edbc2 # v2.3.8 + with: + scan-args: |- + --output=results.sarif + --new=results.json + --gh-annotations=false + --fail-on-vuln=false + + # Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF + # format to the repository Actions tab. + - name: 'Upload artifact' + id: 'upload_artifact' + if: ${{ !cancelled() }} + uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 + with: + name: OSV Scanner SARIF file + path: results.sarif + retention-days: 5 + + # Upload the results to GitHub's code scanning dashboard. + - name: 'Upload to code-scanning' + if: ${{ !cancelled() }} + uses: github/codeql-action/upload-sarif@cdefb33c0f6224e58673d9004f47f7cb3e328b89 # v4.31.10 + with: + sarif_file: results.sarif + + - name: 'Print Code Scanning URL' + if: ${{ !cancelled() }} + run: | + echo "View the OSV-Scanner results in the 'Security' tab, using the following link:" + echo "${{ github.server_url }}/${{ github.repository }}/security/code-scanning?query=is%3Aopen+branch%3A${GITHUB_REF_NAME}+tool%3Aosv-scanner" + env: + GITHUB_REF_NAME: ${{ github.ref_name }} + + - name: 'Error troubleshooter' + if: ${{ always() && steps.upload_artifact.outcome == 'failure' }} + run: | + echo "::error::Artifact upload failed. This is most likely caused by a error during scanning earlier in the workflow." + exit 1