Triage Trivy results by reachability with OpenVEX
By the CapyShield team · · 5 min read
In short
To triage Trivy results by reachability, save a JSON report with trivy fs --format json, run capyshield vex on it to check each finding against your lockfiles and production imports, and write the result as OpenVEX. Passing that file back with trivy --vex suppresses the not_affected findings while affected and under_investigation ones stay visible. On the CapyShield demo project, 22 Trivy findings became 6 affected, 2 not affected and 14 to review.
Trivy is good at finding every known CVE in a lockfile. It has no way to know which of those packages your production code actually loads. The fix is a loop: scan with Trivy, triage the JSON report by reachability, write the decisions as OpenVEX, and hand that file back to Trivy with --vex so it stops reporting what doesn't apply. This post walks through each step with the commands.
How do you triage Trivy results by reachability?
In four commands, run from the repository root:
# 1. Scan and save a JSON report.
trivy fs --format json -o trivy-report.json .
# 2. Triage it by reachability and write OpenVEX plus a Markdown summary.
capyshield vex --input trivy-report.json --repo . \
--output release.openvex.json --summary vex.md --fail-on high,critical
# 3. Scan again with the VEX applied: not_affected findings are suppressed.
trivy fs --vex release.openvex.json .
# 4. Review what was suppressed, and why.
trivy fs --vex release.openvex.json --show-suppressed .Everything runs locally. The triage step reads your lockfiles and import statements and keeps only package names and file counts; no source code leaves the machine.
Which Trivy report does the triage step need?
The JSON report, from --format json. The table output is for people; the JSON includes the package URL (purl) of every vulnerable package, which is what both the triage and Trivy's own VEX matching key on. A filesystem scan of the repository (trivy fs) is the natural fit, because reachability is checked against the same lockfiles Trivy scanned.
capyshield vex auto-detects the scanner, so --scanner trivy is optional. Reachability is computed for Node.js and Python, from package-lock.json, npm-shrinkwrap.json, pnpm-lock.yaml, yarn.lock, poetry.lock, uv.lock and requirements*.txt, plus the manifests that declare them. Findings in other ecosystems are kept and reported as under_investigation, never dropped.
What does the triage step produce?
Three outputs: the OpenVEX document, an optional Markdown table for humans (--summary), and a terminal summary. On the demo project from the CapyShield README, it looks like this:
capyshield: 22 trivy finding(s), 1 source file(s) analyzed: 6 affected, 2 not_affected, 14 under_investigation, 0 fixed
affected CVE-2020-28500 [email protected] (medium, imported in 1 file(s))
affected CVE-2021-23337 [email protected] (high, imported in 1 file(s))
affected CVE-2024-29041 [email protected] (medium, imported in 1 file(s))
...
capyshield: wrote openvex.json
capyshield: FAIL 2 affected finding(s) at severity high,critical- 6 affected: lodash and express are direct dependencies imported in production code. These get an
action_statementsuch as "Upgrade lodash to 4.17.21 or later." - 2 not_affected: node-fetch is declared as a direct dependency, but no production file imports it. Justification:
vulnerable_code_not_in_execute_path. - 14 under_investigation: transitive packages such as
qs,body-parserandpath-to-regexpthat production code doesn't import directly. Whether they load depends on what express does with them, which import analysis can't see, so they are not guessed.
Because two affected findings are high, --fail-on high,critical exits with code 3. That gate fires on reachable findings only, so it can be strict without failing every build over a test dependency. Each statement's status_notes records the facts behind the decision, for example dependency_scope=direct imported_in_prod=false matched_files_count=0.
How do you feed OpenVEX back to Trivy with --vex?
Pass the file to any Trivy scan. Trivy requires a purl as the product identifier and applies a statement when its purl matches a package found in the scan. The statements capyshield vex writes use the purls from the Trivy report itself, for example pkg:npm/[email protected], so they match:
trivy fs --vex release.openvex.json .Trivy logs each finding it filters, with the VEX format, vulnerability ID, status and justification, and leaves it out of the report. affected and under_investigation findings stay visible, which is what you want: the report now lists the things that still need work.
A few details from the Trivy docs worth knowing:
- Suppressed is not deleted.
--show-suppressedlists filtered findings with their status and where the suppression came from, which is what a reviewer or auditor will ask for. - Multiple sources combine.
--vexcan be repeated, for example a local file plus--vex repofor Trivy's VEX repository, and the order of the flags sets the priority. - It is marked experimental. Trivy flags its VEX support as subject to change, so pin your Trivy version in CI and re-check after upgrades.
- It works across targets. Trivy accepts OpenVEX for filesystem, repository, image, VM, Kubernetes and SBOM scans.
What do you do with the under_investigation findings?
Review them once, then record the answer next to the code so the next run applies it automatically. Local rules in .capyshield/vex-rules.yaml take precedence over reachability, and accept a package name or purl:
# .capyshield/vex-rules.yaml
rules:
- vulnerability: CVE-2024-45296
package: path-to-regexp
status: affected
- vulnerability: CVE-2024-47764
package: cookie
status: not_affected
justification: vulnerable_code_not_in_execute_path
impact_statement: "The app never sets cookies from user-supplied names or values."These two rules are illustrations of the format; the right status depends on your code. Use the standard justification labels rather than free text alone, since scanners and policy engines can act on labels. Because the rules file is versioned, every triage decision goes through code review, and git blame shows who made it and when.
How do you run this in CI?
Generate the VEX on every build, gate on reachable findings, and publish the OpenVEX file as a release artifact. In GitHub Actions:
- uses: capyshield-hq/capyshield/action@dd8fad936b663d4f51837fa0c60824781667f528 # v0.2.0
- run: |
trivy fs --format json -o trivy.json .
capyshield vex --input trivy.json --repo . --output release.openvex.json \
--summary vex.md --fail-on high,critical
- run: trivy fs --vex release.openvex.json --exit-code 1 --severity HIGH,CRITICAL .The second Trivy run is optional. It fails on any high or critical finding that is not marked not_affected, including under_investigation ones, which suits teams that want every unreviewed finding to block a release. Set SOURCE_DATE_EPOCH if you want the OpenVEX file to be byte-for-byte reproducible. On a CapyShield Cloud Team plan, adding --sync applies team rules and keeps one triage history across projects. The docs cover the rest of the setup.
Frequently asked questions
- How do I use a VEX file with Trivy?
- Pass it with --vex, for example trivy fs --vex release.openvex.json . Trivy applies a statement when its package URL matches a package found in the scan and filters findings marked not_affected.
- How can I see which Trivy findings a VEX file suppressed?
- Add --show-suppressed to the scan. Trivy then lists the filtered findings with their status instead of hiding them.
- Does capyshield vex fail CI on every Trivy finding?
- No. --fail-on high,critical exits with code 3 only when a finding triaged as affected, meaning imported in production code, has one of the listed severities.
- Which ecosystems does capyshield vex check for reachability?
- Node.js and Python, from npm, pnpm, Yarn, Poetry, uv and requirements files plus their manifests. Findings in other ecosystems are kept and reported as under_investigation.