What is Subresource Integrity?
Subresource Integrity (SRI) is a tamper check for scripts and stylesheets your page loads from other domains. You add an integrity attribute holding a fingerprint of the file. If the file is ever changed, the fingerprint no longer matches and the browser refuses to run it, so a break-in at your supplier does not become a break-in on your page.
What the Shield scan checks
Outside scripts, shown beside your score. It is not part of the 100 points. Shield reads the HTML of your home page and counts the script tags whose src points at a domain other than yours. It reports how many of those have no integrity attribute. It does not verify that an integrity value is correct, and it does not see scripts that other scripts add later.
If the check finds a problem, the scan tells you: 2 of 3 script(s) from other domains load without a tamper check. If that domain is breached, so is your page.
What it looks like
<script src="https://cdn.example.com/library-3.7.1.min.js"
integrity="sha384-BASE64-FINGERPRINT-OF-THE-FILE"
crossorigin="anonymous"></script>
The value starts with the hash type (sha256, sha384 or sha512), then a dash, then the fingerprint of the exact file.
How to add it
- Load a fixed version of each outside file, not an address that always points at the latest one.
- Copy the integrity value published by the supplier, or generate it from the file yourself.
- Add
integrityandcrossorigin="anonymous"to the tag. - Load the page and check the browser console. A mismatch is reported there and the file is blocked.
- When you upgrade the file, update the fingerprint with it.
What it does not cover
SRI protects files your page asks for directly. It does not control what an approved script does once it runs. Pair it with a Content Security Policy.
Count your unprotected outside scripts now
Type your website address to run the free scan. It checks this and the other 10 items. No account, no email.
The interactive scan needs JavaScript. See the checks you can run yourself.
Questions
Can I use SRI on a script that changes often?
Not usefully. The fingerprint matches one exact file, so a script whose content changes will be blocked. Use SRI for files pinned to a fixed version, and keep changing scripts to suppliers you trust and a tight Content Security Policy.
Do I need SRI for scripts on my own domain?
It adds little there. SRI is aimed at files served from somewhere you do not control.
What is the crossorigin attribute for?
A browser can only check the fingerprint of a file from another domain when that file is requested with CORS. Adding crossorigin="anonymous" makes that request without sending cookies.
Sources
- MDN: Subresource Integrity
- W3C: Subresource Integrity
- OWASP: Third Party JavaScript Management Cheat Sheet
Written by Apex Flow Labs LLC for Apex Flow Shield. A score of 100 means the responses Shield received passed all 11 of its checks. It does not prove each setting is configured well, and no scan can show that a website cannot be attacked.