Skip to main content
Security guideReviewed

Supply chain attacks: how a compromised package or script reaches your website, and what to do first

A supply chain attack reaches a website through code you trust but did not write: a package your build installs, a step in your pipeline, or a script your pages load from someone else's server.

This guide explains each route at the level a defender needs to recognise it, the signals that give one away, and what you and your developers, or your incident responder, do in the first days. It comes with a provenance worksheet and a response timeline you can copy.

Package-release provenance worksheet and compromise response timeline

Copy this into a document or ticket. Part A has one block for each dependency that matters, Part B one for each script the browser loads from another server, and Part C covers the build.

How to use it

Part D is the response timeline for the first days after you learn a dependency or script was compromised, and Part E is an invented example filled in. Fill every line from evidence such as the lockfile, the registry page or a build log.

supply-chain-attacks.txt

Introduction8 lines

PACKAGE-RELEASE PROVENANCE WORKSHEET Application: (name and address) Commit or build checked: (commit hash, build number or image digest) Package manager and version: (output of npm --version or pnpm --version on the build runner) Completed by: (name and role) Date: (date) Which entries to fill: every package your own code imports directly, every package the lockfile flags with an install script, every package that handles sign-in, payments, file uploads or secrets, the build steps in Part C, and every script your pages load from a domain you do not control. Fill each line from evidence (the lockfile, the registry page, a build log) and write "unknown" rather than leaving a line blank. An unknown is a finding.

What a supply chain attack is

A supply chain attack does not break into your code.

It changes something your code depends on, so that the next install, build or page load delivers the attacker's code under a name you already trust. The change happens upstream, in a package registry, a maintainer's account, a build service or a script host, and it reaches you through the same channels you use to stay up to date.

OWASP files this under A03:2025 Software Supply Chain Failures, which it describes as breakdowns or other compromises in the process of building, distributing or updating software, often caused by vulnerabilities or malicious changes in third-party code, tools or other dependencies. Two different problems sit inside that definition.

A vulnerable component is an honest mistake: a bug with an advisory and a fixed release, which the dependency security guide deals with. A compromised component is a deliberate change: a release, build step or script altered to do harm. This guide is about the second kind.

For a website or web application, the supply chain has five links worth naming. Each is a place where a change made by someone else can become part of what your visitors receive.

  • Packages: everything in the lockfile, including the packages your packages depend on. OWASP's A03 guidance counts nested, or transitive, dependencies as part of what you need to track.
  • Install-time code: scripts a package runs on the machine that installs it, before your application has started.
  • The build: the CI service, its third-party steps and the secrets it holds, which together turn your repository into something deployable. The CI/CD security guide covers hardening it.
  • The artefact: the bundle or image that is actually deployed, which can differ from your repository if the build that made it was tampered with.
  • Browser scripts: analytics, chat widgets, tag managers, booking and payment widgets that each visitor's browser fetches from another server on every page load.

How an upstream compromise reaches your site

Each route below is described at the level you need to recognise it in your own setup.

None of them needs an attacker to touch your server. A software bill of materials, which has its own guide, is the inventory that tells you whether a reported compromise involves a component you run.

A new release of a package you already use

Anyone listed as a package's owner can publish a new version. npm's documentation for its owner command says an added maintainer can modify metadata, publish new versions and add other owners, and that there is only one level of access. 2 min read

A package that only looks like the one you meant

Some attacks need no stolen account. npm's threats page describes typosquatting, registering a name close to a popular package in the hope that someone mistypes or confuses the two, and says npm can detect typosquats and block them from being published. 1 min read

Code that runs the moment a package is installed

A package can declare lifecycle scripts, such as preinstall, install and postinstall, that run on whatever machine installs it: a developer's laptop, a CI runner or a build server. 1 min read

The build that turns your code into a release

Your pipeline is part of the supply chain too. 1 min read

Scripts the browser loads from someone else's server

Every script tag that points at another domain gives that domain a say in what your visitors run. 1 min read

How you would notice a compromised dependency

Detection comes from two directions.

Some signals arrive from outside, as an advisory, an alert or a vendor notice. Others sit in files you already have, but only help if someone reads them when they change.

Signals from outside

Outside signals tell you that something is wrong somewhere. 1 min read

Signals in your own lockfiles and builds

These signals depend on someone reading changes as they happen, which is cheapest in the pull request that makes them. 2 min read

What signatures, provenance and trusted publishing prove

Registry tooling now answers some provenance questions, and it pays to be exact about which ones. npm signs packages published to its public registry so that tampering with the package content can be detected.

