Skip to content
GDPR compliant. Hosted in DE.
14-day free trial →
Supply-Chain ProtectionIntegrity VerificationSecurity Headers
Security 12 min read 14 Jun 2026

Subresource Integrity (SRI): Secure Your Scripts 2026

SRI hashes protect against tampered CDN and third-party scripts. Learn how to monitor SRI coverage and detect changed external resources early on in 2026.

X

XICTRAQ Team

XICTRAQ

SRISecuritySupply-ChainSubresource IntegrityCDN
92%
of pages load third-party code (HTTP Archive 2024)
100,000+
websites attacked via a tampered CDN script (Sansec)
3.23%
median of scripts per page protected by SRI (HTTP Archive 2024)
Subresource Integrity (SRI): stop tampered CDN scriptsProtected with SRI hash<scriptintegrity="sha384-…"src="//cdn/app.js">Script tag with integrityCCDN delivers filelegit✓Hash matchesScript executesAttacker tampers with fileHash differsSRI✕✕Browser blocks scriptSHA-256 / SHA-384 / SHA-512as integrity hash (W3C SRI)crossorigin=anonymous (MDN)Unprotected without SRI<scriptsrc="//cdn/app.js">// no integrity attributeScript tag without integrityCCDN delivers filetampered!Attacker injects codeno hash comparisonMalicious code runs in browserSkimming · data exfiltration!Payment data harvested92% of pages load third-party codemedian 20 external scripts/page(HTTP Archive Web Almanac 2024)100,000+ websites attacked via a tampered CDN script (Sansec, Polyfill.io 2024)
When you embed a script from a CDN, you blindly trust that the delivered code is unchanged — on every single page view by your visitors. In 2024, that trust backfired spectacularly: in the Polyfill.io attack, adversaries delivered malicious code to more than 100,000 websites through a popular CDN script (Sansec) — later analyses counted over 380,000 affected hosts (The Hacker News). Subresource Integrity (SRI) is the browser technique that prevents exactly this: a cryptographic hash in the integrity attribute ensures the browser only executes a script if it exactly matches the expected content. If the file is tampered with at the CDN, the hash differs and the browser blocks it. This guide explains how SRI works, why it remains so rarely used at scale despite its effectiveness, and how continuous security header monitoring keeps your SRI coverage complete.

What Subresource Integrity Is and Why It Matters in 2026

Subresource Integrity is a W3C standard that lets browsers verify the integrity of externally loaded resources. You add an integrity attribute containing a cryptographic hash of the expected file content to a <script> or <link> tag. Before the browser executes the script or applies the stylesheet, it computes the hash of the downloaded file and compares it to the stored value. If both match, the resource runs — otherwise the browser discards it and reports an error (MDN).

The relevance stems from the reality of modern websites: 92% of all pages load at least one third-party resource (HTTP Archive Web Almanac 2024), and the median page requests 20 external scripts totaling around 449 KB (HTTP Archive Web Almanac 2024). Scripts account for 30.5% of all third-party requests by content type (HTTP Archive Web Almanac 2024). Each of these scripts is a potential entry point: if a provider's server is compromised or the file is altered in transit, foreign code runs with full privileges in your page context.

SRI addresses a very specific threat class: supply-chain attacks via compromised or swapped scripts. ENISA ranks traditional software supply-chain attacks among the ten most common threat categories — they accounted for 10.6% of analyzed incidents (ENISA Threat Landscape 2025, 4,875 incidents examined). That is precisely where SRI fits: it does not protect against a hacked CDN account, but it prevents the code tampered with there from causing harm in your visitors' browsers.

How an SRI Hash Works Technically

An SRI hash is a Base64-encoded cryptographic fingerprint of the file content, prefixed with an algorithm identifier. The browser downloads the resource, computes the hash on the fly, and aborts execution as soon as the value differs (MDN). The allowed prefixes are sha256, sha384, and sha512 — conformant browsers must support all three (W3C SRI). In practice, sha384 is recommended as a balanced compromise between security and performance.

Script tag with Subresource Integrity
<script
  src="https://cdn.example.com/lib.js"
  integrity="sha384-oqVuAfXRKap7fdgcCY5uykM6R9GqQ8K"
  crossorigin="anonymous"></script>

