Reliability and security · L2Dependency and supply-chain security

Dependency and supply-chain security

Most of the code you ship was written by strangers. Here is how to know what you run, and to trust it.

L2 SeniorReliability and security21 min read
Fact-checked by AI against cited sources · Human review pendingLast reviewed 9 Nov 2026 · How we check content
Section 1 of 8

What broke

In March 2024, a developer named Andres Freund noticed something small. SSH logins on his Debian unstable (sid) systems used a lot of CPU. A tool called valgrind also showed odd errors. 1

He measured it. A failed login took about 0.8 seconds instead of 0.3. He traced the delay to liblzma, part of the xz compression tools. Then he found a backdoor. 1

The bad code was in xz versions 5.6.0 and 5.6.1. The part that started it was not in the Git repository that people read. It was only in the release tarballs, the files that Linux distributions download and build. 1 There, a line in one build file ran a hidden script at the end of configure. That script pulled more code out of two "test" files in the repository and put it into the library. 1

OpenSSH does not use liblzma directly. But Debian and several other distributions patch it to talk to systemd, and libsystemd depends on liblzma. That chain loaded the backdoor into the SSH server. 1

Freund pointed to weeks of activity by the person who committed the changes. He wrote that they were "either directly involved" or their system was badly compromised. 1 Luckily, few distributions had shipped 5.6.0 or 5.6.1 yet, and mostly in pre-release versions. 1

Look at what the attacker needed. Not a bug in your code. Just one trusted committer, one build step nobody read, and a dependency of a dependency.

Section 2 of 8

The idea in simple words

Your app is mostly code that you did not write. Every library, every build tool and every CI action runs with your app's power. OWASP now ranks "Software Supply Chain Failures" third in its Top 10. 4 You met it in the OWASP lesson.

You face two separate problems:

  • Known flaws. A library you use has a published bug, a CVE. You need to know you use it, and then upgrade.
  • Malicious code. Someone put harmful code into a package, a build or a tool on purpose. No scanner knows about it yet.

The defenses answer three questions. What exactly do we run? A lockfile and an SBOM answer that. Is any of it known to be bad? A scanner answers that. Did it really come from where we think? Signatures and provenance answer that.

The key idea. Treat every dependency, build tool and CI action as code that runs with your permissions. Fix the exact versions, know the full list, check where each piece came from, and give your pipeline the smallest power it needs.

Section 3 of 8

How it works

Where attacks get in

Step through the path from source code to your app. Use Next and Back, or the ← and → keys.

Every hand-off between source code and your app is a place to tamperSource Build Registry Your app You read the source.You run what the registry sends. xz 5.6.0 and 5.6.1release tarball ≠ gitextra code ran at build time Dependency confusionprivate index: torchtritonpublic index: torchtriton (fake)pip installed the public one Moved tag@v44.5.1 → attacker's commitsame name, new code in CI ✓ lockfile: exact version + hash✓ provenance: which source, which build✓ actions pinned to a commit SHA SeniorPath
  1. Code you depend on passes through several hands. You review the source, but you install a built package from a registry. Each arrow is a hand-off an attacker can use.
  2. Source to build: the xz release tarballs held a line that was not in git. It ran a hidden script while the package was built.
  3. Registry: PyTorch nightly used a package called torchtriton from its own index. Someone put a package with the same name on PyPI, and pip installed that one instead.
  4. Build: a CI action is code too. In March 2025, attackers moved tags of tj-actions/changed-files to point to a malicious commit. Workflows that used the tag ran it.
  5. Defenses, one per hand-off. A lockfile fixes the exact version and its hash. Provenance says which source and build made a package. A commit SHA cannot be moved like a tag.
Step 1 of 5

