Description
Subresource Integrity (SRI) lets a browser check an external script or stylesheet against an expected hash before using it. The check is only as trustworthy as the file used to calculate that hash.
Potential impact
If the host serves an altered file, a browser without an integrity check may run the modified script or apply the modified stylesheet.
Remediation
- On supported
scriptandlinkelements, setintegrityto the hash of the file you verified. Review each new version before updating the hash. - For a cross-origin file, set
crossoriginand make sure the host’s CORS response allows your origin.
Examples
Before
html
<script src="https://example.com/script.js"></script>
After
The URL and hash illustrate the format. Replace both with the URL and verified hash of the file you deploy.
html
<script
src="https://example.com/script.js"
integrity="sha384-OgVRvuATPupdUSgWVsKllsZZAgvFiTpjlPdSdj0eGVcI/A5efowlBbInEKwdsA5l"
crossorigin="anonymous"
></script>
A supporting browser blocks this script if the downloaded file’s hash differs from integrity.