<link
  rel="stylesheet"
  href="https://cdn.example.com/style.css"
  integrity="sha384-9ndCyUa8q2y2bI3rvT2gI3lyf3v6dGmF"
  crossorigin="anonymous">
Why crossorigin="anonymous" is mandatory

For resources from a different origin (cross-origin), the browser must be able to read the response bytes to compute the hash. This requires the CORS protocol: the crossorigin="anonymous" attribute tells the browser to make a CORS request, and the delivering server must respond with an appropriate Access-Control-Allow-Origin header (MDN). Without CORS, the browser treats the response as opaque and cannot verify integrity — the resource is then blocked even though it is legitimate.

You can specify multiple hashes — for example for different algorithms — separated by spaces. The browser uses the strongest one it supports. This enables a smooth migration from weaker to stronger hash functions without locking out older clients. Important: SRI protects static, immutable files. For resources that change dynamically on the server, the hash would have to be regenerated on every change — SRI is unsuitable here.

Supply-Chain Attacks: The Threat SRI Addresses

Web skimming — also known as Magecart — is the most prominent attack form SRI helps against. Attackers inject JavaScript into payment or form pages to harvest credit card and login data directly in the browser. According to a RiskIQ analysis, a Magecart attack is attempted every 16 minutes (RiskIQ). The threat is growing: Recorded Future recorded a 103% increase within six months in the 2024/2025 period (Recorded Future).

Polyfill.io 2024

After the domain was taken over, malicious code was delivered to over 100,000 websites through the popular script (Sansec); later counts cited 380,000+ hosts (The Hacker News). SRI would have blocked the tampered file.

CosmicSting

During this campaign, 5 to 30 stores per hour were temporarily compromised (Sansec). The report cites roughly 75% of Adobe Commerce and Magento platforms as affected (Sansec).

S3 bucket attack

A Magecart group compromised misconfigured cloud storage, affecting more than 17,000 domains (Imperva) — some high-profile sites. Not a single server hack, but a script swap in the supply chain.

Stolen credentials

Stolen credentials were used in 77% of web application breaches (Verizon DBIR 2024). If an attacker has access to the CDN account, only a client-side integrity check like SRI provides protection.

What makes this attack class so insidious is that it completely bypasses classic server-side defenses. A web application firewall, a hardened server, and regular backups do not help when the malicious code is delivered legitimately through an embedded third-party script and executed exclusively in the visitor's browser. The shop operator's server never 'sees' this code — it lives in the source of a file on a foreign CDN. This is precisely the gap a client-side integrity check closes: SRI moves control to where the code is actually executed. Given that skimming campaigns like CosmicSting temporarily hit 5 to 30 stores per hour (Sansec), this shift is not a theoretical luxury but a practical necessity for any operator embedding foreign scripts.

The economic dimension is substantial: the average cost of a data breach in 2024 was USD 4.88 million (IBM Cost of a Data Breach 2024). For a German online shop, a record harvested via foreign code means not only reputational damage but also a potential reporting obligation under Art. 33 GDPR.

The Reality: SRI Is Common but Barely Used

The adoption numbers paint a paradoxical picture. On one hand, SRI is present on many sites: 23.2% of desktop pages and 21.3% of mobile pages use at least one integrity attribute (HTTP Archive Web Almanac 2024). On the other hand, actual coverage is minimal: the median is just 3.23% of scripts per page checked against a hash — and this figure has remained virtually unchanged since 2022 (HTTP Archive Web Almanac 2024).

PercentileScripts with SRI (desktop)Assessment
10th percentile1.4%Negligible
25th percentile2.0%Very low
50th percentile (median)3.23%Low — stagnant since 2022
75th percentile5.7%Room to improve
90th percentile12.5%Low even at the top end

Even the sites with the highest coverage protect only 12.5% of their scripts via SRI at the 90th percentile (HTTP Archive Web Almanac 2024). Most protected resources come from CDNs — the leaders are www.gstatic.com (35%), cdnjs.cloudflare.com (7%), and code.jquery.com (5–6%) (HTTP Archive Web Almanac 2024). Notably, Shopify dropped SRI in favor of the integrity attribute of import maps (HTTP Archive Web Almanac 2024) — an indication that the protection mechanism is evolving.

