On this page
What this issue is
Many sites load libraries such as jQuery, Bootstrap or a slider from a CDN (content delivery network, a third-party server that hosts files). Your page trusts whatever that server sends. Subresource Integrity is a browser feature that fixes this. You add a hash (a fingerprint) of the expected file to the tag. The browser downloads the file, computes its hash and runs it only if the two match.
Why it costs you leads or sales
If a CDN account is hacked or a file is replaced, the altered script runs on your pages with full access. It can copy what people type into lead forms, change where a form posts, or send visitors elsewhere. You lose leads quietly, and browser or ad platform warnings can follow.
- Visitor loads pagePage requests a CDN script
- CDN serves altered fileNo integrity hash to compare
- Malicious code runsReads form fields
- Lead data divertedSent to a third party
Without SRI the altered file runs. With SRI the browser stops at the hash check.
How to check if your site has it
View the page source
Open your key pages (home, landing, form, checkout) and choose View Source. Search for
<script src="https://and<link rel="stylesheet" href="https://.Look for integrity
Each tag pointing to another domain should contain
integrity="sha384-..."andcrossorigin="anonymous".Use the Network tab
In browser DevTools, open Network, reload, and filter by JS and CSS. Note every file from a domain that is not your own.
Sort them
Mark each as a fixed-version library (SRI suitable) or a vendor tag such as analytics or chat (usually not suitable).
How to fix it
Pin the file to an exact version URL, generate a hash, and add both attributes. The crossorigin attribute is needed so the browser can read the file to hash it, and the CDN must send CORS headers (most public CDNs do).
<script
src="https://code.jquery.com/jquery-3.7.1.min.js"
integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo="
crossorigin="anonymous"></script>curl -s https://code.jquery.com/jquery-3.7.1.min.js | openssl dgst -sha384 -binary | openssl base64 -A
# Put the output after "sha384-" in the integrity attributeFind the enqueue call
In your theme or plugin, locate
wp_enqueue_scriptcalls with external URLs.Add the attributes
Use the
script_loader_tagfilter to addintegrityandcrossoriginfor a given handle, or hard-code the tag in a child theme. Better still, host the file locally.
Edit theme.liquid
In Online Store > Themes > Edit code, find external
<script>tags intheme.liquidor section files and add the attributes.Leave app scripts alone
Scripts injected by apps are not in your theme code and cannot be pinned this way.
Custom HTML tags
If a Custom HTML tag loads a library from a CDN, add the integrity and crossorigin attributes to that tag's script element.
Skip vendor templates
Do not try to pin Google's own gtm.js or gtag.js. They change without notice and a hash would break them.
Use custom code
In Project Settings > Custom Code or a page's custom code, edit external script tags to include the attributes.
Edit templates
Update the layout files that print the tags, then consider a build step that generates hashes automatically (webpack has an SRI plugin).
Before
- Loads /latest/ from a CDN
- No integrity attribute
- Any change runs on your pages
After
- Exact version URL
- integrity=sha384 hash plus crossorigin
- Changed file is blocked by the browser
How to confirm it's fixed
- Reload the page with DevTools Console open and confirm there are no 'Failed to find a valid digest' errors.
- Check in the Network tab that each pinned file loads with status 200.
- Test the lead form and checkout end to end after the change.
- Temporarily alter one character of a hash in a staging copy and confirm the browser blocks the file, then restore it.
How to prevent it happening again
Keep a list of every third-party file your pages load and who owns it. Pin versions, record hashes alongside the version number, and regenerate the hash whenever you upgrade. Self-hosting libraries removes the CDN from the trust chain. SRI works well alongside a Content-Security-Policy that limits which domains may serve scripts.
How FunnelGuard handles this
FunnelGuard does not check for missing Subresource Integrity today. It is a possible future check. FunnelGuard runs your real customer journeys on a schedule and checks each step, the tracking hits sent to ad and analytics platforms, and whether test leads arrive. So if a blocked or altered script breaks a form or a tag, the journey check can show that the step failed, but it will not tell you SRI was missing.
Questions people ask
What is Subresource Integrity (SRI)?
SRI is a browser security feature. You add an integrity attribute containing a hash of a script or stylesheet to its tag. The browser only runs the file if its content matches the hash.
Why is my script blocked after I added an integrity attribute?
The hash does not match the file the browser received. Common causes are a wrong hash, a URL that serves changing content, or a missing crossorigin="anonymous" attribute. Check the Console for the exact error.
How do I generate an SRI hash?
Download the file and run openssl dgst -sha384 -binary file.js | openssl base64 -A, then prefix the result with sha384-. Online SRI generators and the CDN's own copy-snippet option do the same.
Do I need crossorigin anonymous with SRI?
Yes, for files from another domain. The browser needs a CORS request to read the file and verify the hash, and the CDN must allow it.
Can I use SRI on Google Tag Manager or Google Analytics scripts?
No. These scripts are updated by the vendor without notice, so a fixed hash would soon fail and block them. Use SRI for versioned libraries you choose, not vendor tags.
Is missing SRI a serious vulnerability?
It is a low-likelihood but high-damage risk. It matters only if a CDN or the file is tampered with, but then the injected code can read form data on your pages.
Does FunnelGuard detect missing SRI?
No, not yet. It may become a future check. FunnelGuard does run your journeys and can show when a form or tag step stops working.
Related issues
- OPS-170Missing Content-Security-PolicyFix guide
- OPS-172Missing X-Content-Type-OptionsFix guide
- OPS-173Missing Referrer-Policy (URLs with PII leak to third parties)Fix guide
- OPS-177Reflected XSS in form fields or searchFix guide
- OPS-178Stored XSS via form submissions into adminFix guide
- OPS-174Missing Permissions-PolicyFix guide