A typical web application ships a few thousand lines of its own code and hundreds of thousands of lines from dependencies, plus build tools, CI actions, base images, and package registries. Each of them is a path for an attacker into what you deploy. Software supply chain failures are new in the OWASP Top 10:2025, at third place, because attacks on this chain have become common and damaging. This lesson covers the main attack types, then the practical defenses: locking and reviewing dependencies, software bills of materials (SBOMs), hardened CI/CD pipelines, and deploying only artifacts you can trace.
Before you start
You should know how your package manager installs dependencies and how your CI system runs workflows. Read OWASP Top 10 Explained for where this category fits, and Threat Modeling and Secure-by-Design Software Architecture for trust boundaries, which you'll apply to the build pipeline itself. Examples use npm and pnpm, and GitHub Actions.
How supply chain attacks happen
Several distinct attack types share the label:
- Known vulnerabilities in dependencies you use, left unpatched. The most common problem, and the easiest to detect.
- Malicious packages: typosquats (a package named one letter off a popular one), dependency confusion (a public package with the same name as your private one), and packages created to steal credentials during installation.
- Compromised maintainers: an attacker takes over a legitimate maintainer's account or token and publishes a malicious version of a trusted package. In 2025, self-spreading malware in the npm ecosystem used stolen tokens to publish infected versions of many packages.
- Compromised build tools and CI actions: in March 2025, the widely used GitHub Action
tj-actions/changed-fileswas modified so that its existing version tags pointed at code that printed CI secrets into build logs. Every workflow that referenced it by tag ran the attacker's code. - Long-term infiltration: the 2024 backdoor in the xz compression library was planted by a contributor who spent years earning maintainer trust.
The common lesson: anything that runs during install, build, or deploy runs with your pipeline's privileges, and version labels can change underneath you.
Lock what you install
A lockfile (package-lock.json, pnpm-lock.yaml, yarn.lock) records the exact version and integrity hash of every package, including transitive dependencies. Commit it, and install from it exactly in CI:
# npm: installs exactly what the lockfile says, and fails if package.json disagrees
npm ci
# pnpm: the same strict install
pnpm install --frozen-lockfileReview lockfile changes in pull requests the same way you review code. An unexpected new dependency, or a package whose resolved URL points somewhere unusual, deserves a question.
Reduce what install scripts can do
Packages can run arbitrary scripts when installed (preinstall, postinstall). This is how many malicious packages steal tokens. pnpm 10 doesn't run dependency lifecycle scripts unless you allow them per package. With npm, you can disable them and enable selectively:
npm ci --ignore-scriptsAnother useful control is a minimum release age: refusing versions published only hours ago gives the community time to detect a malicious release. pnpm supports this with the minimumReleaseAge setting; dependency update bots can be configured to wait similarly.
Find and fix known vulnerabilities
Scan dependencies against vulnerability databases on every pull request and on a schedule, because new advisories appear for code you haven't changed:
npm audit --omit=dev
pnpm audit --prod
# OSV-Scanner checks lockfiles against the open OSV database, across ecosystems
osv-scanner scan --lockfile=pnpm-lock.yamlNot every advisory matters equally. Ask whether the vulnerable code is reachable in your application, whether it's a production or development dependency, and whether an exploit is public. Fix critical, reachable issues quickly; schedule the rest. Automated update tools such as Dependabot or Renovate open pull requests for updates, which keeps the backlog small. Pair them with tests so updates can be merged with confidence.
Choose dependencies deliberately
Each new dependency is a long-term trust decision. Before adding one, check that it's maintained, widely used, has a clear security policy, and does something you can't reasonably write in a few lines. Prefer the platform's built-in features: Node.js now provides fetch, a test runner, crypto.randomUUID, and more.
Software bills of materials
A software bill of materials (SBOM) is a machine-readable list of every component in a piece of software, with versions and identifiers. The two main formats are CycloneDX (an OWASP project) and SPDX (an ISO standard). An SBOM lets you answer "are we affected?" in minutes when the next major vulnerability is announced, and lets your customers do the same.
# npm 10 and newer can generate an SBOM from the installed tree
npm sbom --sbom-format cyclonedx --omit dev > sbom.cdx.jsonGenerate the SBOM in CI for every release, store it with the artifact, and feed it to a scanner that alerts you when a new advisory matches a component you ship. An SBOM is an inventory, not a security guarantee: it's only as useful as the process that reads it.
Harden the CI/CD pipeline
Your CI system has the keys to production: deploy credentials, signing keys, package publishing tokens. Treat it as one of your most sensitive systems.
Pin actions to commit SHAs
A tag like @v4 can be moved to different code, as the tj-actions incident showed. A full commit SHA can't. Pin third-party actions by SHA, with the version in a comment for readability, and let an update bot propose new SHAs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1Grant minimal permissions
GitHub Actions gives each workflow a GITHUB_TOKEN. Set its permissions explicitly to the minimum, at the workflow level, and widen them only for the jobs that need it:
name: ci
on:
pull_request:
push:
branches: [main]
permissions:
contents: read # the default for every job in this workflow
jobs:
verify:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 24
- run: npm ci --ignore-scripts
- run: npm test
- run: npm audit --omit=dev --audit-level=highKeep untrusted code away from secrets
Pull requests from forks contain code you haven't reviewed. GitHub doesn't give secrets to pull_request workflows from forks, which is the safe default. The pull_request_target trigger runs with secrets and write permissions, and checking out and running the pull request's code in such a workflow hands that code your secrets. Avoid this pattern unless you fully understand it. Also avoid interpolating untrusted values such as issue titles or branch names directly into run: scripts, where they can inject shell commands; pass them through environment variables instead.
Use short-lived credentials
Instead of storing long-lived cloud keys as CI secrets, use OpenID Connect (OIDC) federation: the cloud provider trusts tokens that GitHub issues for a specific repository, branch, and workflow, and exchanges them for credentials that expire within an hour. Restrict the trust policy to the exact repository and branch that deploys. For npm, trusted publishing similarly lets CI publish packages without a stored token.
Protect branches and environments
Require pull request reviews and passing checks before merging to deployment branches. Use protected environments with required reviewers for production deploys, so a workflow change alone can't deploy. Restrict who can change workflow files.
Deploy only what you built
The final link in the chain is making sure what reaches production is exactly what your pipeline built from reviewed source:
- Build once, deploy that artifact. Don't rebuild on the server; upload the artifact the verified CI job produced. Rebuilding elsewhere reintroduces every risk you just controlled.
- Record provenance. Build provenance is a signed statement of what source, workflow, and inputs produced an artifact. The SLSA framework defines levels of build integrity, and GitHub's artifact attestations and npm's provenance generate such statements.
- Verify before deploy. Check the artifact's digest or attestation in the deploy job, and deploy by digest rather than by mutable tag (for container images,
image@sha256:...rather thanimage:latest).
attest:
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write # for the signing certificate
attestations: write
steps:
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: web-build
- uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2
with:
subject-path: web-build.tar.gzThe SHAs in these examples were the latest releases of each action in November 2026. Newer releases will have appeared by the time you read this, so look up the commit for the release you choose in the action's own repository, rather than copying a SHA from an article.
Common mistakes and troubleshooting
- Installing without the lockfile in CI.
npm installcan change versions; usenpm cior--frozen-lockfile. - Pinning actions by tag. Tags can be moved; pin by full SHA.
- Broad default token permissions. Set
permissionsexplicitly in every workflow. pull_request_targetrunning fork code. It exposes secrets to untrusted code.- Long-lived cloud keys in CI secrets. Use OIDC federation.
- Building on the production server. Deploy the artifact CI built and verified.
- Ignoring audit output because it's noisy. Triage by reachability and severity, and keep the backlog small with automated updates.
If npm ci fails with "lockfile out of sync," regenerate the lockfile locally with npm install, review the diff, and commit it; never paper over it in CI with npm install.
Practical exercise: secure one pipeline
For a repository you maintain:
- Confirm the lockfile is committed and CI installs with
npm cior--frozen-lockfile. - Run
npm auditorosv-scanner, and triage every high or critical finding. - Generate a CycloneDX SBOM in CI and store it with the build.
- Pin every third-party action by commit SHA, and add
permissions: contents: readat the top of each workflow. - Check that no workflow uses
pull_request_targetwith a checkout of the pull request's code. - Write down where long-lived secrets are stored, and plan to replace one with OIDC.
Key takeaways
- Supply chain risks include vulnerable dependencies, malicious packages, hijacked maintainers, and compromised CI actions.
- Commit lockfiles, install exactly from them, restrict install scripts, and scan dependencies continuously.
- SBOMs (CycloneDX or SPDX) let you answer "are we affected?" quickly.
- Pin actions by SHA, grant minimal token permissions, keep fork code away from secrets, and use OIDC.
- Build once in CI, record provenance, and deploy only that verified artifact.
References
- OWASP Top 10:2025, A03 Software Supply Chain Failures (opens in a new tab)
- GitHub Docs: Security hardening for GitHub Actions (opens in a new tab)
- GitHub Docs: Artifact attestations (opens in a new tab)
- SLSA: Supply-chain Levels for Software Artifacts (opens in a new tab)
- CycloneDX (opens in a new tab)
- npm Docs: npm sbom (opens in a new tab)
- OSV-Scanner (opens in a new tab)
- pnpm: Settings (minimumReleaseAge) (opens in a new tab)
What's next
With the code and the pipeline under control, the next question is what your application does with the data it holds. Privacy Engineering: Encryption, Retention, Deletion, and Data Protection turns the privacy principles from the Basic level into working code.

