Add Subresource Integrity to third-party scripts on Shopify
Why it matters
If a CDN or vendor serving your scripts is compromised, the altered file runs on your pages with full access to them. An integrity hash makes the browser refuse any file that differs from the one you approved.
Staged change. Do this in stages and check each one before the next, so a mistake does not break your site or your mail.
The fix
- Stage 1: open Online Store, Themes, Edit code and find the third-party script and link tags you added to layout/theme.liquid or snippets with fixed-version URLs; compute their hashes as in the generic steps.
- Stage 2: add integrity and crossorigin="anonymous" to those tags and check the console. Scripts injected by Shopify or by apps cannot be changed from the theme.
layout/ theme.liquid
<script src="https://cdn.jsdelivr.net/npm/package@1.2.3/dist/package.min.js" integrity="sha384-PASTE_THE_HASH_HERE" crossorigin="anonymous" defer></script>
Related
Scan your domain to see whether this applies to you.