Advanced
Searching inHow-to guides
How to search
  • Type the task in your own words (find port, open firewall, disk full) or paste an error message in quotes.
  • Choose "Quick answer" to see only the commands, or an area to stay in one field.
  • "two words" finds the exact phrase.
  • Plain words find names, texts and examples.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search
Try:

How-to 237Security · Supply chain

How to find vulnerable dependencies with Grype

Your own code may be fine, but the 600 libraries it pulls in are not always: one old log4j, requests or openssl with a known CVE is enough. Grype scans a project folder, a container image or an SBOM and lists every package with a known vulnerability, its severity and the version that fixes it. This how-to scans a repository and an image, scans an SBOM from Syft, ignores accepted findings with a reason, and fails CI on high-severity issues.

  • 5 Lessons
  • 4 Commands

$ run as a normal user# run as root (or with sudo)

237.1

The quick answer

grype dir:.
grype registry.example.com/shop/api:1.4.2 --only-fixed
grype registry.example.com/shop/api:1.4.2 --fail-on high

Commands in this lesson

237.2

Step by step

  1. Install — one binary (see the full guide) or the container anchore/grype. The first run downloads the vulnerability database (update daily with grype db update).
  2. Scan the project folder (line 1) — reads lock files (package-lock.json, requirements.txt/poetry.lock, go.sum, pom.xml …). Lock files give exact versions; without them results are incomplete.
  3. Scan an image (line 2) — OS packages and language packages inside. --only-fixed hides findings with no fix yet, so the list shows what you can act on today.
  4. Read the table — NAME, INSTALLED, FIXED-IN, TYPE, VULNERABILITY, SEVERITY. Fix by upgrading the package (or the base image) to the FIXED-IN version.
  5. SBOM first, scan later — make the SBOM once at build time with Syft, keep it with the release, and scan it again whenever new CVEs appear — no need to pull the image:
syft registry.example.com/shop/api:1.4.2 -o cyclonedx-json > sbom-api-1.4.2.json
grype sbom:sbom-api-1.4.2.json
  1. Accept a finding with a reason — not exploitable in your use, fix planned:
.grype.yaml
only-fixed: true
ignore:
  - vulnerability: CVE-2024-12345
    reason: "Only affects the CLI tool, not used at runtime. Re-check 2026-12-31."
  1. In CI (line 3) — --fail-on high exits with an error when a high or critical finding is present. Add -o sarif > grype.sarif to show results in the pull request.
  2. Keep it fresh — rebuild images regularly (new base image = new OS fixes), and let Dependabot/Renovate open upgrade PRs.

237.3

Check that it worked

The scan prints a table (or No vulnerabilities found); after upgrading the flagged package the finding is gone; in CI a test branch with an old library fails at the Grype step with discovered vulnerabilities at or above the severity threshold.

237.4

Common problems

ProblemCauseFix
dir: scan finds almost nothingNo lock files committed.Commit lock files; scan after dependency install.
Very long list on an old imageOld base image.Update the base image first — it removes most findings.
Same CVE ignored foreverIgnore without review date.Reason + date in .grype.yaml; review regularly.
failed to load vulnerability dbNo internet in CI.Cache or mirror the DB; GRYPE_DB_CACHE_DIR.
Results differ from TrivyDifferent databases and matching.Pick one as the gate; use the other for a second opinion.
Private registry access deniedNo login for Grype.docker login first, or registry credentials in env vars.

237.5

Go further

1Why scan an SBOM instead of the image again?

The SBOM lists all packages of a release; scanning it again finds newly published CVEs without pulling or rebuilding the image.

2What does --only-fixed do?

It hides vulnerabilities that have no fixed version yet, so the list shows only what you can fix now.

All commands in this chapter