Skip to content
Vol. 1 · Ed. 2026
CyberGlossary
Entry № 1237

Subresource Integrity (SRI)

Reviewed byCybersecurity entrepreneur & security researcher

What is Subresource Integrity (SRI)?

Subresource Integrity (SRI)A browser mechanism that verifies a cryptographic hash of a script or stylesheet loaded from a third party before executing it, preventing tampered files from running.


Subresource Integrity, standardised as a W3C Recommendation in 2016, is configured with an integrity attribute on script or link tags containing one or more base64-encoded SHA-256/384/512 digests of the expected file. The browser fetches the resource, recomputes the digest and refuses to execute or apply it if no listed hash matches; multiple space-separated hashes let a page accept several known-good versions. Because SRI requires knowing the exact bytes in advance, it protects static, version-pinned assets rather than dynamically generated ones.

SRI is the primary client-side defence against CDN compromise and hijacked third-party scripts such as the Magecart family. The Polyfill.io attack shows why it matters: after a new owner acquired the cdn.polyfill.io domain in February 2024, the CDN began serving payloads that redirected mobile users to scam sites — discovered by Sansec on 25 June 2024 and affecting over 100,000 sites (tracked as CVE-2024-38526). Any page that had pinned an integrity hash would have blocked the mutated file outright, because the digest no longer matched.

SRI works alongside CSP and the crossorigin attribute, and should be combined with version pinning and automated hash-regeneration in the build pipeline so code and digest never drift apart.

flowchart TD
  A["Browser parses tag<br/>with integrity attribute"] --> B[Fetch resource from CDN]
  B --> C[Compute SHA-256/384/512 digest]
  C --> D{Digest matches a<br/>listed hash?}
  D -->|Yes| E[Execute / apply resource]
  D -->|No — tampered or swapped| F[Block and raise error]

Examples

  1. 01

    '<script src="https://cdn.example.com/lib.js" integrity="sha384-..." crossorigin="anonymous"></script>'.

  2. 02

    CSP directive 'require-sri-for script style' (where supported) to enforce SRI on all subresources.

Frequently asked questions

What is Subresource Integrity (SRI)?

A browser mechanism that verifies a cryptographic hash of a script or stylesheet loaded from a third party before executing it, preventing tampered files from running. It belongs to the Application Security category of cybersecurity.

What does Subresource Integrity (SRI) mean?

A browser mechanism that verifies a cryptographic hash of a script or stylesheet loaded from a third party before executing it, preventing tampered files from running.

How do you defend against Subresource Integrity (SRI)?

Defences for Subresource Integrity (SRI) typically combine technical controls and operational practices, as detailed in the full definition above.

What are other names for Subresource Integrity (SRI)?

Common alternative names include: SRI.

Related terms

See also