Skip to content
FunnelGuard

Fix guide by FunnelsGuard

Subresource Integrity missing on CDN scripts: how to fix it

OPS-193Low impactCould addBy FunnelGuardPublished Updated
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.

What happens when a CDN file is tampered with
  1. Visitor loads pagePage requests a CDN script
  2. CDN serves altered fileNo integrity hash to compare
  3. Malicious code runsReads form fields
  4. 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

Find unprotected third-party scripts
  1. 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://.

  2. Look for integrity

    Each tag pointing to another domain should contain integrity="sha384-..." and crossorigin="anonymous".

  3. 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.

  4. 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 tag with SRIhtml
<script
  src="https://code.jquery.com/jquery-3.7.1.min.js"
  integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo="
  crossorigin="anonymous"></script>
Generate a hash yourselfbash
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 attribute
Where to add the attributes
  1. Find the enqueue call

    In your theme or plugin, locate wp_enqueue_script calls with external URLs.

  2. Add the attributes

    Use the script_loader_tag filter to add integrity and crossorigin for a given handle, or hard-code the tag in a child theme. Better still, host the file locally.

Script tag before and after

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

Verification
  • 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.

Does FunnelGuard catch this?

Could add

Not checked yet: could be added to FunnelGuard.

Stop finding out from your customers

FunnelGuard runs your real forms and checkouts on a schedule, checks the tracking and the leads behind them, and alerts you once, with a screenshot. Try any paid plan free for 3 days.