What Subresource Integrity Is
Subresource Integrity (SRI) is a W3C security feature that lets an HTML author pin the exact content of a third-party script or stylesheet. The integrity attribute carries one or more cryptographic hashes, each written as an algorithm prefix, a dash and a base64-encoded digest (for example sha384-oqVuAf…). Before executing a <script> or applying a <link rel="stylesheet">, the browser hashes the bytes it downloaded and compares the result to the listed hashes; if none match it refuses the resource entirely, so a compromised CDN or a tampered file cannot silently inject code.
- integrity="<alg>-<base64>" pins an expected script or stylesheet
- The browser blocks the resource on any hash mismatch
- Allowed algorithms: sha256, sha384, sha512 (SHA-2 family)
- Defends against a compromised or tampered CDN / third-party host
- Defined by the W3C Subresource Integrity specification
