Third-party scripts and supply-chain risk
Every script a page loads runs with full access to that page. Here is how that goes wrong, how to limit the damage, and how to notice when something changes.
Updated
Why a vendor script is your script
The browser does not tell an analytics tag from your own checkout code. Any script on the page can read what the visitor types, change what they see, and send data anywhere. When you add a vendor's tag, you extend your trust to that vendor, to everyone who can change the file they serve, and to anything their script loads in turn.
How it goes wrong
- The vendor is compromised, and the file your pages load is replaced with one that also skims form fields.
- A domain changes hands. In 2024 the polyfill.io domain was sold and began serving malicious code to the sites that still loaded a script from it.
- An abandoned script keeps pointing at a domain that later expires and is registered by somebody else.
- A tag manager account is taken over, and a new tag is published without a deploy and without a code review.
None of these needs a flaw in your own site, and none of them shows up in your repository.
Know what loads
Make a list of every outside origin each important page loads scripts from, and who asked for each. Most sites have a few nobody can explain: an old A/B testing tool, a chat widget from a cancelled contract, a font loader. Remove those first. It is the only step here that also makes the site faster.
Limit what a script can do
- Host it yourself when the licence allows. A file on your own origin changes only when you change it.
- Pin an exact version in the address, never
latest. - Add Subresource Integrity to scripts whose contents should not change. The browser refuses the file if its hash no longer matches.
- Use a Content-Security-Policy that lists the origins scripts may come from, so a script injected from anywhere else does not run.
- Keep third-party scripts off the pages that handle payment and sign-in wherever you can.
<script src="https://cdn.example.com/lib@4.2.1/lib.min.js"
integrity="sha384-..." crossorigin="anonymous"></script>Integrity hashes suit libraries. They do not suit tags the vendor updates on purpose, such as analytics and tag managers, which is why watching matters as well.
Notice the change
A changed hash on a known address is ordinary: vendors ship releases. A page that starts loading scripts from an origin it never used before is the signal worth an alert, because that is what a compromised vendor, a hijacked tag manager and a card skimmer all look like from outside.
OpSniper records the script origins of each monitored page and alerts when the page loads from an origin it did not load from before, at most once a week per site. It does not compare when either scan was answered with an error status, so a typical firewall challenge or maintenance page does not raise a false alarm.
If the site takes card payments
PCI DSS 4.0 asks merchants to keep an inventory of the scripts on payment pages with a reason for each (requirement 6.4.3) and to detect unauthorised changes to those pages (11.6.1). An inventory and change alerts are evidence toward those requirements. They are not compliance in themselves, which is for your assessor to judge.
Check a page
A scan lists the outside origins a page loads scripts from and how many use integrity hashes, as part of what it checks. Scan a site free, or read the agency checklist for the rest.