Skip to content
Tutorials Center
My learning

Topics

Lesson 35 of 38 ยท DevSecOps

Supply Chain Security and SBOM

Understand software supply chain attacks and defences: SBOM formats, lockfiles and hash pinning, typosquatting, dependency confusion, build provenance, SLSA and artifact signing.

Modern applications are mostly other people's code. A typical web service pulls in hundreds of open-source packages, base images, build plugins and CI actions, and each of those pulls in more. Your security is only as strong as the weakest link in that chain. Supply chain attacks target the chain instead of your code: a poisoned package, a hijacked maintainer account, a malicious build step or a tampered image can reach thousands of victims at once.

This lesson explains the main risks, introduces the Software Bill of Materials (SBOM) and build provenance, and shows defensive checks you can run yourself. The exercises are defensive stand-ins: they inspect fake package data and never fetch or execute anything.

Where the chain can break

flowchart LR
    A["Source code<br/>and commits"] --> B["Dependencies<br/>packages, images, actions"]
    B --> C["Build system<br/>CI runners and scripts"]
    C --> D["Artifact<br/>package or image"]
    D --> E["Registry"]
    E --> F["Deployment"]
    X1["Stolen maintainer account"] -.-> B
    X2["Typosquat or dependency confusion"] -.-> B
    X3["Compromised build script or runner"] -.-> C
    X4["Registry tampering"] -.-> E

Every stage has its own attack. Defences must cover the whole path.

Attack How it works Main defence
Known vulnerable dependency You use a library with a published flaw SCA scanning and quick updates
Typosquatting A malicious package with a name like a popular one (reqeusts) Review new dependencies, allow-lists, private mirror
Dependency confusion A public package has the same name as your internal one and a higher version, so the installer picks it Scoped or namespaced names, registry rules that pin internal names to the private source
Compromised maintainer or package An attacker publishes a malicious new version of a trusted package Lockfiles, delayed adoption, hash pinning, provenance checks
Malicious install scripts Code runs at install time Disable scripts where possible, build in isolated environments
Build compromise The CI pipeline or a plugin is altered, so the artifact differs from the source Hardened, ephemeral builders, pinned actions, provenance
Image or registry tampering The artifact is replaced after the build Signing and verification, digests

Lockfiles and hash pinning

A manifest such as requirements.txt or package.json states what you want (requests>=2). A lockfile records exactly what you got: the precise version of every direct and transitive dependency, and ideally a hash of each file. Installing with hash checking means a changed or substituted package fails the install. Examples: pip install --require-hashes, package-lock.json and npm ci, poetry.lock, Cargo.lock, go.sum.

Try it: verify artifact hashes

This script simulates installing three artifacts against a lockfile of expected SHA-256 hashes. The tampered file is detected because its content differs.

Python Check downloaded artifacts against pinned hashes

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.

SBOM: an ingredients list for software

An SBOM is a machine-readable inventory of the components in a piece of software: names, versions, suppliers, licences, hashes and how they relate. When a new vulnerability such as a serious logging-library flaw is announced, an SBOM lets you answer "are we affected?" in minutes instead of weeks. Regulations and customers increasingly ask for them.

The two leading formats are SPDX (a Linux Foundation standard, also ISO/IEC 5962) and CycloneDX (an OWASP standard). Tools such as Syft, Trivy and the build plugins of most ecosystems generate them from source, lockfiles or images. A tiny CycloneDX-style fragment (read-only):

JSON
{
  "bomFormat": "CycloneDX",
  "specVersion": "1.5",
  "components": [
    { "type": "library", "name": "jsonkit", "version": "0.9.1",
      "purl": "pkg:pypi/[email protected]",
      "hashes": [{ "alg": "SHA-256", "content": "EXAMPLE_HASH" }] }
  ]
}

The purl (package URL) gives each component a standard identifier that vulnerability databases understand.

Try it: use an SBOM to answer "are we affected?"

Python Search SBOMs for a vulnerable component

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.

Only batch-worker is affected. Without the SBOMs, someone would have had to search every repository by hand.

Spotting typosquats

A cheap defensive check compares new dependency names with a list of popular or known-good names and flags near misses. Real systems also consider download counts, publication age and maintainer reputation. This version uses edit distance on made-up names.

Python Flag dependency names that look like popular packages

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.

Provenance, SLSA and signing

Provenance is signed metadata that states what was built, from which source, by which builder, with which inputs. If the artifact you deploy has valid provenance pointing at your repository and your hardened builder, you know it was not built on someone's laptop or swapped later.

SLSA (Supply-chain Levels for Software Artifacts, pronounced "salsa") is a framework of progressively stricter build levels: scripted builds with provenance, hosted builds with signed provenance and hardened, isolated builds that resist tampering. Sigstore (Cosign, Fulcio, Rekor) offers keyless signing tied to the build's OIDC identity and a public transparency log. At deployment, an admission policy verifies the signature and provenance (container runtime and registry security, policy as code).

A practical checklist

  1. Commit lockfiles; install with ci-style commands and hash checks.
  2. Use a private registry or proxy with rules that pin internal names to internal sources.
  3. Review new dependencies and keep the tree small; remove what you do not use.
  4. Scan dependencies on every build and on a schedule (shift-left security).
  5. Pin CI actions to commit SHAs, give workflows minimal permissions and use ephemeral runners.
  6. Generate an SBOM for every release and store it with the artifact.
  7. Sign artifacts, record provenance and verify both before deploying.
  8. Keep a plan for a compromised dependency: how to find it (SBOM), pin or roll back, rotate secrets that the build could see and notify users.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is dependency confusion?

    If an installer prefers a higher public version of a name you use internally, it can pull attacker-controlled code. Pin internal names to the private registry.
  2. 2. How does a lockfile with hashes help against a swapped package?

    Hash checking detects any difference between the reviewed artifact and what is delivered.
  3. 3. What question does an SBOM help you answer quickly?

    An SBOM is an inventory of components, so you can check whether a newly disclosed vulnerability affects you.
  4. 4. What does build provenance prove?

    Provenance is signed evidence of where and how an artifact was built. It does not prove the absence of bugs.

Summary

  • Supply chain attacks target dependencies, build systems and registries; defences must cover all stages.
  • Lockfiles with hash checks, private registries and careful dependency review stop typosquats, confusion and swaps.
  • SBOMs (SPDX, CycloneDX) turn "are we affected?" into a quick query.
  • Provenance, SLSA levels and signing (such as Sigstore) let deployment verify what it runs.
  • Pin CI actions, limit pipeline permissions and plan for the day a dependency is compromised.

Next: Project: A Cloud Configuration Auditor