Cryptojacking scripts turn your visitors’ browsers into unpaid mining rigs, and most site owners only find out when someone complains that the page makes their laptop fan spin up. This article explains how cryptojacking detection works in practice: where these scripts hide in website code, which signatures and runtime behaviors give them away, and how to clean them up so they stay gone. It’s written for developers, WordPress administrators and security auditors who have a suspicious script tag in front of them, or who want to make sure they never do.
How Browser Mining Ends Up in Your Pages
Browser-based mining became popular in 2017, when Coinhive released a JavaScript miner for Monero. Site owners were supposed to add it on purpose. Attackers added it to sites without asking. The best-known case was in February 2018, when the Browsealoud accessibility plugin was compromised and served Coinhive to thousands of sites, including UK government domains.
Today the infection paths are the same ones used for most client-side attacks. Attackers inject code through vulnerable WordPress plugins, steal FTP or hosting panel credentials, tamper with a third-party script at its source, or slip a malicious package into an npm dependency tree. The payload is usually a small loader that pulls a WebAssembly mining module and connects over WebSocket to a mining pool proxy.
Myth: Cryptojacking Died with Coinhive
Coinhive shut down in March 2019, and many people assume the threat went with it. That’s wrong. Forks and replacements such as CryptoLoot, CoinIMP and a long list of self-hosted pool proxies kept running. Attackers also learned to host the miner code on the compromised site itself, so blocking a known domain doesn’t catch anything.
There’s a second myth worth dropping: that cryptojacking is harmless because “it only uses some CPU.” A site that can be made to run a miner can just as easily be made to run a card skimmer or a credential harvester. The miner is evidence of write access to your code, and that’s the real problem.
Detecting Cryptojacking Scripts in Source Code
An experienced auditor starts with static signatures and then moves to behavior, because modern miners are almost always obfuscated. On the static side, these patterns are worth grepping for across the web root, theme files and database dumps:
– Known library names and objects such as CoinHive.Anonymous, CRLT, Client.Anonymous or variables containing “miner” and “throttle”
– WebAssembly.instantiate or .wasm files that no part of your application should need
– WebSocket URLs (wss://) pointing to unfamiliar hosts, especially on ports like 3333, 5555 or 7777
– Calls to new Worker() spawned in a loop, often sized to navigator.hardwareConcurrency
– Obfuscation wrappers like eval(atob(…)), long hex-escaped strings or String.fromCharCode chains
A combined search such as grep -rEn “hardwareConcurrency|WebAssembly|wss://|eval(atob” across wp-content and your build output takes seconds. Expect false positives, since legitimate bundles also use workers and WebAssembly, but every hit outside a known vendor file deserves a look.
Runtime Signals: What the Browser Tells You
Static analysis misses code that’s built at runtime or loaded only for certain visitors. Attackers often serve the miner only to non-admin users, only on mobile, or only every 5th page view, so an admin browsing their own site sees nothing.
A practical runtime check goes like this. Open the page in a private window with a fresh profile and no admin cookies. In Chrome DevTools, record 30-60 seconds in the Performance tab and look for sustained CPU usage while the page is idle. Then check the Network tab filtered by WS for persistent WebSocket connections that exchange small JSON messages, which are typical of the pool protocol. Finally, look under Sources for worker threads you can’t trace back to your own code.
An idle content page should drop close to 0% CPU within a few seconds of loading. A page that holds 4 cores at 80-100% for a full minute is mining, whatever the script calls itself.
A Realistic Cleanup Scenario
Here is a typical case. A WooCommerce store gets customer reports of slow checkout pages on phones. The developer searches the theme files, finds nothing, and decides it’s a hosting problem. Two weeks later, an external scan flags an unknown script loaded from a lookalike analytics domain.
The injection was never in the files at all. It sat in the wp_options table, inside a widget’s HTML, placed through a known flaw in an outdated form plugin. Cleaning it took four steps: export the database and search it for script tags and base64 blobs, remove the injected content, update or remove the vulnerable plugin, and rotate every admin password and application key. Skipping that last step is how reinfections happen within days.
Common Mistakes in Cryptojacking Detection
Scanning files but not the database. On CMS platforms, injected scripts often live in post content, widget settings or theme options. A file-integrity check will report everything as clean while the miner keeps running.
Trusting a whitelisted CDN. A Content Security Policy that allows all of cdn.jsdelivr.net or unpkg.com lets an attacker load any package hosted there, including a miner. Pin exact files with Subresource Integrity hashes and allow specific paths instead of whole domains.
Removing the symptom, not the entry point. Deleting the script tag feels like a fix. Unless you know how the code got in, whether through a plugin CVE, a leaked credential or a compromised dependency, the same attacker will be back, sometimes with a skimmer instead of a miner.
Prevention That Actually Holds
The strongest control is a strict CSP with a connect-src directive. Mining needs a live connection to a pool, so a policy limiting WebSocket and fetch targets to your own domains and named APIs breaks most miners even if they’re injected. Our guide on how to implement Content Security Policy correctly covers rolling it out in report-only mode first.
Add file-integrity monitoring on the web root, lock down write permissions, and keep plugins and npm packages under version control with lockfiles. Daily automated malware detection and website security scanning catch injections that appear between deployments.
Some cases fall outside these rules. If you run a headless setup or a static site on Netlify or Cloudflare Pages, the attack surface shifts to your build pipeline and CI secrets, not the server. And if the cloud bill spikes while the frontend looks clean, check the server itself. Server-side cryptojacking with XMRig through an exposed Docker API or a weak SSH password is a separate problem that a browser-side scan won’t detect.
FAQ
Can an ad blocker or antivirus protect my visitors from cryptojacking scripts?
Partly. Extensions block known miner domains, but self-hosted and obfuscated miners routinely get past them. It’s on you as the site owner to keep the code clean, and you can’t count on visitors having a blocker installed.
Is cryptojacking a GDPR or legal issue for the site owner?
It can be. Running unauthorized code on visitors’ devices points to a compromise, and if the same access exposed personal data, breach-notification duties may apply. Treat it as a security incident, not a performance bug.
How fast does Google react to a site serving a miner?
Google Safe Browsing and several antivirus vendors flag miner domains, and a site can be marked within days. Getting a warning or blacklist removed usually takes a review cycle of 1-3 days after cleanup.
Summary
Cryptojacking scripts are still around. They’re just better hidden. Find them by combining signature searches across files and the database with runtime checks for idle CPU load and persistent WebSocket traffic, and always test as an anonymous visitor. Once you’ve found one, close the entry point, rotate credentials, and set a tight connect-src policy so the next injected miner has no pool to reach.
