Explore our new Cybersecurity Terms Glossary, explained by our experts.
Cybersecurity Terms Glossary
Subresource Integrity lets a page declare the cryptographic hash of a script or stylesheet it loads, so the browser refuses to execute the file if it has been altered.

What Is Subresource Integrity?
Every third-party script a page loads runs with the same privileges as the page’s own code. It can read the DOM, modify forms, and send data anywhere. Subresource Integrity is the browser feature that lets a page state in advance what that file should contain, expressed as a cryptographic hash, so the browser can refuse to run it if the bytes differ.
<script src="https://cdn.example.com/lib.js"
integrity="sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC"
crossorigin="anonymous"></script>
The integrity attribute holds an algorithm prefix and a base64-encoded digest. SHA-256, SHA-384, and SHA-512 are supported; SHA-384 is the usual choice. The browser fetches the file, computes the hash, and compares. On a mismatch it reports a network error and does not execute the file.
The crossorigin attribute is required for cross-origin resources, not optional. Without it the browser cannot read the response body for verification and the integrity check fails, which is the most common reason an SRI deployment appears not to work. Multiple hashes may be listed, separated by spaces, and the resource passes if it matches any one of them, which is how a planned file change is rolled out without breaking existing pages.
The threat is a trusted file being replaced: a compromised CDN, a hijacked domain, a supplier whose build system was breached, or an attacker on the network path where transport protection is incomplete. Two UK cases illustrate the cost.
In 2018 Ticketmaster UK was compromised through a chatbot script supplied by a third party, Inbenta, which was modified to skim payment details. The ICO fined the company £1.25 million on 13 November 2020, finding that it had failed to assess the risks of including a third-party script on a payment page. The same year, British Airways lost card data from its booking process to a modified script, resulting in a £20 million penalty.
More recently, in June 2024 the polyfill.io service, embedded on a very large number of websites, began serving malicious code after the domain changed ownership. Sites that had pinned a hash were unaffected, because the altered file no longer matched. Sites that simply included the script were not.
strict-dynamic has the same characteristic.script and link elements, not to images, iframes, or fetch requests.Generate hashes during the build rather than by hand, so the attribute cannot drift from the file, and pin third-party scripts to a specific version rather than a latest alias, since a version that can change cannot have a fixed hash. Where a supplier changes a file without warning, the page breaks rather than running unknown code, which is the behaviour you asked for; a monitored error report tells you it happened.
Treat SRI as one layer. A Content Security Policy restricting script-src and connect-src limits where code may come from and where data may go, HSTS protects the transport, and together they form the practical answer to payment page tampering. PCI DSS v4.0 requirements 6.4.3 and 11.6.1 require scripts on payment pages to be authorised, inventoried, and monitored for unauthorised change, and SRI with reporting is a recognised way of meeting them. Our web application security testing reviews third-party script inclusion against these controls alongside the rest of the HTTP security headers.
Almost always one of three causes. The crossorigin attribute is missing, so the browser cannot read a cross-origin response body to verify it. The server does not return a permissive cross-origin header. Or the file changed after the hash was generated, which happens with any URL that points at a latest alias rather than a pinned version. Check the browser console, which names the computed hash.
Generally no. Those scripts are updated by the provider without notice and often generated per request, so no fixed hash exists. Manage that risk differently: load such scripts in a sandboxed iframe where the design permits, restrict where they may send data using Content Security Policy connect-src, and keep them off payment and authentication pages.
No, they address different questions. SRI verifies that a specific file is exactly what you expected. Content Security Policy governs which sources may provide code at all and where the page may send data. A policy can require integrity attributes on scripts, which is how the two combine, and a payment page benefits from both plus an inventory of what is loaded.
List more than one hash in the integrity attribute, separated by spaces; the resource passes if it matches any of them. Add the new version’s hash before switching, deploy, then remove the old one afterwards. For scripts you host yourself, generate hashes automatically during the build so the attribute and the file are always produced together.
You May Be Interested In These
We use a few cookies that are needed to make this website work, and they are always on. We would also like to set analytics cookies, to see which pages are useful; functional cookies, so that our live chat works; and advertising cookies, to measure our campaigns. We will not set any of those until you say yes, and you can change your mind at any time from the Cookie Settings link in the footer.
Choose the cookies you are happy for us to use. Strictly necessary cookies are always on; everything else is off until you turn it on.
These cookies keep the website working: they hold your security checks, your form submissions and the choice you make here. The site cannot run without them, so they are always on.
These let our live chat open and remember your conversation, and let the newsletter sign-up work. Switch them off and the chat window will not appear.
These tell us which pages are read and how people find us, so that we can improve the site. The reports are about groups of visitors, never about you personally.
These let us measure our advertising and show you our adverts on other websites, such as LinkedIn, Google and Meta. Switch them off and you will still see adverts, but they will be less relevant.