Skip to content
FunnelGuard

Fix guide by FunnelsGuard

Compromised third-party script injecting links: find and fix

SEO-317High impactPartlyBy FunnelGuardPublished Updated
On this page

What this issue is

Most sites load code from other companies: chat widgets, analytics, review badges, fonts, A/B testing tools, tag managers. This code runs with the same power as your own code. If the company is hacked, or an account or domain used to serve the file is taken over, the file can be changed. The change then reaches every site that loads it.

Why it costs you leads or sales

Search engines read your outbound links as a sign of who you endorse. Links to spam sites can hurt trust in your pages, trigger manual actions or security warnings, and push your rankings down. AI search tools that cite sources also tend to favour sites that look clean and reliable.

The same script can do more than add links. It can redirect visitors, swap your buttons, capture form data or load ads. Visitors who see a warning or get sent away do not become leads. Fixing the cause late also means weeks of cleanup and re-review.

How a hacked script reaches your visitors
  1. Vendor hackedScript file or its host is altered
  2. Your page loads itScript tag still points to the vendor
  3. Links injectedHidden spam links added in the browser
  4. Search trust dropsRankings and warnings suffer

The break happens outside your own server, which is why your files look fine.

How it usually unfolds (Example)
  1. Day 0

    A vendor script is altered. Your site loads it without any change on your side.

  2. Days 1-14

    Hidden links appear on every page that loads the script. Nobody notices.

  3. Weeks 2-4

    Search engines crawl the links. Rankings slip or a warning shows in Search Console.

  4. After cleanup

    Script removed, site re-reviewed, visibility slowly recovers.

How to check if your site has it

