Cybersecurity

What Happens If SRI Validation Fails?

Understand why SRI failures occur, how browsers handle mismatched hashes, and how to troubleshoot common SRI issues.

By Inventive HQ Team

What happens when SRI validation fails

When Subresource Integrity validation fails, the browser refuses to use the resource entirely — a script never executes and a stylesheet is never applied — even though the file was already downloaded. The browser fetches the file, computes its hash (SHA-256, SHA-384, or SHA-512), compares it to the integrity attribute you provided, and on any mismatch it discards the downloaded bytes, fires an error event on the element, and logs a console message. There is no partial execution and no fallback: the resource is treated as if it failed to load, so anything on the page that depended on it breaks.

That's the summary an AI Overview will give you. What it can't show you is why a hash that worked yesterday fails today, or how to trace a real failure back to its cause in under a minute. SRI failures almost never mean "you're under attack" — in practice they mean a CDN quietly rewrote your file or you're missing a crossorigin attribute. Below is the exact failure sequence, a symptom-to-fix table for every common cause, and a generator to produce a correct hash from the bytes the browser actually receives.

The failure sequence, step by step

How a browser handles a Subresource Integrity check A flow showing the browser fetching a resource, computing its hash, comparing it to the integrity attribute, and either executing the resource or blocking it on mismatch. 1. Fetch Download file from CDN 2. Hash Compute SHA-384 of response bytes 3. Compare computed hash vs integrity="..." MATCH Execute script / apply stylesheet MISMATCH — blocked Discard bytes · fire error event · console warning · resource never runs

any 1-byte difference

The critical detail most explanations skip: step 1 happens regardless. The browser has to download the file to hash it, so SRI is an execution guard, not a network guard. A failing check wastes the bandwidth and then blocks the code — which is exactly why a broken SRI hash looks like "the file loaded (200 in the Network tab) but the page is dead."

Advertisement

Symptom → cause → fix

Symptom in DevToolsRoot causeFix
Failed to find a valid digest in the 'integrity' attribute ... computed SHA-384 ...The file changed since you generated the hash (version bump, re-minify, whitespace/line-ending change)Copy the computed hash the console prints, or regenerate from the live bytes with curl + the generator below
Resource shows 200 OK in Network tab but script/CSS has no effectHash mismatch — bytes downloaded then discardedSame as above; SRI does not stop the request, only execution
No 'Access-Control-Allow-Origin' header alongside the integrity errorCross-origin resource without valid CORS responseEnsure the CDN returns Access-Control-Allow-Origin and add crossorigin="anonymous" to the tag
Integrity error only in production, not locallyProduction CDN auto-optimizes (Cloudflare Auto Minify, Rocket Loader, Brotli re-pack)Disable optimization for that asset, or hash the post-optimization output
Works, then breaks after a "latest" URLYou pinned an SRI hash to a floating/@latest URLPin an immutable, version-locked URL (e.g. .../library@1.2.3/...)
Unsupported hash algorithm / silently ignoredUsed md5- or sha1- prefixUse sha256-, sha384-, or sha512- only
Wrong prefix vs. actual algorithmLabel says sha256- but value is a SHA-384 digestMatch the prefix to the algorithm you actually ran

The number one cause: the CDN rewrote your file

SRI hashes the exact byte stream of the response body. Base64-encode the SHA-384 of those bytes and you get the value in integrity. Change a single byte — a trailing newline, a minifier that renames a variable, gzip vs. Brotli decompressing to different intermediate output — and the digest changes completely. This is by design (it's what makes tampering detectable), but it means the failure is almost always benign drift, not an attack.

The fastest reliable fix is to hash the bytes the browser actually receives, not the file in your repo:

curl -s https://cdn.example.com/lib/app.min.js \
  | openssl dgst -sha384 -binary \
  | openssl base64 -A

Prefix the output with sha384- and paste it into the tag. If the value keeps drifting between deploys, the CDN is mutating the asset — pin a versioned URL and turn off auto-minification for it.

Generate a correct SRI hash

Paste the file contents or fetch a URL and get a ready-to-copy integrity attribute in all three supported algorithms:

Loading interactive tool...

Provide multiple hashes during a rotation

If you're intentionally changing a file and can't update every page at once, list more than one hash. The browser passes if the resource matches any of them and uses the strongest algorithm it supports:

<script src="https://cdn.example.com/app.js"
        integrity="sha384-OLDHASH... sha384-NEWHASH..."
        crossorigin="anonymous"></script>

This gives you a window where either the old or new file validates, so you can roll the asset forward without a hard cutover.

Quick recovery checklist

  1. Open DevTools Console and read the exact integrity error — it prints the hash the browser computed.
  2. Confirm the resource returned 200 in the Network tab (it did — that's why the page is dead, not blank).
  3. Copy the computed hash from the console straight into the integrity attribute, or regenerate it from the live URL with curl + openssl.
  4. If you also see a CORS error, add crossorigin="anonymous" and verify the CDN sends Access-Control-Allow-Origin.
  5. If the hash keeps drifting, pin a versioned URL and disable CDN auto-optimization for that file.

Frequently Asked Questions

What happens when SRI validation fails?

The browser refuses to use the resource. A script with a failing integrity check never executes, and a stylesheet with a failing check is never applied. The browser downloads the file, computes its hash, sees the mismatch, discards the bytes, and fires an error event. Anything on the page that depended on that script or CSS silently breaks.

Does a failed SRI check still download the file?

Usually yes. The browser fetches the resource over the network first, then hashes the response body and compares it to the integrity value. If they don't match, the downloaded bytes are thrown away and never parsed or executed. So SRI does not save bandwidth on a failure — it prevents execution, not the request.

Why does my SRI hash suddenly stop matching?

The file on the CDN changed. The most common causes are a library version bump that reused the same URL, a CDN auto-optimization feature (minify, Rocket Loader, Brotli re-encoding) that rewrites the bytes, or a trailing whitespace/line-ending difference. SRI hashes the exact byte stream, so even a one-character change produces a completely different hash.

Why does SRI fail with a CORS error?

Cross-origin resources loaded with an integrity attribute must be served with permissive CORS headers, and the tag must include crossorigin="anonymous". Without a valid Access-Control-Allow-Origin response header the browser marks the response as opaque, cannot read its bytes to hash them, and treats the integrity check as a failure.

How do I fix an SRI hash mismatch?

Re-download the exact file the browser receives (curl the URL) and regenerate the hash from those bytes, then paste the new value into the integrity attribute. If the CDN keeps changing the file, pin an immutable, versioned URL and disable auto-minification for that asset.

Can I supply more than one SRI hash?

Yes. Put multiple space-separated hashes in the integrity attribute, for example integrity="sha384-abc... sha512-def...". The browser uses the strongest algorithm it supports and passes if the resource matches any one of the listed hashes — useful during a file rotation window.

Which hash algorithms does SRI support?

SRI supports sha256, sha384, and sha512, named by the prefix on the integrity value. MD5 and SHA-1 are not allowed. SHA-384 is the common default because it balances security and hash length.

How do I see an SRI failure in the browser?

Open DevTools. The Console shows a message like "Failed to find a valid digest in the 'integrity' attribute for resource ... with computed SHA-384 integrity ...". The message conveniently prints the hash the browser actually computed, which you can copy straight into your tag.

SRItroubleshootingweb securityCDNhash validation