Skip to main content
Home/Blog/Cybersecurity/What Happens If SRI Validation Fails?
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 If SRI Validation Fails?

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. A mismatch can come from an expected asset change, CDN rewriting, or tampering; a separate CORS error can also block the resource. 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."

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)Investigate the change and verify the asset against a trusted release before generating a new hash
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 rewrites the decoded asset (for example, minification or script rewriting)Disable rewriting for that asset, or verify the rewritten output before hashing it
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 decoded resource bytes. Base64-encode the SHA-384 of those bytes and you get the value in integrity. Change a single decoded byte — a trailing newline or a minifier that renames a variable — and the digest changes completely. Switching between gzip and Brotli alone does not cause a mismatch when both decode to the same bytes. A mismatch may be benign drift or tampering, so investigate it before updating the hash.

After confirming that the changed asset matches a trusted release, hash the decoded bytes the browser receives:

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

Prefix the output with sha384- and update the tag only after you verify the asset. 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:

SRI Hash Generator

Generate Subresource Integrity hashes for scripts and stylesheets

Open the full SRI Hash Generator tool →
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. Investigate the changed file and compare it with a trusted release. Once verified, regenerate its hash and update the integrity attribute.
  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.

Don't wait for a breach to act

Get a free security assessment. Our experts will identify your vulnerabilities and create a protection plan tailored to your business.