Explore our new Cybersecurity Terms Glossary, explained by our experts.

View the Glossary View the Glossary
PRIVIA

Cybersecurity Terms Glossary

What Is Subresource Integrity?

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.

Illustration for the cybersecurity term Subresource Integrity
Home / Blog / Cybersecurity Terms / What Is Subresource Integrity?
17 November 2026

What Is Subresource Integrity?

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.

The Syntax

<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.

What It Defends Against

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.

The Limits

Deploying It

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.

FAQ – Frequently Asked Questions

Why Does My Integrity Check Fail on a Working Script?

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.

Can We Use SRI with Google Tag Manager or Analytics?

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.

Does SRI Replace Content Security Policy?

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.

How Do We Update a Third-Party Script Without Breaking Pages?

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.

Related Terms

You May Be Interested In These

What Is ETW Tampering?

Cybersecurity Terms

17 November 2026

What Is ETW Tampering?

Read More
What Is UEBA?

Cybersecurity Terms

17 November 2026

What Is UEBA?

Read More
What Is Root Cause Analysis?

Cybersecurity Terms

17 November 2026

What Is Root Cause Analysis?

Read More