Subresource Integrity (SRI) Explained: Protecting Third-Party Scripts

How Subresource Integrity stops tampered CDN and third-party scripts from running on your site, when to use it, and its limits.

Yrzo AI28 November 2026 2 min read

The problem SRI solves

Most websites load JavaScript and CSS from other servers: CDNs, analytics providers, widget vendors. If one of those servers is compromised, the attacker can change the file — and every site that loads it runs the attacker's code. This is a classic supply chain attack, and it is how many card skimming incidents begin.

Subresource Integrity (SRI) lets the browser check that a file has not changed.

How it works

You add an integrity attribute containing a cryptographic hash of the exact file you expect, plus crossorigin="anonymous". When the browser downloads the file, it hashes it and compares. If the hashes do not match, the browser refuses to run it.

For example, a script tag might include integrity="sha384-..." with the hash of that specific library version.

When to use SRI

SRI works best for files that never change at a given URL:

  • versioned libraries from public CDNs (for example a specific version of a charting library)
  • fixed versions of fonts or CSS frameworks

Is your site exposed to this?

Run a free, non-intrusive check of what attackers can see from outside. No account needed.

When SRI does not fit

  • scripts that the vendor updates in place at the same URL, such as many analytics and chat widgets — the hash would break every time they update
  • dynamically generated scripts

For those, rely on a strict Content-Security-Policy that limits which domains can load scripts and where data can be sent, and keep the number of third-party scripts to a minimum.

How to generate the hash

Many CDNs show the SRI hash next to each file. You can also generate one with standard command-line tools by hashing the file with SHA-384 and base64-encoding the result.

SRI and PCI DSS

PCI DSS v4.0 expects merchants to authorise and check the integrity of scripts on payment pages. SRI, CSP and script monitoring together are a practical way to meet that. See PCI DSS website security.

Check your site

Yrzo AI lists the third-party scripts your pages load and flags ones without SRI or CSP protection. Run a free scan or see the full report.

Related reading: Magecart Card Skimming on WooCommerce and Shopify: How to Spot and Stop It · React App Security Checklist: Front-End Risks That Matter · Is Webflow Secure? What Webflow Handles and What You Still Own

subresource integritySRI explainedintegrity attribute scriptthird party script security
Share

Check your own website in 60 seconds

Free check, no account needed. Want the full picture? Full reports start at £149, with up to 110 checks with a 14-day money-back guarantee.

Keep reading