Subresource Integrity
What is Subresource Integrity?
Subresource Integrity, or SRI, is a browser security feature that checks whether an external script or stylesheet exactly matches a publisher-approved cryptographic hash before using it. It helps stop a modified or compromised file from a CDN, such as a JavaScript library, from silently running on a website. MDN’s SRI guidance describes it as a way to verify fetched resource contents.
How Subresource Integrity works
- Choose an exact, version-pinned external file rather than a changing “latest” URL.
- Create a SHA-256, SHA-384, or SHA-512 hash from that file’s exact bytes.
- Add the algorithm and hash to the HTML resource’s
integrityattribute. - For a cross-origin resource, add
crossorigin="anonymous"so the browser can perform the required CORS-enabled fetch. - The browser downloads the file, calculates its hash, and compares it with the approved value.
- If the values differ, the browser blocks the script or stylesheet instead of using it.
Subresource Integrity example
A script tag might reference a fixed CDN URL and include integrity="sha384-..." plus crossorigin="anonymous". The integrity value is the approved fingerprint, while the crossorigin setting requires the CDN to allow the browser’s request. Changing even one character in the downloaded file produces a different hash, so a new approved hash is required.
Benefits of SRI for web security
SRI adds a browser-enforced verification step for fixed third-party assets.
- It reduces risk from CDN compromise and third-party asset tampering.
- It prevents a mismatch from becoming silent script execution.
- It makes unexpected dependency changes visible as a deployment failure.
- It gives teams a precise approval record for external files.
SRI, Content Security Policy, and HTTPS
These controls address different parts of browser security and work best together.
| Control | What it protects | Key limit |
|---|---|---|
| SRI | Exact bytes of a referenced file | Does not secure inline or changing assets |
| Content Security Policy | Allowed sources and browser behavior | Does not verify a file’s exact content |
| HTTPS | Data while it travels over the network | Does not prevent a trusted host from serving changed content |
Practical limits of Subresource Integrity
SRI is powerful, but only for resources whose contents can remain predictable.
- Dynamic files and unpinned URLs will break when their contents change.
- Cross-origin files need suitable CORS support.
- It does not protect inline scripts or an already compromised first-party HTML page.
- A trusted script can still behave maliciously after it has passed an SRI check.
Safe implementation practices
Use SRI as part of a repeatable release process.
- Pin immutable versions and generate hashes in the build pipeline.
- Review hash changes like source-code changes.
- Test the blocked-resource path before production releases.
- Maintain an inventory of third-party assets, use CSP, and scan dependencies.
- Avoid uploading private assets to public hash-generation tools.
Subresource Integrity in Emergent projects
When building with an AI web app builder, review every third-party script, keep external assets versioned, and include browser security checks before deployment. Emergent teams can pair SRI with sound app design and development practices to make web applications safer to ship and maintain.
on Emergent today