That protects against an attacker who controls a registry mirror or proxy and alters a package on its way to you. A registry signature does not tell you whether the maintainer meant to publish that release.

Provenance answers a different question: where and how a version was built. npm's provenance attestation links a package to the source code and build instructions that produced it, and its publish attestation records that an authorised user published it. npm is explicit that provenance does not mean the package is free of malicious code; it gives you a verifiable link to the source and build that you can audit before deciding to trust it.

If a malicious change was committed to the source repository and built by the project's own workflow, the provenance is accurate and the package is still malicious.

Trusted publishing replaces long-lived npm tokens in the publishing workflow with short-lived tokens specific to that workflow, issued through OpenID Connect. When a public package is published through trusted publishing from a public repository on GitHub Actions or GitLab CI/CD, npm generates provenance automatically unless the publisher turns it off.

Trusted publishing does not close the other doors by itself: npm accepts trusted publishes in addition to token publishes and interactive publishes by a maintainer, and recommends selecting the setting that requires two-factor authentication and disallows tokens once trusted publishing is set up.

Even then, a maintainer can still publish interactively with a two-factor prompt. A release that arrives without provenance from a project that normally has it is a question to ask, not a formality.

A delay buys time for someone else to notice. npm's min-release-age setting installs only versions that have been available for more than a given number of days, and pnpm's minimumReleaseAge, which defaults to 1440 minutes (one day), does the same in minutes. The cost falls on urgent fixes too. npm's documentation says that when the window stops npm audit fix from installing a patched version, npm keeps the vulnerable version, warns and exits with a non-zero code, and a package listed in min-release-age-exclude can skip the delay.

The third-party script supply chain

Packages are checked when you build.

Browser scripts are fetched when someone visits, by every visitor, from whoever controls the address in the script tag. That changes which controls fit.

Start with who controls the copy. A script served from your own domain changes only when you deploy, and OWASP lists in-house mirroring of third-party scripts among its typical defences, to prevent alterations by the third party.

A script fetched live from the vendor changes whenever the vendor, or whoever controls the vendor's server, changes it. A script added through a tag manager changes whenever someone with publishing access to the tag manager publishes.

Subresource Integrity lets the browser check a file against a hash in the script tag's integrity attribute, and refuse it with a network error when the content differs. It works on script elements and on stylesheet, preload and modulepreload links, and a file from another origin needs CORS from its host and the crossorigin attribute on the tag.

Because the hash pins exact content, it suits a versioned file.

On a vendor file updated in place, OWASP points out the other side: a vendor update can leave you with secure but non-working code, so vendor scripts need watching for changes either way.

A Content Security Policy controls which resources a page may load. Its script-src directive sets the allowed sources for JavaScript, and a violation report records what was blocked. MDN describes report-only mode for trying a policy without enforcing it, and recommends the report-to directive for reports while still declaring the deprecated report-uri until every browser supports report-to.

A policy that allows a script because of the host it comes from does not look at the file itself, so a changed file served from a host you already allow still passes; the content check is Subresource Integrity.

What the policy adds is a block, and a report where reporting is set up, when a page tries to load script from a source the policy does not list.

For scripts that only need to show something, OWASP describes isolating them in an iframe served from a different domain, where the vendor code has no direct access to the host page's DOM or cookies. For vendors you cannot isolate, its advice extends to the contract: agreements that cover how the vendor monitors and controls its own source code to prevent and detect malicious changes to its JavaScript.

Begin with the pages that collect passwords, payment details or personal information. A third-party script on those pages runs with the same privileges as the visitor, on the same page as what they type, so each one should have a reason to be there and an owner who can say who controls it.

Package compromise response: the first days

The first news of a compromised dependency or script may be an advisory, an alert or a vendor email naming a package and a list of bad versions.

The response timeline in the worksheet turns that into steps; this section explains the reasoning behind their order.

First, decide whether this is a website incident right now. If the live site is serving the attacker's code to visitors, an attacker still seems to be active, or customer data may have been taken, call your host and an incident response specialist before anything else, and use the hacked website guide for the first hour.

Clever Ops does not provide incident response, forensic investigation or monitoring, so it is not the right first call. The timeline is written for you and your developers, or your responder, to work through.

Freeze before you clean

Stop new builds and deploys, and pause automated dependency update pull requests and auto-merge, so that nothing installs a fresh copy while you are still working out what you have. 1 min read

Work out which versions ran, where and when

The question has three parts. 1 min read

Decide which secrets to treat as exposed

Assume the bad code could read anything the process running it could read. 1 min read

