What you need
The exact URL or file of a script or stylesheet you load from another origin, and the ability to edit the page.
Example
For a script whose entire content is alert('Hello, world.');, the sha384 digest is verified against OpenSSL (openssl dgst -sha384 -binary file | openssl base64 -A). The tag looks like this:
<script src="https://cdn.example.com/app.js" integrity="sha384-H8BRh8j48O9oYatfu5AZzq6A9RINhZO5H16dQZngK7T62em8MUt1FLm52t+eX6xO" crossorigin="anonymous"></script>
What the attributes do
integritycarries one or more hashes; the browser accepts the file if any of them matches. List a second hash to roll an update.crossorigin="anonymous"requests the file without credentials and lets the browser read it. The server must sendAccess-Control-Allow-Origin(most CDNs do).- SRI works on
<script>and<link rel="stylesheet">(and preloads). - It does not protect dynamically injected scripts or the page itself.