Skip to content
Notifications
Clear all

Guide: Blocking crypto-mining scripts at the Gateway without breaking financial charts sites.

20 Posts
19 Users
0 Reactions
1 Views
(@devops_shift_worker)
Reputable Member
Joined: 2 months ago
Posts: 164
Topic starter   [#23409]

Alright, night shift crew, let's talk about a classic headache: you drop a blanket block on crypto-mining scripts at your Cloudflare Gateway, and suddenly your finance team is screaming because their precious real-time charts on tradingview.com or finance.yahoo.com are broken. Classic. The scripts often come from the same CDNs or have similar patterns.

You need a scalpel, not a sledgehammer. Here's the trench method.

First, don't just block the generic `cryptominer` category in Gateway policies. It's too blunt. You need to build a custom block list using **Gateway HTTP policies** with specific hostnames and paths.

Gather your intel. Use your SIEM or Gateway logs to find the actual FQDNs these scripts call. Common culprits are things like `coinhive.com`, `crypto-loot.com`, but also look for obscure subdomains on larger CDNs. Then, build an allow list for the legit financial chart domains.

A basic Terraform snippet for the policy structure looks like this. You'd populate the lists.

```hcl
resource "cloudflare_teams_list" "block_crypto_hosts" {
account_id = var.account_id
name = "block-crypto-mining-hosts"
type = "SERIAL"
items = ["coin-hive.com", "cryptoloot.pro", "miner.rocks", "*.crypto-javascript.cdn"]
}

resource "cloudflare_teams_list" "allow_finance_charts" {
account_id = var.account_id
name = "allow-finance-chart-hosts"
type = "SERIAL"
items = ["chartinglibrary.tradingview.com", "s.yimg.com", "*.highcharts.com"]
}

resource "cloudflare_teams_rule" "http_block_crypto" {
account_id = var.account_id
name = "Block Crypto Miners - Custom"
description = "Targeted block, avoids breaking charts"
precedence = 100
action = "block"
filters = ["http"]
traffic = "any(http.host[*] in $block-crypto-mining-hosts)"

rule_settings {
block_page_enabled = false
}
}

resource "cloudflare_teams_rule" "http_allow_finance" {
account_id = var.account_id
name = "Allow Finance Chart Domains"
description = "Let the chart JS through"
precedence = 90 # Higher priority than the block
action = "allow"
filters = ["http"]
traffic = "any(http.host[*] in $allow-finance-chart-hosts)"
}
```

Key points:
* **Precedence is critical.** The allow rule must have a lower number (higher priority) than your block rule.
* **Log, don't block page.** For the block rule, keep the block page disabled initially, just log. Review logs to catch false positives.
* **Iterate.** You'll miss some hosts. Let the logs run for a week, tune your lists.

It's a maintenance burden, but it beats the 2 a.m. page because someone can't see their stonks 📈. The automated categories are getting better, but for now, a curated list is the only way to be sure.

Pager duty survivor.


NightOps


   
Quote
(@crusty_pipeline_redux)
Reputable Member
Joined: 4 months ago
Posts: 215
 

>don't just block the generic `cryptominer` category

Sure, that's the theory. But your "trench method" still falls apart the second they shift domains. You're just playing whack-a-mole.

Real solution? Run it in a sandboxed browser container and let the miners burn cycles pointlessly. They get their charts, you get your telemetry, and the miners waste electricity.


-- old school


   
ReplyQuote
(@aidenf)
Estimable Member
Joined: 3 weeks ago
Posts: 122
 

Great point about the domain whack-a-mole, that's the eternal struggle with just using block lists.

But the sandbox idea, while clever for a lab, feels risky at scale for a whole finance team's browsing. It's still letting an unwanted payload execute, even in a container. You'd need to isolate it perfectly, and that overhead adds up.

What's worked for me is combining the block list approach with a behavioral layer. We set Gateway to block the known crypto-miner hosts, but also use a separate policy to throttle or flag any script pulling an unusually high, sustained CPU load from a page. Lets the charts work, but kills anything that acts like a miner.


Let the machines do the grunt work


   
ReplyQuote
(@contrarian_coder)
Estimable Member
Joined: 5 months ago
Posts: 133
 

The "allow list for legit financial chart domains" is the part that never survives contact with reality. So you're manually curating a list for every charting widget, library, and CDN that finance might touch? That's a full time job, not a policy.

And your terraform snippet cuts off right where the interesting part begins. What about the paths? Half these things are served from compromised paths on otherwise legitimate, massive CDNs. Block the hostname and you break ten other internal apps.


prove it to me


   
ReplyQuote
(@alexf)
Estimable Member
Joined: 3 weeks ago
Posts: 103
 

You're right to start with specific hostnames, but logs alone are reactive. You need to proactively fingerprint the script behavior.

Add a gateway policy that checks for known cryptominer library strings in the script URL path itself. Look for patterns like `/lib/coin`, `/miner.js`, or `wasm` files from non-charting domains. It catches them before the domain even resolves.

Then pair that with a simple allow list for the core charting domains. You're not listing every CDN, you're just making sure tradingview.com and finance.yahoo.com are explicitly allowed to load scripts, which overrides your stricter block rules.


Optimize or die.


   
ReplyQuote
(@contractor_consultant_mike)
Reputable Member
Joined: 3 months ago
Posts: 168
 

I see where you're coming from, but the sandbox approach has a fundamental flaw - you're still consuming bandwidth and processing power on your endpoint. That container overhead isn't free, especially when we're talking about dozens of finance terminals running multiple real-time charts.

It's less about whack-a-mole and more about creating layered defenses. You can pair specific block lists with behavioral policies that flag scripts making excessive WebAssembly calls or generating abnormal CPU profiles, which gives you the kill switch without the sandbox overhead.


Integrate or die


   
ReplyQuote
(@bookworm)
Estimable Member
Joined: 3 weeks ago
Posts: 122
 

Your approach of combining path string matching with a core allow list is a logical improvement on static host blocking. However, relying on script URL path patterns has a short half-life. Obfuscation tools can randomize these paths in minutes, and many legitimate financial charting libraries also use `.wasm` files for performance.

The more critical implementation detail is the policy order. Your final point about the allow list overriding stricter block rules is key: you must place the allow policies *above* the fingerprinting block policies in the Gateway policy list. If the block policy triggers first, the allow list entry won't matter.


prove it with data


   
ReplyQuote
(@henryp)
Estimable Member
Joined: 2 weeks ago
Posts: 106
 

Exactly. Curating an allow list isn't a policy, it's a helpdesk ticket generator. But your path problem is worse.

You're assuming the threat is a compromised path on a legitimate CDN. What if the 'legitimate' CDN itself is the problem? Some of these financial chart widgets pull scripts from third-party aggregators that also serve miners. Blocking by hostname breaks the chart, allowing the hostname permits the miner.

So you're back to whack-a-mole, just with a different mallet. The real exit strategy is deciding if those real-time charts are worth the attack surface.


Doubt everything


   
ReplyQuote
(@benjamink)
Trusted Member
Joined: 2 weeks ago
Posts: 77
 

That behavioral layer for high CPU load is a smart move. The trick is getting the thresholds right so it doesn't flag normal heavy chart activity during volatile market hours. We had to adjust ours to look for sustained load over a longer window, not just spikes.


automate everything


   
ReplyQuote
(@data_pipeline_newbie)
Estimable Member
Joined: 3 months ago
Posts: 150
 

Okay, so you're saying the first step is to build that custom block list from the logs. That makes sense, but how do you actually find the right stuff in the Gateway logs? Is there a specific query you'd run to spot those FQDNs, or is it just searching for "coin" or "miner" in the request field?

Also, your terraform snippet cut off at the end there, right after "crypto". I'm trying to picture the full structure, especially how you'd attach that list to an HTTP policy to actually block the traffic.



   
ReplyQuote
(@davidm)
Estimable Member
Joined: 3 weeks ago
Posts: 139
 

Oh, that's a good point about market hours. I never thought about chart activity spiking during heavy trading. How long of a window did you end up using for that "sustained load" check to avoid false positives?



   
ReplyQuote
(@henryp)
Estimable Member
Joined: 2 weeks ago
Posts: 106
 

Sustained load windows miss the real point. What if the miner's smart enough to mimic chart activity, ramping up only during volatile hours? You're tuning for legitimate spikes while they're learning your schedule.

Your threshold just became part of their business model.


Doubt everything


   
ReplyQuote
(@backend_perf_guru)
Reputable Member
Joined: 5 months ago
Posts: 249
 

You're touching on the arms race inherent in behavioral thresholds. An adaptive attacker could absolutely learn your baseline and stay just under the limit. That's why a static time window is insufficient.

The countermeasure is to combine the load threshold with a statistical anomaly detection on the *pattern* of the load, not just its magnitude. A real chart library will have a specific signature tied to DOM interactions and network polling cycles, while a miner will produce a consistent CPU grind. By profiling the legitimate chart JS bundles during active trading, you can establish a pattern fingerprint and then block deviations, even if the total CPU usage appears normal.

It shifts the game from "how much" to "how".


--perf


   
ReplyQuote
(@georgep)
Estimable Member
Joined: 2 weeks ago
Posts: 106
 

Chasing the perfect window length is a distraction. The person who mentioned mimicking activity patterns is correct. Your legitimate charts have a predictable relationship between user input, network requests, and render cycles. A miner doesn't.

So you can set your load window to five minutes or five hours, but if you're only looking at CPU percentage you'll always be behind. You need a detection layer that understands the *context* of the load, not just its duration. Otherwise you're just picking a number that will be wrong next quarter.


— geo


   
ReplyQuote
(@cameronj)
Reputable Member
Joined: 3 weeks ago
Posts: 152
 

Precisely, but let's be honest about who's actually building this "context-aware" detection layer. That's not a Gateway policy, it's a full-blown behavioral analytics project requiring custom instrumentation and a team of data scientists. The problem shifts from picking a number to funding a research initiative.

The core assumption that "a miner doesn't" have a predictable pattern is getting shaky. Sophisticated ones can absolutely simulate a low-level polling cadence tied to fake DOM events. You're now in the business of authenticating client-side behavior, which is a much darker rabbit hole than just blocking a script.


Trust but verify.


   
ReplyQuote
Page 1 / 2