Skip to content
Tutorials Center
My learning

Topics

Lesson 20 of 38 ยท Vulnerable Components and Auth Failures

Dependency Scanning and SBOMs

Learn how software composition analysis, lock files and a Software Bill of Materials (SBOM) help you find vulnerable dependencies before attackers do.

You cannot patch what you do not know you have. Software composition analysis (SCA) is the practice of listing every component in your software and checking each against vulnerability databases. A Software Bill of Materials (SBOM) is the written inventory that makes this possible: a machine-readable list of components, versions and where they came from, like an ingredient list on food packaging.

This lesson builds on Vulnerable and Outdated Components. You will learn what scanners do, how an SBOM looks, and how to build a tiny scanner of your own as a learning stand-in.

What a dependency scanner does

Whatever the tool, the flow is the same:

  1. Discover components from manifests (package.json, composer.json, requirements.txt, pom.xml) and, better, from lock files that pin exact versions.
  2. Identify each one with a standard name, such as a package URL (purl): pkg:npm/[email protected].
  3. Match the identity against advisory databases: national vulnerability data, ecosystem advisories and vendor feeds.
  4. Report findings with severity, the fixed version and the path through the dependency tree.

Real tools you will meet: npm audit, composer audit, pip-audit, OWASP Dependency-Check, Trivy, Grype, and hosted services built into code platforms. The commands below are shown read-only; run them only in your own projects.

Terminal
# Read-only examples. Output is illustrative, not from a real project.
npm audit --omit=dev
composer audit
pip-audit -r requirements.txt
trivy fs --scanners vuln .

Lock files and reproducible builds

A manifest says ^2.1 (any compatible version). A lock file says 2.1.7 (exactly this build, with a checksum). Committing lock files gives you:

  • Reproducibility: the version you scanned is the version you ship.
  • Reviewable change: upgrades appear as diffs.
  • Integrity: checksums detect tampering (see software and data integrity).

What an SBOM contains

Two widely used formats are CycloneDX and SPDX. Both list components, versions, licenses, hashes and relationships. A minimal, simplified record looks like this:

JSON
{
  "bomFormat": "CycloneDX",
  "specVersion": "1.5",
  "components": [
    { "type": "library", "name": "template-lib", "version": "3.2.0",
      "purl": "pkg:generic/[email protected]" }
  ]
}

SBOMs matter most on the day a new critical flaw is announced. Instead of asking every team "do you use library X?", you search your SBOM store and get an answer in minutes.

Python Build a mini SBOM from a lock file

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The packages are fictional. A real generator would also record hashes and the dependency graph.

A tiny scanner against a local advisory feed

Now join the SBOM to an advisory list. Real advisory data arrives as ranges; here each entry names a fixed version. This stand-in runs entirely in memory.

Python Scan the SBOM and prioritize

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The sorting captures a real lesson: a medium flaw in code that attackers can reach may matter more than a high score in code you never call. Tools call this reachability analysis. It reduces noise, but treat it as a hint and verify it.

Making scanning part of the process

  • Scan in CI on every pull request and fail the build for critical findings with a fix available.
  • Scan on a schedule, because new advisories appear for code you did not change.
  • Scan images and the OS layer, not only language packages.
  • Keep an exceptions list with an owner and an expiry date for findings you accept, so "temporary" does not become forever.
  • Store the SBOM for every release you ship.
  • Triage by exposure and fix availability: patch available and reachable means act now.

Common mistakes

  • Scanning only package.json and missing the lock file.
  • Ignoring development tools that run in CI with access to secrets.
  • Alert fatigue: hundreds of low findings bury the one that matters. Tune thresholds and use reachability.
  • Upgrading blindly in production without tests.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is an SBOM?

    An SBOM lists components, versions and often hashes and relationships, so you can search it when a new flaw is announced.
  2. 2. Why is a lock file better than a manifest alone for scanning?

    A manifest gives version ranges; a lock file shows what is actually installed, so findings match what ships.
  3. 3. A finding has a lower CVSS score but sits in code that is reachable from the internet, while a higher one is in unused code. What is a reasonable priority?

    Risk depends on exposure. Reachability and an available fix are strong reasons to prioritize.
  4. 4. Why scan on a schedule and not only when code changes?

    A dependency that was safe yesterday can have a published flaw today, so periodic scans catch what code-change scans cannot.

Summary

  • SCA matches your components against advisory data; an SBOM is the inventory that makes it fast.
  • Scan lock files, images and the OS layer, in CI and on a schedule.
  • Prioritize with severity, reachability and fix availability.
  • Track accepted risks with an owner and an expiry date.

Next: Authentication Failures