Tell the people who need to know

Inside the business, tell whoever builds and hosts the site, and everyone with access to the tag manager or the package registry account. 1 min read

Restore from a known-good state

Recovery means rebuilding, not patching in place. 1 min read

Making the next compromise smaller

No setting stops a determined attacker upstream, but several shrink what a bad release can reach and how long it goes unnoticed.

The dependency security guide covers routine updates and advisories; these are the controls aimed at deliberate changes.

  • Builds install with npm ci or a pnpm frozen-lockfile install, never with a command that can rewrite the lockfile.
  • Install scripts run only for packages on an explicit list, approved by exact version where the package manager allows it. npm approve-scripts writes version-pinned entries by default, so approving one release's script does not approve the next.
  • New releases wait out a release-age delay before a build can pick them up, with a written route for exempting an urgent fix.
  • Deployments roll out in stages where your platform supports it, which OWASP suggests as a way to limit exposure if a trusted vendor is compromised.
  • The machines and runners that install packages hold only the secrets their job needs. Developer accounts on GitHub and npm use phishing-resistant multi-factor authentication, as CISA recommended after the 2025 compromise.
  • Third-party scripts on sign-in, account and payment pages are few, listed, and either self-hosted with an integrity hash or isolated.
  • Publishing rights in the tag manager are treated like deploy rights, with a named owner and a record of changes.
  • Lockfile diffs are read in every dependency pull request, and the worksheet is updated when a package that matters changes hands.

Where a security review or test fits

Clever Ops does not monitor your dependencies or your site and does not respond to incidents.

What it offers sits either side of one: a check of the application before an incident, and a check of the rebuilt application after one, once any responder has finished their work.

A secure code review reads the lockfile against the package manifest, checks new packages and versions against published advisories, and reads what runs on its own at install, build or deploy time, such as package scripts and CI workflow files. A website security audit reviews the Content Security Policy on public pages, including whether it lists the script sources the site actually uses.

A vulnerability assessment identifies each component by its exact version where the application reveals it, and matches it to the vendor's own advisories.

Each of these describes the build and the pages that were tested, on the dates they were tested. None of them is monitoring, and a release published the day after the report is outside what the report can speak to. If Clever Ops built or hosts the site, the work is a security review rather than an independent test, and the report says who built it and who hosts it.

Frequently asked questions

An attack that changes something your software depends on, such as a package, a build step or a script loaded from another server, so the attacker's code reaches you through a normal update, build or page load. OWASP covers it under A03:2025 Software Supply Chain Failures, which it describes as breakdowns or other compromises in the process of building, distributing or updating software.

One that reaches you through the npm registry: a malicious release of a package you already use, published from a compromised maintainer account or token, or a lookalike or substitute package. GitHub wrote in September 2025 that the Shai-Hulud worm infiltrated npm via compromised maintainer accounts by injecting malicious post-install scripts into popular packages, and CISA reported that its malware harvested credentials and published compromised versions of other packages.

It stops a new release being picked up quietly, as long as builds install from it with npm ci or a frozen lockfile, which fail instead of rewriting the lockfile. It does not help when someone updates the lockfile to the bad version, or when the bad version was locked before anyone knew. Its history in version control is also your best record of what was installed and when.

Block them by default and approve the few packages that need them. npm says the only valid use of install or preinstall scripts is compilation that must be done on the target architecture. pnpm blocks unlisted dependency build scripts, and npm's version 12 documentation says it blocks unreviewed dependency install scripts by default, while version 11 runs them with a notice, so check which version your build uses. Blocking scripts does not stop a package's ordinary code running when it is imported.

No. Provenance tells you which source commit and build workflow produced a package and that an authorised account published it. npm says it does not mean the package has no malicious code; it gives you something to audit. A release that lacks the provenance its earlier releases carried is still a useful warning sign.

Pause builds, deploys and automated dependency updates, and copy the installed packages, lockfiles, caches and build logs before reinstalling anything, then work out which versions ran where and when. If the live site is serving malicious code or customer data may have been taken, call your host and an incident response specialist first. The response timeline on this page sets out the order for the first days.

No. Clever Ops does not provide incident response, forensic investigation or monitoring, so start with your developers, your host and an incident response specialist. Once the application has been rebuilt, a secure code review can read the lockfile, install scripts and CI workflow files, and a website security audit can review the Content Security Policy your public pages send. Each report records what was checked and what was not.

Scope the right test for your application

Tell us what you have built, who uses it and when it needs to launch. You will get a plain-English recommendation: a website audit, a web application test or a referral to a specialist.