TExcelTAD

Supply-Chain Attacks

You can patch every server, enforce MFA and review every line your team writes, and still ship malicious code, because most of the code you run was written by someone else. A typical web application pulls in hundreds of open-source packages, is built by a CI service, packaged into a container image based on someone else's image, and updated by an agent that talks to a vendor's server. Each of those is a link in the software supply chain, and an attacker who controls one link reaches every customer downstream at once.

That leverage is why supply-chain attacks are among the most damaging incidents on record. A handful of well-known cases show the different links:

Case (year) Link that was attacked What happened
event-stream (2018) Maintainer handover A new maintainer of a popular npm package added a dependency that targeted one cryptocurrency wallet app
SolarWinds Orion (2020) Build system Attackers changed the vendor's build so that signed, official updates contained a backdoor
Codecov (2021) Distribution script A modified uploader script in CI copied environment variables (secrets) to the attacker
xz utils, CVE-2024-3094 (2024) Long-term maintainer trust A contributor who had gained co-maintainer rights over two years hid a backdoor in release tarballs; found by chance before wide release

The Supply-Chain Security course covers the tooling in depth (SBOMs, scanners, signatures, SLSA). This lesson gives the map: the attack classes, how they are detected and the core defences.

The chain and where it breaks

source dependencies build / CI registry consumer stolen devaccount typosquat,confusion tamperedbuild step swappedartifact hijackedupdater defences: pin by hash, verify signatures and provenance, SBOM + scanning, least privilege for CI, private registry scopes

The attack classes

  • Malicious packages and typosquatting. The attacker publishes a package whose name is one keystroke away from a popular one (reqeusts for requests) and waits for typos in install commands. The package's install script runs with the developer's rights. See malicious packages.
  • Dependency confusion. A company uses an internal package acme-billing from its private registry. If the build tool also asks the public registry and prefers the higher version number, an attacker who publishes acme-billing 99.0.0 publicly gets installed instead. See dependency confusion.
  • Compromised maintainer or account. A stolen registry token or a social-engineered handover lets the attacker publish a malicious legitimate version. Everything about it looks normal, including the name.
  • Compromised build. The source is clean but the build machine injects code, so the signed output is malicious (SolarWinds). Only a reproducible build or independent provenance reveals the difference.
  • Swapped artifacts and hijacked updates. A download mirror, a CDN or an updater channel without signature checks serves a different file than the one the vendor built.

Detection: is this the file we meant to get?

The basic check against swapped artifacts is to compare the downloaded file's hash with the one the publisher listed, over a channel the attacker does not control. sha256sum -c does it for a whole list. The session below runs in your sandbox: it "publishes" two release files with their checksums, then a mirror swaps one byte in one of them.