SRI Working Together with CSP and Other Headers

SRI is not a lone wolf. It delivers its full protective effect in combination with other security mechanisms — above all the Content Security Policy. While SRI secures the integrity of known, allowed scripts, CSP controls which sources may be loaded at all. The two complement each other rather than replace one another.

  • CSP require-sri-for approach: CSP can enforce that scripts and styles only load with a valid integrity hash — turning SRI from a recommendation into a requirement.
  • script-src with nonces: CSP authorizes legitimate scripts via one-time tokens, while SRI additionally verifies their content. Together they exclude both injection and tampering.
  • Strict-Transport-Security (HSTS): Enforces HTTPS and prevents scripts from being swapped over an unencrypted connection in transit.
  • Mixed-content avoidance: Complements SRI, because mixed content opens an unencrypted supply chain in which tampering becomes possible in the first place.
  • X-Content-Type-Options: Prevents MIME sniffing so a resource is not interpreted as an executable script against its declaration.

If you have already cleanly configured your HTTP security headers, you should treat SRI as the logical next building block. Only the combination of transport security (HTTPS/HSTS), source control (CSP), and integrity verification (SRI) forms a multi-layered concept against script-based attacks. It is also worth examining the certificate trust layer: continuous evaluation of Certificate Transparency logs uncovers mis-issued certificates, which can be a prerequisite for undetected man-in-the-middle tampering with scripts.

SRI as a Compliance Building Block: PCI DSS 4.0 and GDPR

SRI is no longer just a nice-to-have. With PCI DSS 4.0, integrity verification of scripts on payment pages became effectively mandatory. Requirement 6.4.3 calls for an inventory of all scripts used on payment pages, in which each resource is authorized, integrity-checked, and justified (PCI Security Standards Council). Requirement 11.6.1 adds the obligation to detect and alert on unauthorized changes to headers and scripts of the payment page (PCI Security Standards Council).

Two web standards for PCI compliance

PCI requirements 6.4.3 and 11.6.1 point directly to two open web standards: Subresource Integrity and Content Security Policy (PCI Security Standards Council). These requirements have been mandatory since March 31, 2025 — anyone processing credit card payments through their own site can hardly avoid an integrity check of their scripts.

SRI also contributes in the GDPR context. Art. 32 GDPR requires 'appropriate technical and organizational measures.' If SRI prevents tampered third-party code from exfiltrating personal data, it demonstrably reduces the risk of a reportable data breach. In combination with a documented data protection impact assessment for web tracking, this creates robust evidence of technical safeguards.

Monitoring SRI Coverage: Why Setting It Once Is Not Enough

The biggest practical problem with SRI is not the setup but the maintenance. An integrity attribute is only as good as its hash — and that hash is valid for exactly one file version. When a CDN provider updates its library, a build process changes the file, or a developer switches the script source, one of two things happens: either the script breaks because the old hash no longer matches, or the attribute is removed in the heat of the moment — and protection silently disappears.

This is exactly where continuous monitoring comes in. There are two complementary layers: first, the detection of new, unprotected external scripts — resources added without an integrity attribute. Second, the detection of changed externals, where the delivered content of a third-party file has changed compared to the last check. Both are early warning signs of a potentially compromised supply chain.

Detecting changed externals

A script that was unchanged yesterday and delivers different content today without you performing a deployment is a classic supply-chain warning sign. Automated monitoring that regularly fetches and compares external resources makes such deviations visible before they cause harm — and complements the detection of third-party script risks with a content-based check.

The stagnation of SRI coverage — unchanged since 2022 at around 3.23% of scripts per page (HTTP Archive Web Almanac 2024) — shows that manual maintenance is rarely sustained over time in practice. The reason is humanly understandable: an integrity attribute set once is quickly forgotten in day-to-day work, and after the first broken script following a CDN update, developers are tempted to remove the protection entirely rather than recompute the hash on every update. Continuous monitoring reverses this incentive pattern: instead of treating SRI as tedious manual labor, the state of script protection becomes a measurable metric that surfaces on every deviation — and that is exactly what prevents the silent slide into an unprotected state.

