Subresource Integrity (SRI)
SRI allows browsers to verify that external resources haven't been tampered with.
Results in 1–3 minutes · Free · No signup required
Want the result for your own site? Free SRI Checker — paste your domain, get the report.
Why It Matters
If a CDN is compromised, attackers could inject malicious code into your site. SRI ensures scripts and stylesheets match expected cryptographic hashes.
How We Check
We check external script and stylesheet tags for integrity attributes with valid cryptographic hashes.
Good vs Bad Values
| Value | Verdict | Why |
|---|---|---|
<script src="https://cdn.example.com/lib.js" integrity="sha384-…" crossorigin="anonymous"> | Good | Hash pinned and CORS mode set: the browser refuses the file if a single byte differs. |
integrity="sha512-…" or "sha256-…" | Good | All three SHA-2 algorithms are valid in SRI; sha384 is the usual choice. |
Several hashes in one attribute (sha384-… sha512-…) | Good | Allowed. The browser uses the strongest algorithm it supports and accepts a match against any hash listed for it. |
integrity set but no crossorigin attribute on a cross-origin file | Bad | The request is made in no-cors mode, so the browser cannot verify the hash and blocks the file. The page breaks. |
integrity="sha1-…" or "md5-…" | Bad | Unsupported algorithms are ignored by browsers, so the tag looks protected but is not. |
Third-party script or stylesheet without integrity | Bad | Whoever controls that CDN account can run code on your pages and in your users' sessions. |
src=".../lib@latest/lib.js" with a pinned hash | Weak | A moving URL and a fixed hash contradict each other: the page breaks the day upstream publishes a release. Pin an exact version. |
Same-origin script without integrity | Good | Not flagged. SRI exists to protect resources served from hosts you do not control. |
How to Fix
Add integrity attributes to external resources: <script src='...' integrity='sha384-...' crossorigin='anonymous'>. Use srihash.org to generate hashes.
Generate the hash from the exact file the CDN serves, then prefix it with the algorithm:
curl -s https://cdn.example.com/lib@1.2.3/lib.min.js | openssl dgst -sha384 -binary | openssl base64 -A
Stylesheets work the same way:
<link rel="stylesheet" href="https://cdn.example.com/lib@1.2.3/lib.min.css"
integrity="sha384-PASTE_HASH_HERE" crossorigin="anonymous">
Next.js — next/script passes integrity and crossOrigin through to the tag:
<Script src="https://cdn.example.com/lib@1.2.3/lib.min.js"
integrity="sha384-PASTE_HASH_HERE" crossOrigin="anonymous" />
SRI is markup, so there is no nginx or Apache directive for it. If the external file is not essential, self-host it instead: a same-origin file needs no hash.
Keep hashes current in CI. Pin exact versions in the URL, store the hash next to the version in your build config, and fail the build when a hash is missing. When you upgrade a library, regenerate the hash in the same commit so a mismatch is caught before deploy rather than by visitors.
Verify in the browser. Open DevTools, reload, and look for a console error beginning “Failed to find a valid digest in the 'integrity' attribute”. That message means the hash does not match what the CDN returned.
Common Mistakes
- Hashing the wrong bytes. The hash must be of the exact file the CDN serves, not your local build or the unminified source.
- Forgetting to regenerate the hash when you bump the library version. The browser then blocks the script and the feature silently stops working.
- Assuming SRI covers scripts injected at runtime. Tags created in JavaScript need `script.integrity` and `script.crossOrigin` set before they are appended.
- Adding integrity to a host that rewrites content per request (for example minify-on-the-fly or user-agent specific bundles). The hash will not match for every visitor.
Frequently Asked Questions
What is Subresource Integrity (SRI)?
SRI allows browsers to verify that external resources haven't been tampered with.
Why does Subresource Integrity (SRI) matter for website security?
If a CDN is compromised, attackers could inject malicious code into your site. SRI ensures scripts and stylesheets match expected cryptographic hashes.
How do I fix Subresource Integrity (SRI) issues?
Add integrity attributes to external resources: <script src='...' integrity='sha384-...' crossorigin='anonymous'>. Use srihash.org to generate hashes.
Related Security Checks
Related Tool
SRI Checker
Run all 4 related checks with our free sri checker
Check Your Website Now
Run a free security scan to check for Subresource Integrity (SRI) issues and 61 other security checks.
Scan Your Website Free