bash · try it yourself
mkdir release mirror
printf 'tool v1.4.2\n' > release/tool-1.4.2.tar
printf 'docs v1.4.2\n' > release/docs-1.4.2.tar
(cd release && sha256sum *.tar > SHA256SUMS && cat SHA256SUMS)
cp release/* mirror/
printf 'tool v1.4.2!\n' > mirror/tool-1.4.2.tar      # the mirror serves a modified file
cd mirror && sha256sum -c SHA256SUMS; echo "exit code: $?"
5c9cb6ae313b36a543d65a0fd58eda9827a83c5b00e01713506ddea2f99456dc  docs-1.4.2.tar
3f14037a5d86c227c7ddee4397bc79031a77861caf11f459941d3e0ca02536e1  tool-1.4.2.tar
docs-1.4.2.tar: OK
tool-1.4.2.tar: FAILED
sha256sum: WARNING: 1 computed checksum did NOT match
exit code: 1

A non-zero exit code stops the install script or pipeline. Note the weak point: if the attacker can change the file and SHA256SUMS on the same server, the check passes. That is why publishers sign the checksum file or the artifact (GPG, Sigstore's cosign) and why package managers record hashes in a lock file at the moment a dependency is first reviewed.

The same idea at the level of a project's dependencies, plus a check for look-alike names, in Python:

python · try it yourself
import hashlib

def levenshtein(a, b):
    prev = list(range(len(b) + 1))
    for i, ca in enumerate(a, 1):
        cur = [i]
        for j, cb in enumerate(b, 1):
            cur.append(min(prev[j] + 1, cur[j - 1] + 1, prev[j - 1] + (ca != cb)))
        prev = cur
    return prev[-1]

POPULAR = ["requests", "numpy", "pandas", "urllib3", "cryptography", "django"]

# lock file: name -> sha256 recorded when the dependency was reviewed (synthetic contents)
lock = {name: hashlib.sha256(f"{name}-release".encode()).hexdigest()
        for name in ["requests", "numpy", "internal-billing"]}

# what the build actually downloaded this time
downloaded = {
    "requests": b"requests-release",
    "numpy": b"numpy-release-with-extra-code",      # contents changed since review
    "internal-billing": b"internal-billing-release",
    "reqeusts": b"something",                       # a new name nobody reviewed
}

for name, data in downloaded.items():
    digest = hashlib.sha256(data).hexdigest()
    if name not in lock:
        near = [p for p in POPULAR if 0 < levenshtein(name, p) <= 2]
        hint = f", looks like {near[0]!r}" if near else ""
        print(f"BLOCK {name:16} not in lock file{hint}")
    elif digest != lock[name]:
        print(f"BLOCK {name:16} hash {digest[:12]} != locked {lock[name][:12]}")
    else:
        print(f"ok    {name:16} {digest[:12]}")
ok    requests         0494f961ca2c
BLOCK numpy            hash 65c9e5bf9a09 != locked adc06a505fe4
ok    internal-billing 3e90bf229b95
BLOCK reqeusts         not in lock file, looks like 'requests'

Two more detection sources matter in practice: software composition analysis (scanning an SBOM against vulnerability databases, the Grype and Trivy lessons) for known-bad versions, and behaviour at build and run time: a test suite that suddenly opens network connections, or a build agent uploading data to an unknown host, is a warning sign that no hash will show.

Prevention

Risk Control
Typos, new packages Review every new dependency; allow-list or a curated internal mirror; tools that flag look-alike names
Dependency confusion Reserve your internal names publicly or use scoped names (@acme/billing); configure one registry per scope; never "fall back" to the public registry
Changed versions Lock files with hashes (hash pinning); update deliberately, through reviewed pull requests
Tampered artifacts Verify signatures and provenance (signatures, SLSA levels)
Compromised build Ephemeral, isolated CI runners; short-lived credentials; reproducible builds; separate the signing key from the build job
Stolen maintainer accounts Phishing-resistant MFA for registry and code-host accounts; branch protection; two-person review for releases

None of these is enough alone. The xz backdoor passed code review because it lived in test files and the release tarball differed from the repository; it was caught because an engineer noticed SSH logins taking 0.5 seconds longer than usual. Defence in depth plus attention to anomalies is the real control.

Pitfalls

  • Trusting the checksum next to the file. It only protects against corruption, not against an attacker who controls the server. Use signed checksums or a lock file from your own review.
  • Pinning versions, not hashes. numpy==2.2.0 trusts whatever file a mirror or proxy serves under that version; a hash pins the exact bytes you reviewed.
  • "It's popular, so it's safe." Popular packages are the most valuable targets. Popularity tells you many people would notice a problem eventually, not that it has been reviewed.
  • CI with production secrets for every job. A malicious test dependency then runs next to your cloud keys. Give each job only the secrets it needs.

Practice

  1. In the Python example, the attacker manages to publish numpy contents that hash to the locked value. Is that a realistic threat?
  2. Your company's internal package is billing-core. List two configuration changes that stop dependency confusion.
Answers
  1. No. That needs a second preimage for SHA-256, which nobody can compute. The realistic threats are around the hash: a lock file updated without review, or a compromised version that was malicious before it was locked.
  2. Rename it under a scope you own (@acme/billing-core) and point that scope at the private registry only; and/or register the same name on the public registry as a placeholder, and configure the package manager so it never mixes registries for one name (pip: an index for internal packages only, no --extra-index-url).

Test yourself

In the sandbox session, why did sha256sum -c report tool-1.4.2.tar: FAILED?

  1. The file was missing
  2. The mirror's copy differed by one character, so its SHA-256 no longer matched the published value
  3. SHA256SUMS was signed with the wrong key
  4. sha256sum cannot check .tar files

What is dependency confusion?

  1. Two packages with the same version number
  2. A build that installs a public package with the same name as an internal one, usually because it has a higher version
  3. A circular dependency
  4. A lock file in the wrong format

Which attack does verifying the checksum file published on the same download server NOT stop?

  1. Accidental corruption during download
  2. An attacker who controls the server and replaces both the file and the checksum
  3. A flipped bit on a disk
  4. A truncated download

The SolarWinds compromise is an example of which link being attacked?

  1. A typosquatted package
  2. The vendor's build system, so signed official updates were malicious
  3. A user's weak password
  4. A DNS record