00->1
Learning pathStep 35 of 62Web and technical attacks ← All writeups

Software Supply Chain Security, Explained

If you are reading this, you have probably seen "supply chain attack" in the news and noticed that OWASP moved Software Supply Chain Failures into the Top 10 for 2025 (as category A03). You want to know what it means and what a normal developer or defender can actually do about it.

By the end you will be able to explain what the software supply chain is, name the places it can break, describe two real incidents (Log4Shell and the xz backdoor) and what each teaches, say what a software bill of materials (SBOM) is and why it helps, and use pip's hash-checking mode to refuse a package that does not match what you expected.

You should know what a vulnerability is (Threats and Vulnerabilities) and have seen the OWASP list (Web-Based Attacks and the OWASP Top 10). The lab uses Python (Python Basics for Security).


1. What the software supply chain is

Almost no program is written from scratch. A typical application includes libraries written by others, uses build tools and automation to assemble and test it, and receives updates from outside. Each of those pieces, and each person and system that produces them, is part of the software supply chain.

OWASP defines the failure like this: "Software supply chain failures are breakdowns or other compromises in the process of building, distributing, or updating software." They are "often caused by vulnerabilities or malicious changes in third-party code, tools, or other dependencies" (OWASP Top 10:2025, A03).

NIST's guidance on the subject, SP 800-161 Rev. 1, describes the risk behind it in its abstract: products and services can contain malicious functionality, be counterfeit, or be vulnerable because of weak manufacturing or development practices, and these risks stem largely from organizations having limited visibility into how the technology they acquire is developed, integrated and deployed (NIST SP 800-161 Rev. 1).

The key idea: you inherit the security of everything you include. If a library has a flaw, your program has it. If a tool you use to build is compromised, the program you ship may be too.

Direct and transitive dependencies

A direct dependency is a library you chose. A transitive dependency is a library that one of your libraries uses, and so on down the chain. You may depend on dozens of packages you never heard of. OWASP's advice is to "track not just your direct dependencies, but their (transitive) dependencies, and so on."


2. Where the chain can break

Link in the chain What can go wrong Example in this post
A library you use It contains a vulnerability, discovered later Log4Shell (section 3)
The source or the release A malicious change is added upstream, or to the packaged release The xz backdoor (section 4)
A vendor or update channel OWASP: "A trusted vendor is compromised with malware, leading to your computer systems being compromised when you upgrade" See also Watering Hole Attack, which covers the CCleaner case
A look-alike package You install a fake with a name close to the real one Typosquatting
Developer and build tools The tools that build your software are themselves software. OWASP advises updating your "CI/CD, IDE, and any other developer tooling regularly"
Secrets in the environment OWASP describes a self-propagating npm worm whose malware would "detect npm tokens in the victim environment" Git and GitHub on keeping secrets out of reach
Everything runs with your privileges OWASP: "Components typically run with the same privileges as the application itself", so a bad component gets all of them Security Design Principles on least privilege

3. Case 1: Log4Shell, a vulnerable dependency (2021)

Apache Log4j is a widely used Java logging library. The CVE record for CVE-2021-44228, published on 10 December 2021, describes the flaw: in Log4j2 versions 2.0-beta9 through 2.15.0 (with a few exceptions for security releases), JNDI features "do not protect against attacker controlled LDAP and other JNDI related endpoints". "An attacker who can control log messages or log message parameters can execute arbitrary code loaded from LDAP servers when message lookup substitution is enabled." From 2.15.0 the behaviour was disabled by default, and from 2.16.0 the functionality "has been completely removed" (CVE record CVE-2021-44228). The scoring details and the weakness types are worked through in Threats and Vulnerabilities.

What makes it a supply chain lesson is not the bug itself but what kind of thing it was: a library that other software includes. A product can contain a library its owners never chose directly, because something they did choose depends on it. If you cannot list what you use, you cannot tell whether you are affected. That is the problem an inventory (an SBOM, section 5) is meant to solve.


4. Case 2: the xz backdoor, a malicious change (2024)

