OSV Scanner #373
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
| --- | |
| # This workflow uses actions that are not certified by GitHub. | |
| # They are provided by a third-party and are governed by | |
| # separate terms of service, privacy policy, and support | |
| # documentation. | |
| # A sample workflow which sets up periodic OSV-Scanner scanning for vulnerabilities, | |
| # in addition to a PR check which fails if new vulnerabilities are introduced. | |
| # | |
| # For more examples and options, including how to ignore specific vulnerabilities, | |
| # see https://google.github.io/osv-scanner/github-action/ | |
| name: "OSV Scanner" | |
| on: | |
| push: | |
| branches: ["main"] | |
| schedule: | |
| - cron: "0 0 * * 0" | |
| workflow_dispatch: | |
| permissions: {} | |
| jobs: | |
| osv-scanner: | |
| permissions: | |
| # Required to upload the SARIF file to the security tab | |
| security-events: write | |
| # Required to read the code | |
| contents: read | |
| # Required to read the code | |
| actions: read | |
| uses: "google/osv-scanner-action/.github/workflows/osv-scanner-reusable.yml@9a498708959aeaef5ef730655706c5a1df1edbc2" # v2.3.8 | |
| with: | |
| fail-on-vuln: false | |
| check: | |
| runs-on: ubuntu-latest | |
| needs: osv-scanner | |
| steps: | |
| - name: Check OSV scan results | |
| shell: bash | |
| env: | |
| # Passed through the environment rather than interpolated into the | |
| # script body. The runner injects this out-of-band, so the scanner | |
| # JSON can never break out of the surrounding shell context no matter | |
| # what it contains or how large it is. | |
| RESULTS: ${{ needs.osv-scanner.outputs.results }} | |
| run: | | |
| set -euo pipefail | |
| IFS=$'\n\t' | |
| # printf is a bash builtin, so the (potentially very large) value is | |
| # written to disk without hitting the ARG_MAX command-line limit. | |
| printf '%s' "${RESULTS}" > "${RUNNER_TEMP}/results.json" | |
| # jq expression: | |
| # - iterate packages -> vulnerabilities -> full osv entry -> severity[] (type, score) | |
| # - extract numeric scores for CVSS types (cvss_v3 or numeric severity[].score) | |
| # - compare to threshold | |
| if jq ' | |
| .results[] | |
| | .packages[]? | |
| | .vulnerabilities[]? | |
| | ( .severity[]?.score // "" ) as $s | |
| | select($s != "") | |
| | ($s | tonumber) >= 4.0 | |
| ' "${RUNNER_TEMP}/results.json" | grep -q -e . ; then | |
| >&2 echo "error: found one or more vulnerabilities with a medium or higher severity (see step 'scan > osv-scanner > Run osv-scanner-reporter' for details)" | |
| exit 1 | |
| fi |