Subresource Integrity lets a browser check a fetched script or stylesheet against a digest supplied by the page. If the fetched bytes fail the applicable integrity check, the browser refuses to use that resource. SRI protects a particular resource reference; it does not prove that its approved code is benign, that the publisher is trustworthy, or that a compromised page cannot replace both the URL and the digest.
The useful starting question is who can change each side of the comparison: the resource bytes, the HTML containing the expectation, and the deployment process that updates them.
Bind the expected value to a reviewed artifact
For a deliberately small JavaScript fixture, the exact UTF-8 bytes are:
window.Demo = {ready: true};
The fixture includes a final newline. We calculated its SHA-384 integrity value locally:
sha384-AOVNLxK1XDyDI9DYZ2mkuUkS90YFa1T4aX945cK+WEPlqBbCUNmSMFMheH9b2Ecc
Three checks passed: the original bytes reproduced the digest, an added space changed it, and the decoded digest contained 48 bytes. These are Python hashing checks, not browser enforcement tests. The value is for this tiny fixture only and must not be copied onto an unrelated library.
MDN's SRI documentation describes integrity metadata and supported resource loading. Treat the digest as part of a specific artifact reference, generated from the file you reviewed.
Separate integrity failure from a network or CORS failure
A cross-origin SRI resource must also satisfy the browser's relevant CORS requirements. A typical cross-origin script reference uses an integrity value and crossorigin="anonymous"; the resource server must provide a suitable response. Copying only the hash attribute can therefore leave a resource that still fails to load.
When diagnosing a failure, inspect the browser's actual request and error. The resource may be unavailable, blocked by policy, missing suitable CORS permission, or different from the expected bytes. Those are different repairs, and disabling integrity checks erases the distinction.
Use a controlled fixture to test the accepted and rejected paths before relying on the boundary. Do not interpret a hash comparison performed by a build script as proof that a supported browser exercised the same load.
Make updates an intentional review step
An unversioned URL can change underneath a pinned digest. That is a useful failure if the new content was never approved, but it can also become an outage when a provider routinely changes assets without stable versioned URLs.
Prefer a distribution contract you can review and maintain. When updating, obtain the intended artifact through the approved process, inspect the change, generate the new digest, and deploy the HTML and resource references coherently. Retain a rollback pair that agrees.
Do not automatically “fix” an integrity mismatch by hashing whatever the endpoint currently returns and committing the result. That would turn unexpected content into the new expectation without answering why it changed.
Understand what remains outside the check
SRI does not authorize runtime network destinations, audit a script's behavior, or recursively establish that every asset it later loads is approved. Inspect the actual loading graph and the platform's enforcement rules for the resources in question.
Our container-verification guide separates artifact identity, provenance, and acceptance policy in another environment. The same distinction is useful here: identifying expected bytes and deciding to trust those bytes are different decisions.
A compromised HTML publisher may replace both the script and its integrity metadata. An approved but vulnerable dependency still has the expected digest. Keep code review, dependency maintenance, content policies, and control of the page's deployment path in scope.
Test failure as part of the feature
For an application test, serve a known fixture, confirm its intended effect, then change its bytes while keeping the original integrity value. Confirm that the effect does not occur and that the application handles the missing dependency appropriately. Repeat with the correct digest but a broken CORS response to distinguish those failures.
That browser exercise was not run here. The local result establishes only the three hashing properties above. A usable integrity policy includes an observable rejection path and an owned update process, rather than an attribute added once and forgotten.