Subresource Integrity Pins External Assets to Expected Bytes
A web page can keep all of its application code under careful review and still execute JavaScript delivered from infrastructure outside its control. Analytics libraries, UI frameworks, payment components, and other dependencies are often fetched from a content delivery network. If that remote response changes, the browser normally has no basis for deciding whether the new bytes are an approved release or an unexpected substitution.
Subresource Integrity, usually abbreviated SRI, adds that missing check for supported resource types. The page declares one or more cryptographic digests for an external resource. After fetching the resource, the browser computes a digest over the received representation and compares it with the declared metadata. A match permits use of the resource. A mismatch turns a successful network response into a rejected dependency.
The security boundary is narrow but valuable. SRI does not establish that a library is safe, and it does not validate the identity of its publisher. It establishes that the bytes accepted by the browser are among the bytes the document explicitly authorized.
A trusted origin and trusted content are separate claims
HTTPS authenticates the server endpoint represented by a certificate and protects traffic against ordinary network modification. It does not promise that every response from that endpoint contains the content an application intended to consume.
That distinction becomes important with shared hosting and third-party asset delivery. A CDN account can be compromised. A storage object can be overwritten. A release process can publish the wrong artifact under a stable URL. An upstream operator can make an unintended change. TLS can remain completely healthy through all of these events because the server is still serving its own response over an authenticated connection.
SRI moves one part of the trust decision into the consuming document. Instead of accepting whatever bytes appear at a URL, the document states a digest for the acceptable asset. The URL remains a location; the digest becomes an integrity condition.
This also changes the meaning of a stable asset URL. Without SRI, a path such as /library.min.js can silently become a delivery channel for new code. With a fixed integrity value, changing the object at that path causes existing documents to reject it until their integrity metadata changes as well. Release approval and asset retrieval become distinct events.
The digest binds bytes, not software identity
An SRI value combines an algorithm identifier with a base64-encoded digest. Browsers support designated hash algorithms for this purpose, with SHA-256, SHA-384, and SHA-512 commonly used. The digest is computed from the resource representation according to the SRI processing model, so even a small byte change produces a different expected value.
This precision is both the feature and the operational constraint. Two JavaScript files can behave identically and still have different digests because of whitespace, comments, minification output, line endings, or build metadata. A rebuild that produces semantically equivalent code is still a new byte sequence and needs matching integrity metadata.
That makes SRI a poor fit for resources that intentionally change behind a stable URL without coordinated updates to the consuming page. A vendor endpoint that continuously serves the newest build conflicts with the core property SRI provides. Pinning such an endpoint means the next legitimate update will fail closed from the page’s perspective.
Versioned, immutable assets fit much better. A release pipeline can produce the asset, compute its digest, publish both artifact and page metadata as one controlled change, then retain the versioned object for as long as documents may reference it. In that model, an integrity mismatch is exceptional rather than routine.
Multiple digests can be declared for a resource. This supports controlled transitions or compatibility cases, but each accepted digest broadens the set of byte sequences that the page authorizes. Old values should not accumulate indefinitely as a substitute for release discipline.
Cross-origin delivery adds another enforcement boundary
SRI is frequently associated with third-party CDNs, which makes cross-origin behavior central rather than incidental. For cross-origin resources, integrity checking interacts with Cross-Origin Resource Sharing. The browser needs a response that is eligible for the relevant cross-origin request mode; a digest alone does not grant permission to consume an otherwise ineligible response.
This matters because integrity and origin access solve different problems. The digest answers whether the response bytes match an authorized value. CORS controls whether a cross-origin response can be exposed or used under the request’s mode and browser rules. Treating the two mechanisms as interchangeable can produce deployments that look protected in markup but fail when browser enforcement is applied.
The crossorigin attribute is therefore common beside integrity on external script and stylesheet elements. Its exact effect depends on the element and request mode, so copying attributes between resource types without checking browser semantics can create brittle behavior.
Operational testing needs to cover the delivered response, not only the source artifact in a repository. Compression is generally handled as content encoding during transfer, but transformations that alter the representation used for integrity verification can break the digest. CDN features that rewrite JavaScript or CSS deserve particular scrutiny. A performance optimization that changes asset bytes after the digest was generated can become an availability incident.
Integrity metadata has its own supply chain
SRI can prevent a compromised asset host from substituting arbitrary code when the attacker cannot also modify the document that contains the integrity value. If both the page and the external asset are controlled through the same compromised release path, the attacker may be able to replace the asset and update its digest together.
This is a useful boundary for threat modeling. The strength of SRI depends on separation between the authority that can alter the fetched resource and the authority that can alter the page’s integrity metadata. Hosting a script on a third-party CDN while serving the HTML from independently controlled infrastructure creates a meaningful split. Generating both from one compromised deployment credential offers less protection.
Build systems also deserve attention. A pipeline that downloads an external package, computes an SRI digest automatically, and immediately publishes that digest without any independent approval can faithfully pin malicious bytes obtained during the build. The cryptography works, but the approval point has moved to an untrusted input.
A stronger release process treats digest changes as security-relevant changes. Review can focus on the dependency version, provenance, expected release, and resulting artifact rather than accepting any hash produced by automation. Automation remains useful for calculation and consistency; it should not silently redefine which code is trusted.
Failure behavior needs to be part of service design
An integrity mismatch blocks the affected resource. For a decorative stylesheet, the result may be visual degradation. For a script that initializes authentication, checkout, navigation, or application state, the page may become unusable. That fail-closed behavior is the security control working as designed, but it creates an operational dependency on accurate metadata and immutable delivery.
Monitoring should distinguish integrity failures from ordinary network failures. A resource can return HTTP 200 with valid TLS and still be rejected by the browser. Server-side availability metrics may therefore remain green while clients lose a critical dependency. Browser telemetry, synthetic checks, and deployment verification can expose that gap.
Rollback planning also changes. Restoring an older HTML document while leaving only newer asset versions available can produce digest mismatches or missing resources. Keeping versioned artifacts immutable and available makes page rollback much safer than overwriting a shared filename on each release.
SRI also does not provide fallback code by itself. Applications that need resilience across asset origins must design that behavior deliberately, while avoiding a fallback path that simply accepts unpinned code and defeats the integrity boundary.
SRI is strongest as a narrow control with a clear owner
Subresource Integrity sits beside, rather than above, other browser security controls. Content Security Policy can restrict the origins and execution patterns a page permits. HTTPS protects transport and authenticates endpoints. Dependency review addresses the software selected for use. SRI contributes a separate property: a fetched external asset must match bytes already authorized by the document.
That property is especially effective for static third-party scripts and stylesheets whose release cadence is controlled and whose URLs are versioned. It is less suitable for dynamic endpoints, frequently rewritten assets, or delivery systems that cannot coordinate document metadata with artifact changes.
The practical value comes from keeping the claim precise. A matching digest does not certify good code. It does not make a compromised publisher trustworthy. It does not replace origin policy or dependency governance. It prevents an external resource from changing unnoticed between authorization and browser execution, provided the integrity metadata remains under separate, trusted control.
For web applications that depend on code delivered across organizational boundaries, that is a meaningful reduction in ambient trust. The browser no longer has to equate a familiar URL with acceptable content; it can require the content itself to match an approved cryptographic commitment.