Missing integrity attribute

Missing integrity attribute

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 script and link elements, set integrity to the hash of the file you verified. Review each new version before updating the hash.
  • For a cross-origin file, set crossorigin and 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.

References