Here are the common ways in:

  • Transitive dependencies. You add 5 packages. They can bring in hundreds more. OWASP says to track "not just your direct dependencies, but their (transitive) dependencies". 4 xz reached SSH through two hops. 1
  • Typosquatting. An attacker publishes reqeusts and waits for someone to mistype requests.
  • Dependency confusion. Your private package name also exists on a public index. From 25 to 30 December 2022, PyTorch nightly installs on Linux used a package called torchtriton from PyTorch's own index. Someone uploaded torchtriton to PyPI. Because the PyPI index took precedence, pip installed the fake one. 2 When imported, it read files such as $HOME/.ssh/* and sent them out through DNS queries. 2
  • Maintainer takeover. An attacker gets a maintainer's account or token, or becomes a maintainer, as in xz. The Shai-Hulud worm of 2025 stole npm tokens and used them to publish bad versions of other packages. It reached over 500 package versions. 4
  • Compromised build systems and CI. In March 2025, attackers moved several version tags of the GitHub Action tj-actions/changed-files to a malicious commit. The code read secrets from the runner's memory and printed them, encoded, in workflow logs. The bad code was live on 14 and 15 March 2025. GitHub's advisory says over 23,000 repositories used the action. 3

Lockfiles: know exactly what you install

A version range like ^4.17.0 means "any 4.x from 4.17 up". Each install can pick a different version. A lockfile fixes the whole tree. npm's package-lock.json lets later installs "generate identical trees, regardless of intermediate dependency updates". 5 For each package it stores where it came from and an integrity hash. 5 So a swapped file fails the install.

In CI, use the strict install. npm ci needs a lockfile. If the lockfile and package.json disagree, it "will exit with an error, instead of updating the package lock". It never writes to either file. 6 Python, Go and Rust tools have the same idea under other names.

Commit the lockfile. Review changes to it like code: a new package in the lockfile is new code in production.

Scanning: when to upgrade

A scanner such as Dependabot compares your dependency graph with an advisory database. It alerts when a new advisory affects a version you use. 7 GitHub is clear about the limits: "Alerts can't catch every security issue", and new flaws can take time to reach the database. 7 A scanner finds known flaws. It does not find a fresh backdoor.

So when should you upgrade? OWASP says to choose versions on purpose and "upgrade only when there is need". It also says to watch for libraries that are no longer maintained. 4 OWASP gives no time frames. Here is our own suggestion:

  • Critical flaw in code you actually call: upgrade within days, like any production bug.
  • Other alerts: batch them into a regular update, for example every two weeks.
  • A brand-new release with no security reason: wait, for example a few days. Others then have time to spot a bad release before you install it.

OWASP also suggests staged rollouts for updates, so one bad vendor release does not reach every system at once. 4

SBOM: the full list

A software bill of materials lists every component and version in what you ship. OWASP says to generate and manage it centrally for all your software. 4 When the next Log4Shell appears, you search your SBOMs instead of asking every team. Generate one per build artifact, in CI, and store it next to the artifact.

Signed builds and provenance

A lockfile says which version. It cannot say that the package was built from the source you think. The xz tarballs were not the same as git. 1

Provenance is a record of how an artifact was built: the source, the build platform and the inputs. 8 SLSA is a framework that grades this in build levels. 8

  • Build L0: nothing. "L0 represents the lack of SLSA." 8
  • Build L1: provenance exists. It helps prevent mistakes but "is trivial to bypass or forge". 8
  • Build L2: a hosted build platform makes and signs the provenance. This stops tampering after the build. 8
  • Build L3: a hardened build platform. Runs cannot affect each other, and build steps cannot reach the signing secret. This stops tampering during the build. 8

Signing used to mean guarding a long-lived private key. Sigstore removes that. The signer proves its identity with an OIDC token. Sigstore's certificate authority, Fulcio, issues a short-lived certificate, and the private key is thrown away after one signing. 9 Each signature goes into Rekor, a transparency log. It is append-only, and anyone can audit it. 9

You can use this today. On npm, npm publish --provenance from GitHub Actions or GitLab CI/CD signs provenance through Sigstore. Users check it with npm audit signatures. 10 npm is careful here: provenance "does not guarantee the package has no malicious code". 10 It proves where a package came from, not that the source is safe.

Hardening CI

Your CI runs third-party code with your secrets. The CI/CD lesson showed pinning briefly. Here is the full set.

