Skip to content

ci: upload ZAP and Trivy results to GitHub code scanning - #11

Open
VincentJerico wants to merge 1 commit into
mainfrom
feat/security-tab-sarif
Open

VincentJerico wants to merge 1 commit into
mainfrom
feat/security-tab-sarif

Conversation

@VincentJerico

Copy link
Copy Markdown
Owner

What & why

First of three security-automation PRs. ZAP and Trivy results currently end up only as zip artifacts. With this PR they also go to GitHub code scanning, so they show in Security > Code scanning with history.

  • Trivy: scripts/dependency-scan.sh converts the existing image report to SARIF with trivy convert (no second scan). Category trivy-juice-shop.
  • ZAP: has no SARIF output, so the new scripts/zap-to-sarif.ts converts zap/report.json. Category zap-juice-shop.
    • One rule per alert, keyed by alertRef (plugin 90004 raises two distinct alerts).
    • Risk is mapped to SARIF level and security-severity.
    • Informational alerts are left out.
    • ZAP findings are about URLs, not files, so each result points at the zap/rules.conf line that decides whether that rule fails the build.
  • When it uploads: on pushes to main and manual runs, not on pull requests. Dependabot PRs get a read-only token, and the Security tab should reflect main.
  • Permissions: the two scan jobs get security-events: write. Nothing else changes.
  • README: new "GitHub Security tab" section.

zap-to-sarif.ts runs as plain node (Node 22 strips the types), so no new dependency.

How it was tested

Locally (Node 22.23.4, Docker), against Juice Shop v18.0.0:

  • New self-test tests/sarif.selftest.spec.ts: 4 passed. It covers rule and result mapping, the rules.conf line, two alerts from one plugin, high to error, info left out, and HTML stripping.
  • Full suite: 33 passed. Lint, format and typecheck pass. actionlint: no issues.
  • On a real ZAP run (8 WARN rules, 0 FAIL, 58 PASS), the converter wrote 9 results, one per distinct alert, each on its own rules.conf line.
  • On a real Trivy run (DB from 2026-11-06, 130 unique high or critical CVEs), trivy convert wrote 130 rules and 244 results with security-severity.
  • A manual run of this workflow on this branch checks the actual upload. Results are below once it finishes.

Also found

scripts/zap-baseline.sh reports a ZAP crash, for example a missing rules.conf, as "a FAIL rule triggered". The build still fails, but the message blames the target. The drift-watch PR will fix it.

🤖 Generated with Claude Code

Trivy's image report is converted to SARIF with trivy convert; ZAP's
report.json goes through scripts/zap-to-sarif.ts, which points each alert
at the rules.conf line that gates it. Uploads run on pushes to main and
manual runs, not on pull requests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-advanced-security

Copy link
Copy Markdown

You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool.

What Enabling Code Scanning Means:

  • The 'Security' tab will display more code scanning analysis results (e.g., for the default branch).
  • Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results.
  • You will be able to see the analysis results for the pull request's branch on this overview once the scans have completed and the checks have passed.

For more information about GitHub Code Scanning, check out the documentation.

@VincentJerico

Copy link
Copy Markdown
Owner Author

Verification: manual run 42228479896 on this branch passed all 4 jobs, and code scanning recorded both uploads for refs/heads/feat/security-tab-sarif:

Category Tool Results Rules
zap-juice-shop OWASP ZAP 2.17.0 9 9
trivy-juice-shop Trivy 0.76.0 244 130

The ZAP alerts came through with the mapped severities: 1 high, 2 medium, 6 low. After merge, the first push to main creates the main analyses that the Security tab shows by default.

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