SRI Checklist and Automated Header Monitoring

An effective SRI strategy combines careful setup with continuous control. The following checklist summarizes the most important steps — from initial implementation to ongoing monitoring.

  1. Inventory external scripts — capture all <script> and <link> tags with a foreign origin. A security scan provides the complete overview including dynamically loaded resources.
  2. Set integrity + crossorigin="anonymous" for every static third-party resource — preferably with a sha384 hash (W3C SRI).
  3. Regenerate the hash on every version change — a hash is valid for exactly one file version; outdated hashes break the script.
  4. Add CSP to turn SRI from a recommendation into a requirement and to exclude unwanted sources on principle.
  5. Monitor unprotected and changed externals — new scripts without integrity and content-deviating files are early warning signs.
  6. Prioritize payment and form pages — here PCI DSS 6.4.3/11.6.1 requires a script inventory plus change detection (PCI Security Standards Council).

The XICTRAQ security score rates your website partly based on the security headers in place and the protection of external resources. If a protection mechanism disappears, a new unprotected script appears, or a critical header configuration changes, you receive a timely notice via alerting notifications — by email, Slack, Discord, or Telegram. In combination with ongoing security monitoring, securing your script supply chain turns from a one-time action into a permanently monitored state.

Sources and Studies

This article is based on data and standards from: HTTP Archive Web Almanac 2024 (SRI adoption, third-party scripts), Sansec (Polyfill.io and CosmicSting analyses), The Hacker News (Polyfill.io reach), ENISA Threat Landscape 2025 (supply-chain incidents), RiskIQ (Magecart frequency), Recorded Future (Magecart growth), Imperva (Magecart S3 campaign), Verizon Data Breach Investigations Report 2024 (web application breaches), IBM Cost of a Data Breach 2024, W3C Subresource Integrity (specification), MDN Web Docs (SRI mechanics), PCI Security Standards Council (PCI DSS 4.0 requirements 6.4.3 and 11.6.1).

Frequently Asked Questions About Subresource Integrity

What happens if an SRI hash does not match the script?
The browser discards the resource and does not execute it, or does not apply the stylesheet. An integrity error message typically appears in the console. This is the intended behavior: a deviating file is treated as potentially tampered with. In practice, such a mismatch usually occurs when a provider updated its file without the stored hash being updated accordingly.
Does SRI protect against all supply-chain attacks?
SRI reliably protects against one specific class: the swapping or tampering of static files referenced by hash. In our experience it is a very effective building block, but it does not replace a comprehensive security strategy. Dynamically generated scripts, attacks within an allowed source, or compromised build pipelines are not covered by SRI. In combination with CSP and continuous monitoring, however, the protective effect can be significantly increased.
Do I need SRI for my own scripts too?
For scripts from your own domain, SRI is usually less critical because you control delivery yourself. SRI provides the greatest value for resources from third parties and CDNs, since you have no direct control over the delivered content there. For particularly sensitive pages — such as the checkout — SRI for your own scripts can still make sense to rule out tampering in transit.
Why do so few websites use SRI at scale?
Although around 23% of pages use SRI, the median is only about 3% of scripts per page (HTTP Archive Web Almanac 2024). The main reason is the maintenance effort: each hash is valid for one file version only and must be regenerated on updates. Without automated support, SRI is therefore often used only selectively or silently removed after an update.
Is SRI required for PCI DSS compliance?
PCI DSS 4.0 does not name SRI as mandatory by name, but requirements 6.4.3 and 11.6.1 explicitly reference Subresource Integrity and Content Security Policy as suitable standards (PCI Security Standards Council). Anyone operating payment pages must maintain a script inventory with integrity checking and detect changes — SRI is typically one of the most practical ways to do this.
How do I know if an external script has changed?
Doing this manually is hardly practical, because you would have to fetch and compare every external file regularly. In our experience, automated monitoring that periodically checks external resources, reports new unprotected scripts, and makes content deviations visible is the most reliable approach. This way, an unexpected change in the supply chain is noticed before it affects your visitors.

Related in XICTRAQ

Start in 60 seconds

Let XICTRAQ watch your website.

Permanent free plan available. No credit card, no installation, no hidden fees.