What is Subresource Integrity (SRI)?
Subresource Integrity (SRI) is a W3C security specification that enables web browsers to verify that third-party assets fetched from CDNs (such as unpkg, cdnjs, or Google Fonts) have not been maliciously modified or compromised in transit.
How SRI Prevents CDN Supply-Chain Attacks
If an attacker compromises a public CDN and injects cryptocurrency miners or keyloggers into a popular JavaScript library, browsers loading that script without SRI will blindly execute the malicious code. With an integrity="sha384-..." attribute present, the browser hashes the downloaded file before execution; if the hash does not match, the browser immediately blocks execution and fires an error.
Why SHA-384 is the W3C Recommended Digest
While SHA-256 is supported, W3C recommends SHA-384 as the ideal balance between collision resistance, string length, and performance overhead during browser verification.