Look for links you did not add
  1. Compare source with the rendered page

    Open a page, press Ctrl+U (Cmd+Option+U on Mac) for the source, then open DevTools > Elements and search for <a href=. Links that exist in Elements but not in the source were added by JavaScript.

  2. Search for hidden links

    In DevTools > Elements, search for display:none, left:-9999px, font-size:0 and visibility:hidden near anchor tags. Spam links are often hidden this way.

  3. List every script your page loads

    In DevTools > Network, filter by JS and reload. Note each domain. Remove anything you do not recognise or no longer use.

  4. Check what a script itself changed

    In Network, click each third-party file and look for obfuscated code, eval(, atob( or calls that create a elements.

  5. Look as a search crawler would

    In Google Search Console, use URL Inspection > View crawled page > HTML to see the rendered HTML Google saw. Also check the Security issues and Manual actions reports.

  6. Crawl the site

    Use a crawler that renders JavaScript and export all external links. Sort by domain and look for unfamiliar ones.

Paste in the DevTools console to list external linksjavascript
[...document.querySelectorAll('a[href^="http"]')]
  .filter(a => a.hostname !== location.hostname)
  .map(a => ({
    href: a.href,
    text: a.textContent.trim().slice(0, 40),
    visible: !!(a.offsetWidth || a.offsetHeight)
  }));

Any link with visible: false that you did not add is a strong warning sign. Check legitimate ones too, such as a vendor's "powered by" link.

How to fix it

Remove the script and close the gap
  1. Identify the offending script

    In DevTools, right-click an injected link > Break on > Subtree modifications, then reload. The debugger stops on the code that inserts it and shows the source file.

  2. Remove it right away

    Delete the script tag, disable the plugin or pause the tag. Do this first, ask questions later.

  3. Tell the vendor

    Report what you found with the file URL and a screenshot. Only add the script back once they confirm it is clean.

  4. Rule out your own site being hacked

    Check that your own files, admin users and tag manager accounts are not changed. Rotate passwords and turn on two-factor sign-in.

  5. Ask search engines to re-check

    Once clean, request a review in Search Console if a security issue or manual action was reported, and re-inspect key URLs.

Where to remove or replace the script
  1. Find the source

    Go to Plugins > Installed Plugins and deactivate one at a time, reloading the page, until the links disappear. Also check Appearance > Theme File Editor and any header/footer script plugin.

  2. Replace the code

    Delete the plugin or reinstall it fresh from the official directory. Do not keep a copy from an unknown source.

Subresource Integrity on a static, versioned scripthtml
<script
  src="https://cdn.example.com/lib/1.2.3/lib.min.js"
  integrity="sha384-REPLACE_WITH_REAL_HASH"
  crossorigin="anonymous"></script>
Example Content Security Policy header (test in report-only mode first)text
Content-Security-Policy-Report-Only: script-src 'self' https://www.googletagmanager.com https://cdn.example.com; object-src 'none'; base-uri 'self'; report-to csp-endpoint
Script setup before and after

Before

  • Dozens of unreviewed third-party scripts
  • Anyone with tag manager access can publish
  • No alert when a script changes

After

  • Only scripts you need, each with a named owner
  • Allowed script sources set in a CSP
  • Fixed files pinned with SRI, weekly link check

How to confirm it's fixed

Confirm the cleanup
  • The console snippet shows no unknown external links on your key pages
  • Network tab shows no scripts from domains you do not recognise
  • Search Console URL Inspection shows clean rendered HTML
  • Security issues and Manual actions reports are empty, or a review is requested
  • Tag manager version history shows only changes you made
  • Passwords rotated and two-factor sign-in on for CMS, tag manager and hosting

How to prevent it happening again

Prevention habits
  • Keep a list of every third-party script, who owns it and why it is there
  • Remove tags and plugins you no longer use
  • Limit who can publish in your tag manager and review its change log
  • Roll out a Content Security Policy, starting in report-only mode
  • Use SRI for versioned files from CDNs
  • Run a rendered-link check monthly on key templates
  • Watch vendor security notices and update plugins promptly

How FunnelGuard handles this

FunnelGuard covers this issue partly. It checks for third-party script failures only: when a script on your journey fails to load or breaks a step, the robot visitor sees it, re-checks from a second region and sends one alert with a screenshot and a likely cause.

What it does not do: it does not scan your pages for injected or hidden links, does not compare script contents over time, and does not judge whether a script is malicious. A hacked script that loads fine and quietly adds links will not trigger an alert.

To cover the rest by hand, run the console snippet above on your key pages each month, review Search Console's Security issues report, audit your tag manager change log, and use a rendered-HTML crawler for a site-wide link export. If a script starts breaking forms or buttons, FunnelGuard's alert can be the first hint that something changed. FunnelGuard has a Free plan with 1 site and 2 journeys, and a free read-only website audit.

Questions people ask

How can a third-party script inject links into my website?

The script runs with the same permissions as your own code, so it can add elements to the page. If the vendor or its hosting is hacked, the changed file can insert hidden anchor tags for every site that loads it. The links appear in the browser, not in your own files.

How do I find hidden spam links on my website?

Compare the page source (Ctrl+U) with the rendered DOM in DevTools > Elements, and run a console snippet that lists external links and whether they are visible. In Search Console, URL Inspection > View crawled page shows the HTML Google saw. Links you did not add, especially hidden ones, are the red flag.

Why do I see links in DevTools but not in View Source?

View Source shows the HTML sent by your server. DevTools shows the page after JavaScript has run. Links that appear only in DevTools were added by a script, which is exactly how injected spam links work.

Can Google Tag Manager be used to inject spam links?

Yes. A Custom HTML tag can add links to any page, so an attacker with tag manager access can do it without touching your site files. Review your tags and Versions history, remove unknown users and turn on two-factor sign-in.

Does Subresource Integrity stop a hacked script?

It does for fixed, versioned files. The browser refuses to run the file if its hash no longer matches. It does not suit scripts the vendor changes in place, such as most tag managers and chat widgets, so pair it with a Content Security Policy.

Will hidden spam links hurt my Google rankings?

They can. Search engines may treat them as link spam or a sign of a compromised site, which can lead to lower visibility, warnings or a manual action. Remove the cause quickly and request a review if Search Console reports a problem.

Does FunnelGuard detect injected links from a compromised script?

Only partly. It detects third-party script failures on your journeys and alerts you, but it does not scan for injected or hidden links. Check those by hand with a rendered-page link check and Search Console.

Does FunnelGuard catch this?

Partly

FunnelGuard checks part of this.

How: Third-party script failures only.

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.