Skip to content

Instantly share code, notes, and snippets.

@ralyodio
Created August 1, 2026 03:24
Show Gist options
  • Select an option

  • Save ralyodio/f20c8c3403ba24e6eac63aff5daafabd to your computer and use it in GitHub Desktop.

Select an option

Save ralyodio/f20c8c3403ba24e6eac63aff5daafabd to your computer and use it in GitHub Desktop.
ThreatCrush CI workflow — click the link inside to add it
name: ThreatCrush PR Scanner
# Runs the ThreatCrush CLI against every pull request and scores what it found
# against the known vulnerability catalog (PRD §7.1).
#
# Two deliberate differences from the PRD's draft workflow:
#
# 1. `branches:` includes `master`, this repository's actual default branch.
# The draft listed only main/develop, which would have meant the workflow
# never ran on a single PR.
#
# 2. The scanner install is fault-tolerant. If the CLI cannot be fetched the
# job writes a valid empty SARIF and carries on, so the reporting and
# coverage steps still execute and say plainly that the scanner did not
# run. The alternative — a hard failure on step two — leaves every PR with
# a red X and no diagnostic. See docs/SCANNER_INTEGRATION.md.
on:
pull_request:
types: [opened, synchronize, reopened]
branches: [master, main, develop]
workflow_dispatch:
# Least privilege: read the code, write the PR comment, upload SARIF.
permissions:
contents: read
pull-requests: write
security-events: write
concurrency:
group: threatcrush-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
THREATCRUSH_VERSION: latest
SARIF_FILE: threatcrush-results.sarif
jobs:
threatcrush-scan:
name: Scan PR for Security Issues
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
# NOTE: this is a `pull_request` workflow, so for fork PRs the checked-out
# code is untrusted and the token is read-only. That is the correct trade.
# Do NOT switch this to `pull_request_target` to get a writable token —
# that combination executes fork code with repository secrets in scope and
# is one of the most reliably exploited CI misconfigurations there is.
- name: Checkout PR
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Validate test-case submissions
id: lint
run: bash scripts/validate-test-case.sh
- name: Install ThreatCrush CLI
id: install
run: |
set -uo pipefail
echo "scanner_available=false" >> "$GITHUB_OUTPUT"
# Preferred source: the sh1pt artifact registry (PRD §10.1).
if [ -n "${SH1PT_TOKEN:-}" ] && curl -fsSL --max-time 60 \
-H "Authorization: Bearer ${SH1PT_TOKEN}" \
"https://api.sh1pt.com/v1/scanners/threatcrush/${THREATCRUSH_VERSION}" \
-o threatcrush-cli.tar.gz; then
tar -xzf threatcrush-cli.tar.gz
echo "$PWD" >> "$GITHUB_PATH"
echo "scanner_available=true" >> "$GITHUB_OUTPUT"
echo "installed ThreatCrush from sh1pt"
# Fallback: the public install script (PRD §7.1).
elif curl -fsSL --max-time 60 https://cli.threatcrush.com/install.sh -o install.sh; then
bash install.sh
echo "scanner_available=true" >> "$GITHUB_OUTPUT"
echo "installed ThreatCrush from cli.threatcrush.com"
else
echo "::warning title=ThreatCrush unavailable::Could not fetch the CLI from \
api.sh1pt.com or cli.threatcrush.com. The scan step will be skipped and this \
run will report zero findings. This is an infrastructure problem, not a \
detection result."
fi
command -v threatcrush >/dev/null 2>&1 && threatcrush --version || true
env:
SH1PT_TOKEN: ${{ secrets.SH1PT_TOKEN }}
- name: Run ThreatCrush Scan
id: scan
if: steps.install.outputs.scanner_available == 'true'
run: |
PR_URL="${{ github.event.pull_request.html_url }}"
echo "Scanning: ${PR_URL:-$GITHUB_REF}"
threatcrush scan "${PR_URL:-.}" \
--format sarif \
--output "$SARIF_FILE" \
--config .threatcrush.yml \
--fail-on critical,high \
--verbose
continue-on-error: true
env:
THREATCRUSH_API_KEY: ${{ secrets.THREATCRUSH_API_KEY }}
- name: Ensure a SARIF file exists
if: always()
run: |
# Downstream steps and the Security tab both need well-formed SARIF,
# including on the path where the scanner never ran.
if [ ! -s "$SARIF_FILE" ]; then
echo "no SARIF produced — writing an empty run"
cat > "$SARIF_FILE" <<'JSON'
{
"version": "2.1.0",
"$schema": "https://json.schemastore.org/sarif-2.1.0.json",
"runs": [
{
"tool": {
"driver": {
"name": "threatcrush",
"informationUri": "https://threatcrush.com",
"rules": []
}
},
"results": []
}
]
}
JSON
fi
python3 -c "import json,sys; json.load(open('$SARIF_FILE')); print('SARIF parses')"
- name: Upload SARIF to GitHub Security tab
if: always()
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: ${{ env.SARIF_FILE }}
category: threatcrush
continue-on-error: true
- name: Check expected detections
id: coverage
if: always()
run: |
python3 scripts/validate-coverage.py \
--sarif "$SARIF_FILE" \
--catalog vulns/VULNERABILITY_CATALOG.json \
--output coverage-report.json \
--markdown coverage-report.md
continue-on-error: true
- name: Parse results and post PR comment
if: always()
run: |
python3 scripts/generate-report.py \
--sarif "$SARIF_FILE" \
--coverage coverage-report.json \
--pr-number "${{ github.event.pull_request.number }}" \
--repo "${{ github.repository }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload scan artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: threatcrush-scan-${{ github.event.pull_request.number || github.run_id }}
path: |
${{ env.SARIF_FILE }}
coverage-report.json
coverage-report.md
scan-summary.md
if-no-files-found: warn
retention-days: 30
- name: Fail the job when the scanner could not run
if: always() && steps.install.outputs.scanner_available != 'true'
run: |
echo "::error title=Scan did not run::The ThreatCrush CLI could not be \
installed, so this PR was never actually scanned. Fix the scanner source \
before trusting a green check on this workflow."
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment