Subresource Integrity (SRI) is a browser feature that checks a fetched script or stylesheet against a hash you provide. If the downloaded file does not match, the browser blocks it.
Why it matters
Many pages load libraries from a CDN or other third party. If that host is compromised, every site using the file would run the attacker's version. SRI means a tampered file is rejected instead of executed, which limits supply-chain risk. It works best with versioned, immutable files, since any legitimate change alters the hash.
Example
<script src="https://cdn.example.com/lib.min.js"
integrity="sha384-BASE64HASHHERE"
crossorigin="anonymous"></script>
The integrity attribute holds the algorithm and base64 digest. The crossorigin attribute is needed so the browser can check cross-origin resources.
Common mistakes
- Adding SRI to a URL whose content changes, such as a "latest" file, which then breaks the page.
- Forgetting
crossorigin, which makes the check fail. - Believing SRI protects scripts that load further scripts dynamically.
- Copying a hash from an untrusted source instead of computing it from a known-good file.
Related
Get notified when this term updates
Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.
यह पेज सामान्य जानकारी है, जिसे हमारी संपादकीय टीम ने लिखा है और दस्तावेज़ीकरण बदलने पर अपडेट किया जाता है। सर्वर और प्रदाता अलग-अलग होते हैं, इसलिए बदलाव पहले सुरक्षित तरीके से जाँचें। देखें: संपादकीय नीति और अस्वीकरण.