xz is a common compression tool and library (liblzma). On 29 March 2024, the developer Andres Freund posted to the oss-security mailing list: after "a few odd symptoms around liblzma ... on Debian sid installations over the last weeks (logins with ssh taking a lot of CPU, valgrind errors)", he "figured out the answer: The upstream xz repository and the xz tarballs have been backdoored." (Freund's message on oss-security.) The flaw was assigned CVE-2024-3094, whose CVE record describes "malicious code ... in the upstream tarballs of xz, starting with version 5.6.0", with a CVSS v3.1 base score of 10.0 (Critical) in the record's scoring from Red Hat (CVE record).

What the original message tells us:

  • Part of the backdoor existed only in the release tarballs. Freund wrote that one portion "is solely in the distributed tarballs": a line in the build files that is not in the upstream git source, and which injected an obfuscated script to run at the end of the configure step. He excepted the "source code" links on the release pages, which he believed GitHub generates directly from the repository contents. In other words, what people downloaded was not the same as what was in the public repository.
  • The rest was hidden in files that looked like tests. The bulk of the exploit was in obfuscated form in two test files committed to the repository, which were not used for any tests in 5.6.0.
  • The code was selective. The script decided whether to modify the build, for example targeting only x86-64 Linux, a particular compiler and linker, and builds running as part of a Debian or RPM package build. Freund noted this was likely aimed at making it harder for investigators to reproduce.
  • It was found by a side effect. The backdoor made logins over SSH slower. Freund measured one test as 0.299 seconds before and 0.807 seconds after. OpenSSH does not use liblzma directly, but he explained that Debian and several other distributions patch it to support systemd notifications, and libsystemd depends on lzma.
  • The reach was limited by luck. He wrote that versions 5.6.0 and 5.6.1 "have not yet widely been integrated by linux distributions, and where they have, mostly in pre-release versions."

On who was responsible, Freund was careful: "the committer is either directly involved or there was some quite severe compromise of their system", and he judged the latter "the less likely explanation". This post does not go beyond what that message says.

What the xz case teaches

Lesson Why
Trust is part of the chain. Open source code is only as safe as its maintenance and review The malicious change arrived through the project's own upstream repository and releases
Release artifacts can differ from the source. Part of the backdoor existed only in the tarballs. Comparing what you build with what is in the repository is one way to notice
Small anomalies matter. A slow login and valgrind errors led to the discovery. Performance and logging oddities can be the first sign
Slow adoption of new versions limited the damage Freund noted the affected versions had not yet been widely adopted. OWASP's advice to "deliberately choose which version of a dependency you use and upgrade only when there is need" and to avoid "deploying updates to all systems simultaneously" matches this: staged rollouts limit the damage of a bad release

5. Defences

OWASP's prevention list for A03 is a good checklist (OWASP A03):

Practice Meaning
Keep a software bill of materials "Centrally generate and manage the Software Bill of Materials (SBOM) of your entire software"
Track transitive dependencies Not just the ones you chose
Remove what you do not need "Reduce attack surface by removing unused dependencies, unnecessary features, components, files, and documentation"
Keep an inventory and watch for vulnerabilities "Continuously inventory the versions of both client-side and server-side components" and monitor sources such as CVE and the National Vulnerability Database
Use official sources over secure links "Only obtain components from official (trusted) sources over secure links"
Choose versions on purpose Upgrade when there is a need, not blindly
Watch for unmaintained components Libraries that no longer receive security patches
Update your own tooling CI/CD, IDE and other developer tools
Roll out gradually "Avoid deploying updates to all systems simultaneously"

What an SBOM is

The US Department of Commerce, working with NTIA, published "The Minimum Elements for a Software Bill of Materials (SBOM)" on 12 July 2021, as required by Executive Order 14028. It defines an SBOM as "a formal record containing the details and supply chain relationships of various components used in building software" (NTIA report). Think of it as the ingredients list for software.

The report sets out the baseline data for each component:

Field Meaning (NTIA)
Supplier Name The entity that creates, defines and identifies the component
Component Name The name the supplier gave the unit of software
Version of the Component The identifier the supplier uses for a change from an earlier version
Other Unique Identifiers Other identifiers, or look-up keys for databases
Dependency Relationship That an upstream component X is included in software Y
Author of SBOM Data Who created the SBOM data
Timestamp When the SBOM data was assembled

It names three data formats used to create and read SBOMs: SPDX, CycloneDX and SWID tags. An SBOM does not make software safer on its own. It makes one question answerable fast: "which of our products contain component X at version Y?" That is the Log4Shell question.

Pinning versions and checking hashes

If you install packages by name alone, you get whatever is newest or whatever the server hands you. Two controls tighten that:

  1. Pinning fixes the exact version.
  2. Hash checking fixes the exact file. The pip documentation says hash-checking mode "uses local hashes, embedded in a requirements.txt file, to protect against remote tampering and network issues", requires that "Requirements must be pinned (either to a URL, filesystem path or using ==)", and can be forced with --require-hashes (pip: Secure installs).

Hashes are the same fingerprints you met in Cryptography Basics: if even one byte of the package changes, the hash changes, and the install is refused.


6. Hands-on: make pip refuse a bad package

This lab installs one tiny, widely used Python package called six into a throwaway virtual environment. Everything stays in a folder you can delete. You need Python 3 and an internet connection. See Python Basics for Security for virtual environments. The commands were tested with Python 3.12 and pip 26.2 in a fresh virtual environment, and the exact wording of pip's messages may differ in other versions.

Step 1: download a package and compute its hash

mkdir pip-lab && cd pip-lab
python3 -m pip download six==1.16.0 --no-deps -d .
python3 -m pip hash six-1.16.0-py2.py3-none-any.whl
six-1.16.0-py2.py3-none-any.whl:
--hash=sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254

pip hash prints the SHA-256 fingerprint of the file in the format a requirements file expects. To make sure the value is not just something your own download produced, compare it with the digest the package index publishes for that version. For example, PyPI's JSON page for this release (https://pypi.org/pypi/six/1.16.0/json) lists the same SHA-256 for the .whl file.

Step 2: install with the right hash

Create a virtual environment and a requirements file:

python3 -m venv .venv
printf 'six==1.16.0 \\\n    --hash=sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254\n' > good.txt
.venv/bin/pip install --require-hashes -r good.txt
Successfully installed six-1.16.0

Step 3: install with a wrong hash

printf 'six==1.16.0 \\\n    --hash=sha256:0000000000000000000000000000000000000000000000000000000000000000\n' > bad.txt
.venv/bin/pip install --require-hashes -r bad.txt
ERROR: THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS FILE. If you have updated the package versions, please update the hashes. Otherwise, examine the package contents carefully; someone may have tampered with them.
    six==1.16.0 from https://files.pythonhosted.org/packages/.../six-1.16.0-py2.py3-none-any.whl (from -r bad.txt (line 1)):
        Expected sha256 0000000000000000000000000000000000000000000000000000000000000000
             Got        8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254

pip downloaded the file, hashed it, saw that it did not match the expectation, and refused. If an attacker had swapped the package on the server or in transit, this is how you would find out.

Step 4: try an unpinned requirement

printf 'six\n' > unpinned.txt
.venv/bin/pip install --require-hashes -r unpinned.txt
ERROR: In --require-hashes mode, all requirements must have their versions pinned with ==. These do not:
    six from https://files.pythonhosted.org/packages/.../six-1.17.0-py2.py3-none-any.whl (from -r unpinned.txt (line 1))

Without a pinned version there is nothing to attach a hash to, so pip refuses. (The message shows the newer release, 1.17.0, that pip would have picked. This is exactly the "whatever is newest" behaviour that pinning prevents.)

Step 5: a tiny inventory

.venv/bin/pip install --require-hashes -r good.txt
.venv/bin/pip freeze
# six==1.16.0

pip freeze lists what is installed in the environment with exact versions: a very small cousin of an SBOM. Real SBOMs add suppliers, identifiers and relationships, and are produced with dedicated tools, but the idea is the same: know exactly what you are running.

Delete the lab when you finish: remove the pip-lab folder.

Step 6: read a real CVE record

The CVE project publishes records as data. You can read the xz record yourself:

curl -s https://cveawg.mitre.org/api/cve/CVE-2024-3094 | python3 -m json.tool | head -20

Look for the fields cveId, state, the description text and the metrics section. Then do the same for CVE-2021-44228 and compare how the two descriptions are written.


7. Common mistakes

Mistake The facts
"I only use a few libraries" Each one has its own dependencies. Count the whole tree, not just what you chose
"Open source is safe because everyone can read it" The xz change was in open source code. Code review only helps if someone actually does it
"The release matches the repository" In the xz case, part of the backdoor existed only in the release tarballs
"pip install name is fine" Names can be mistyped or faked, and newest is not always safest. Pin versions and use hashes where it matters
"We'll update everything immediately" Immediate, simultaneous updates also spread a bad release. Stage them, but still patch known-exploited flaws quickly
"We never update, so we are stable" Unmaintained components are a risk too, OWASP lists them explicitly
"An SBOM makes us secure" It makes you faster at answering "do we use this?". You still have to act on the answer
"Pinning hashes solves the supply chain" It protects against a file changing after you trusted it. It does not help if the trusted version was malicious from the start
"Our CI server is just infrastructure" Build tools are software in the chain. Patch them and limit what they can reach
"Secrets in the build environment are fine" Malware that runs in a build or install can read them. Keep tokens minimal and short-lived

Closing

Your software is a stack of other people's work, and each layer is a place where things can go wrong: a vulnerable library (Log4Shell), a malicious change (xz), a fake name (typosquatting) or a compromised vendor. You cannot audit everything, but you can know what you use, choose versions deliberately, check what you download, limit what components can do, and be ready to answer quickly when a new flaw is announced.

Keep these points:

  • You inherit the security of your dependencies, including the ones you never chose.
  • Inventory first. An SBOM turns "do we use it?" from a week-long hunt into a query.
  • Pin versions and check hashes for packages that matter.
  • Official sources, secure links, and watch the names.
  • Release artifacts can differ from the source, and small oddities can reveal big problems.
  • Roll out updates in stages, while still patching known-exploited flaws promptly.
  • Least privilege for components, and keep secrets out of build and install environments.

If you can explain, for Log4Shell and for xz, which link in the chain failed and what control would have helped, you understand the foundation.

Related: Typosquatting covers the look-alike package risk, Threats and Vulnerabilities covers CVE records and how to prioritize patches, and Git and GitHub covers keeping secrets out of repositories.