Subresource Integrity Pins Browser Dependencies to Expected Bytes
A production page can contain no application-side injection flaw and still execute hostile JavaScript if a trusted external asset changes underneath it. The script URL may be correct, TLS may be valid, and the browser may have reached the intended host. None of those facts establish that the returned file is the exact artifact the site operator approved.
Subresource Integrity, commonly shortened to SRI, adds that missing assertion for selected browser-loaded scripts and stylesheets. An integrity attribute carries one or more cryptographic digest values. After fetching the resource, the browser computes the digest of the representation used for the integrity check and refuses to apply or execute it when no supported digest matches.
The mechanism is small. Its architectural effect is more interesting: delivery location and content identity stop being the same security decision.
A trusted origin is not a trusted artifact
External JavaScript creates a transitive execution relationship. A page that loads a library from another origin effectively grants that delivery path code execution inside the page’s security context, subject to the browser’s other controls. The dependency host, its deployment credentials, storage layer, build pipeline, and administrative access can all become relevant to the page’s security.
TLS protects the connection to the selected origin. It does not assert that a particular version of a library was returned. A valid HTTPS response containing modified JavaScript is still a valid HTTPS response.
SRI shifts the acceptance test from location alone to location plus content. A script element can name an external URL while also stating the digest expected for the fetched file. If the host later serves different bytes, whether through compromise, accidental replacement, or an uncoordinated release, the browser can reject the resource.
That property is especially useful for static, versioned assets whose bytes are expected to remain stable.
Integrity metadata creates a release contract
An SRI digest is not a reputation score and does not establish that code is safe. It states that the retrieved content matches content represented by the supplied digest. If an approved file already contains a security defect or malicious logic, faithfully matching its digest does nothing to correct that problem.
The useful boundary is change control. Once a page pins an asset to an expected digest, changing the asset becomes a coordinated release event. The resource and the page’s integrity metadata must move together.
That is a feature, but it carries operational cost. A CDN URL that silently tracks the newest library build conflicts with strict byte-level pinning. If the file changes while the HTML retains its previous digest, the browser blocks it. Teams that value automatic upstream replacement therefore have to choose between that convenience and a stable content assertion.
Versioned immutable URLs fit the model much better. They make cache behavior, rollback, incident analysis, and integrity metadata easier to reason about because a resource identifier is expected to represent stable content.
Cross-origin delivery adds another policy boundary
SRI does not grant a page permission to read arbitrary cross-origin resources. Browser fetch and CORS rules still matter.
For cross-origin subresources covered by SRI, the response must satisfy the relevant cross-origin checks for the browser to treat it as eligible. In practice, external providers that advertise SRI-compatible assets commonly publish suitable CORS response headers, and script or link elements may use a crossorigin attribute as appropriate.
This interaction prevents integrity metadata from becoming a route around the web’s origin model. The digest answers a content question; CORS and fetch policy answer a different question about whether the cross-origin response can participate in the request.
Operational failures often appear when only one side is configured. A correct digest cannot compensate for a response that fails the browser’s cross-origin requirements. Likewise, permissive CORS does not make an altered file satisfy its integrity metadata.
Multiple digests support controlled transitions
The integrity attribute can carry multiple hash expressions. Browsers evaluate supported algorithms according to SRI processing rules rather than treating the attribute as an arbitrary list of independent approvals.
This capability can help during algorithm transitions or deployment changes, but it deserves deliberate handling. Integrity metadata is security-sensitive configuration. Generating it from the exact release artifact is safer than copying a value from an unrelated build, package listing, or stale deployment note.
The digest also needs to describe the bytes the browser ultimately checks. Infrastructure that rewrites JavaScript or CSS in transit can break the assertion even when the transformation appears harmless. Minification, banner injection, edge-side optimization, or line-ending changes should occur before the approved artifact and its digest are finalized, not unpredictably after publication.
That constraint exposes a useful design principle: security controls based on immutable content work best when the delivery pipeline also treats release artifacts as immutable.
SRI and CSP constrain different dimensions
SRI is often discussed beside Content Security Policy because both can restrict browser execution, but their decisions are not interchangeable.
CSP can govern which sources, nonces, hashes, and execution paths the browser permits. It can substantially reduce the set of resources that a document is allowed to load or execute. SRI can then assert that a particular externally loaded resource has expected content.
A policy that permits scripts from a CDN may still trust a large collection of files available at that origin. Adding integrity metadata to a specific script narrows the accepted result for that element to approved bytes. Conversely, an integrity digest does not provide the broad execution controls of CSP.
Used together, the controls can separate two questions that are easy to collapse: is this resource location permitted, and is this the artifact that was approved?
Dynamic dependency models limit the fit
Not every web dependency is a good candidate for byte pinning. Some scripts are intentionally generated per customer, locale, experiment, session, or request. Others act as bootstrap loaders that fetch additional code at runtime. A digest on the initial loader says nothing about code that the loader later retrieves unless separate controls govern those resources.
The same limitation appears with large dependency graphs. Pinning one top-level file does not automatically pin every network dependency it can invoke. The browser verifies the resource carrying the integrity requirement, not the future behavior of arbitrary code after execution.
This makes SRI strongest when applied to genuinely static assets and as part of a wider browser security model. It can reduce exposure to unexpected modification at a distribution point, but it cannot convert mutable third-party execution into a fully isolated trust relationship.
Failure should be designed as a security event
When an integrity check fails, the browser blocks the affected resource. For a decorative stylesheet, that may be visible but tolerable. For a script that initializes authentication, checkout, or core navigation, the same protection can become an availability incident.
That trade-off should be explicit. A fallback that simply loads the same dependency from an unpinned location restores availability by discarding the security property that detected the problem. A better resilience design may use a separately controlled copy with its own expected digest, or allow the feature to fail closed when executing unverified code would create greater risk.
Monitoring also matters. Browser-side integrity failures can otherwise look like ordinary front-end breakage. Content Security Policy reporting and application telemetry can provide related signals depending on the deployment, but teams still need enough observability to distinguish a stale digest from a compromised distribution path.
SRI is most valuable when the organization treats that distinction seriously. The control turns an invisible upstream content change into an enforceable boundary. Its benefit comes not from the hash syntax itself, but from making exact artifact identity part of the browser’s decision to execute code.