Subresource Integrity
Subresource Integrity is a browser security feature that lets websites verify that files loaded from external sources, such as Content Delivery Networks (CDNs), have not been tampered with. It works by allowing a website to specify a cryptographic hash for each external resource, so the browser can check that the downloaded file matches the expected content before executing it. This helps protect users from attacks where third-party hosted files are maliciously modified.
Subresource Integrity (SRI) is a W3C specification that defines a mechanism by which user agents verify that fetched resources have been delivered without unexpected manipulation. Web authors include a cryptographic hash (typically SHA-256, SHA-384, or SHA-512) in the 'integrity' attribute of HTML elements such as <script> and <link>. The browser computes the hash of the fetched resource and compares it against the declared value; if the hashes do not match, the resource is blocked from loading. SRI is applicable to both cross-origin and same-origin resources, though its primary security value is in mitigating risks associated with externally hosted assets, where the serving infrastructure (such as a CDN) may be compromised independently of the origin. SRI does not detect or prevent all supply chain attacks; for example, if an attacker compromises the build process before hashes are generated, the integrity attribute would reflect the tampered content. Additionally, SRI is not suitable for resources that change dynamically, since any modification to the resource content will invalidate the hash.
Why it matters
Modern web applications routinely load JavaScript libraries, CSS frameworks, and other assets from external sources such as Content Delivery Networks. This reliance on third-party infrastructure introduces a significant attack surface: if a CDN or external host is compromised, an attacker can inject malicious code into resources that are then served to every site depending on that CDN. Because browsers trust and execute scripts loaded via valid HTML tags, a single tampered file can affect millions of users across thousands of websites simultaneously. Subresource Integrity provides a critical defensive layer against this class of supply chain attack by ensuring that any modification to a fetched resource, whether through CDN compromise, man-in-the-middle attacks, or other forms of tampering, results in the browser blocking the resource rather than executing it.
The importance of SRI has grown alongside the expansion of the web supply chain. Organizations that rely on externally hosted assets without SRI have no browser-enforced mechanism to detect unauthorized changes to those resources between the time of authoring and the time of delivery. While SRI is not a comprehensive solution to all supply chain risks (for example, it cannot protect against compromises that occur before hashes are generated), it is one of the most accessible and widely supported browser-native controls available for verifying the integrity of fetched content. Implementing SRI is a recommended practice by OWASP and is part of a defense-in-depth strategy for web application security.
Who it's relevant to
Inside SRI
Common questions
Answers to the questions practitioners most commonly ask about SRI.