Diagnosing SRI and CSP failures — from console message to cause
A block is usually one of five things. Read the message and work down the list; most cases resolve in minutes.
From symptom to cause
The console text is the best clue you get.
| Symptom | Check | Fix |
|---|---|---|
| Failed to find a valid digest | Hash value, line endings, deployed file | Recompute from the final file |
| blocked by CORS policy | Access-Control-Allow-Origin | Add the ACAO header at the CDN |
| integrity appears to be ignored | Missing crossorigin | Add crossorigin="anonymous" |
| CSP blocks inline code | Hash, nonce, unsafe-inline | Add a hash or adopt a nonce |
| require-sri-for has no effect | Deprecated directive | Move to the integrity attribute |
Algorithm and Base64
Values starting with sha1- or md5- are not supported by SRI, and the browser blocks the resource.
Bad Base64 is a format error. URL-safe characters (-, _) are not standard Base64, and broken padding changes the length. sha384 is exactly 48 bytes, sha512 exactly 64.
Missing crossorigin
Without crossorigin on a cross-origin file, the fetch is no-cors and the integrity check is skipped. This case can produce no error at all, which makes it the hardest to find.
Paste the whole tag into the validator and it is reported separately; a bare attribute string cannot show it.
CSP syntax
Hashes and nonces must be quoted, 'none' must stand alone, and a repeated directive is ignored the second time.
require-sri-for was removed from Chrome and dropped from the standard. It does nothing where it still parses, so move to the integrity attribute.
Hash mismatch
When the format is fine but the hash does not match, suspect the bytes: LF vs CRLF, a BOM, a trailing newline, or post-build minification.
If you hashed pasted code, turn on the CRLF option and check again; if it still differs, hash the file the server actually returns.
Questions
The validator says pass but the browser blocks it.
The validator reads syntax and hashes; it cannot see the real response headers. Check the ACAO header and the response size in the network panel.
Does adding integrity invalidate caches?
No. SRI does not affect the cache key. Just remember that a cached response is not verified again.
Sources
Every example here can be pasted into the workbench as it is.
Open the workbench