permissions:
  contents: read        # default for every job: read-only
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      # pin to a full commit SHA, with the version as a comment
      - uses: actions/checkout@<full-commit-sha>  # v4
      - run: npm ci
  • Pin actions to a full commit SHA. GitHub warns that "a tag can be moved or deleted" by someone who gets access to the action's repo. 11 That is what happened to tj-actions. 3 Check that the SHA comes from the action's own repo, not a fork. 11
  • Give the token least privilege. Start with read-only contents. Raise permissions only for the job that needs them. 11 Use short-lived OIDC credentials for deploys, as in Secrets and key management.
  • Be careful with pull_request_target. It runs with privileges. Combined with checking out untrusted pull request code, GitHub says it can lead to repository takeover. 11
  • Keep pinned actions up to date. Dependabot can update action references. Its alerts do not cover actions pinned to a SHA, so plan regular updates. 11 7
  • Build once and promote. OWASP lists separation of duties, signed builds, environment-scoped secrets and promoting artifacts rather than rebuilding. 4

If a CI dependency is compromised, treat every secret it could read as leaked. Rotate them. 3

Section 4 of 8

Trade-offs

DefenseStopsDoes not stopCost
Lockfile plus npm ciYes Silent version changes and swapped files. 5A bad version you chose to lock.Low. Review lockfile diffs.
Vulnerability scanningYes Known CVEs in versions you use. 7No New backdoors and flaws not yet in the database. 7Low to start. Ongoing upgrade work.
SBOM per buildSlow answers to "are we affected?"No It only lists. It blocks nothing.Low. One CI step.
Provenance and signaturesYes Packages not built from the claimed source and workflow. 8No Malicious code in the real source. 10Medium. Build setup, and verify on install.
Actions pinned to SHAYes Moved tags. 11A bad commit you pinned yourself.Medium. You must update pins.
Least-privilege CI tokenDamage after a CI compromise. 11The compromise itself.Low.

Simple rule: lock and scan everything from day one. Pin CI actions and cut token permissions next. Add provenance for anything you publish.

Section 5 of 8

At work: how a senior uses this

  • In review, treat a lockfile diff as a code diff. Ask: "Why do we need this new package, and who maintains it?"
  • Before adding a dependency, check its downloads, maintainers, last release and its own dependency count. Prefer the standard library for small tasks.
  • Ask: "If this package turned bad tonight, which secrets could it read?" Install scripts and CI steps run with real credentials.
  • Use scoped or namespaced names for internal packages, and own the same names on public indexes. Point installs at one index you control.
  • Keep an SBOM per release, so "are we affected?" takes minutes.
  • Set a written patch deadline for critical CVEs, and track it like a bug.
  • Pin every third-party action to a SHA. Set permissions: contents: read at the top of every workflow.
Section 6 of 8

With AI

Coding agents add packages to fix problems. They can also suggest package names that do not exist. One study of 576,000 code samples found that, on average, at least 5.2% of the packages from commercial models did not exist. For open-source models it was 21.7%. 12 Attackers can register those names. This is called slopsquatting.

What to ask the agent

"List every direct dependency in this repo with its version, last release date and number of maintainers. Flag any package that is unmaintained or has fewer than 1,000 weekly downloads."

"Find every GitHub Action in .github/workflows that is not pinned to a full commit SHA. Propose the pinned line with the version as a comment. Do not change behaviour."

"Add a top-level permissions: contents: read to each workflow. Then list which jobs need more, and why."

What to check yourself

  • Every package the agent added really exists, is the one you meant, and is in the lockfile.
  • The agent did not change the lockfile in ways the task did not need.
  • Each pinned SHA comes from the action's own repo, not a fork.
  • The agent did not add pull_request_target or wider token permissions to make a workflow pass.
  • No new install script runs during the build without a reason.
Section 7 of 8

Check yourself

1. In the 2024 xz backdoor, where was the line that started the hidden build step?

Show answer

In the release tarballs only. The Git repository did not have the line that started it. Freund found that the line in build-to-host.m4 that ran the hidden script was only in the distributed tarballs, not in git.

