Skip to content
AdminKit

Subresource Integrity (SRI)

What is Subresource Integrity (SRI)?

Subresource Integrity (SRI) lets a web page specify a cryptographic hash a fetched script or stylesheet must match before the browser executes it, blocking a tampered file from a CDN or third-party host. AdminKit's guide to judging header strength covers the related script-trust problem Content-Security-Policy addresses from the response side.

By AdminKit team, Netbase JSC · Updated

Subresource Integrity, a W3C specification, lets a page add an integrity attribute — a base64-encoded cryptographic hash — to a script or link tag loading a file from a CDN or other third-party host. Before executing the fetched file, the browser hashes it and refuses to run it if the result doesn’t match, which stops a compromised or tampered third-party host from silently serving different code than the page expects. OWASP’s Third-Party JavaScript Management Cheat Sheet lists SRI as one of the most effective controls available for this risk, alongside requiring CORS on the third-party host, which SRI needs to function at all. MDN’s Subresource Integrity guide shows the integrity and crossorigin attributes in use and how browsers handle a hash mismatch. SRI protects against a tampered file from a source a page has chosen to trust; it does nothing to stop a page from loading a genuinely malicious script in the first place, which is the separate problem a strict Content-Security-Policy’s script-src directive addresses instead. It complements other response-side controls covered in AdminKit’s glossary, like Referrer-Policy, which limits what a page’s own URL exposes to the third parties it loads rather than what those third parties can run.

Subresource Integrity (SRI) is part of AdminKit’s machine protocols cluster; the full AdminKit glossary lists other related terms.

Frequently asked questions

What does SRI actually check before a browser runs a script?

The browser hashes the fetched script or stylesheet and refuses to run it if the result doesn't match the integrity attribute's cryptographic hash, blocking a tampered file from a CDN or third-party host.

Does SRI require anything from the third-party host serving the file?

Yes -- SRI needs CORS enabled on the third-party host to function at all, which OWASP's cheat sheet lists alongside SRI as one of the most effective controls for this risk.

Does SRI stop a page from loading a malicious script it chose to trust?

No -- SRI only protects against a tampered file from a source the page already trusts; blocking a genuinely malicious script the page chooses to load is what a strict CSP script-src directive addresses instead.

What format is an SRI integrity value?

A base64-encoded cryptographic hash, added as the integrity attribute on a script or link tag.