2. Your workflow has uses: some-org/lint-action@v3. What is the main supply-chain risk?

Show answer

Someone with access to that repo can move the v3 tag to a new, harmful commit. GitHub warns that a tag can be moved or deleted. In the tj-actions attack, tags were moved to a malicious commit. A full commit SHA cannot be moved.

3. Your app installs an internal package acme-utils from a private index, with the public index as an extra source. What best stops dependency confusion?

Show answer

Own the name on the public index too, and install internal packages only from the index you control. PyTorch was hit because pip preferred the public index. Its fix included a placeholder package on PyPI. A scanner only knows about published flaws.

4. A package's provenance is made by a script on a developer laptop and is not signed. What is the highest SLSA build level it can claim?

Show answer

Build L1. Provenance exists, but it is easy to forge. L2 needs a hosted build platform that signs the provenance. Unsigned provenance from a laptop shows how it was built, but anyone could fake it.

5. npm shows a verified provenance attestation for a package. What does that tell you?

Show answer

Which source repository and CI build produced it. Provenance links the package to its source and build. npm says it does not guarantee the package has no malicious code.

Your progress is saved only in this browser. Export it to keep it safe.

Was this clear?
Report a mistake (opens GitHub in a new tab)
Section 8 of 8

Go deeper

Show 12 sources and related lessons
  1. Andres Freund, “backdoor in upstream xz/liblzma leading to ssh server compromise”, oss-security mailing list (29 March 2024) (opens in a new tab)
    The first public report. How slow SSH logins led to a backdoor hidden in the xz release tarballs.
  2. PyTorch blog, “Compromised PyTorch-nightly dependency chain between December 25th and December 30th, 2022.” (opens in a new tab)
    A real dependency confusion attack. Why pip picked the fake package, what it stole, and how PyTorch fixed it.
  3. GitHub Advisory Database, “tj-actions changed-files through 45.0.7 allows remote attackers to discover secrets by reading actions logs.” (GHSA-mrrh-fwg8-r2c3) (opens in a new tab)
    How moved tags made thousands of CI workflows print their secrets into logs.
  4. OWASP Top 10:2025, A03:2025 Software Supply Chain Failures (opens in a new tab)
    Real attacks such as Shai-Hulud, and a prevention list from SBOMs to signed builds.
  5. npm Docs, “package-lock.json” (opens in a new tab)
    What the lockfile records, including where each package came from and its integrity hash.
  6. npm Docs, “npm-ci” (opens in a new tab)
    The install command for CI, which fails instead of changing the lockfile.
  7. GitHub Docs, “Dependabot alerts” (opens in a new tab)
    How a scanner matches your dependency graph against an advisory database, and its limits.
  8. SLSA v1.2, “Build: Track Basics”, slsa.dev (opens in a new tab)
    The four build levels, L0 to L3, and the threats each one stops.
  9. Sigstore documentation, “Overview” (opens in a new tab)
    Keyless signing with short-lived certificates, Cosign, Fulcio and the Rekor log.
  10. npm Docs, “Generating provenance statements” (opens in a new tab)
    How to publish an npm package with provenance from CI, and how users check it.
  11. GitHub Docs, “Secure use reference” (opens in a new tab)
    Pinning actions to a commit SHA, token permissions, and risky triggers.
  12. Spracklen et al., “We Have a Package for You! A Comprehensive Analysis of Package Hallucinations by Code Generating LLMs”, USENIX Security 2025 (arXiv 2406.10279) (opens in a new tab)
    How often code models invent package names that do not exist, across 576,000 code samples.

Real incident: xz-utils (open source), 29 Mar 2024: xz/liblzma: a backdoor hidden in release tarballs reached the SSH server

Related: OWASP Top 10 and secure coding · Secrets and key management · CI/CD and trunk-based development · Reviewing code written by humans and AI · Working with coding agents · Threat modelling and zero trust

Term

See full entry

Jump to a section

  1. 1What broke
  2. 2The idea in simple words
  3. 3How it works
  4. 4Trade-offs
  5. 5At work
  6. 6With AI
  7. 7Check yourself
  8. 8Go deeper