DEV Community

Matt Aluya
Matt Aluya

Posted on

The bot that walked around Cloudflare

Saturday, 11:43 PM. My phone buzzed with an email from our hosting provider: the load on our server had become "quite high."
I opened my laptop expecting a slow plugin or a runaway cron job. Instead, one web address had been requested 58,887 times in a few hours. Almost every request claimed to be the same ordinary Chrome browser, from addresses all over the world.
We had Cloudflare. So how was this even reaching us?

Meet the bot

The bot was patient and a little clever. It came through Tor, so every few requests it wore a new face. Blocking one IP address did nothing, because the next request came from somewhere else.

It wasn't just noisy, either. Between floods, it tried to log in as people on our team, using their real names.

But it had a tell. It pretended to be Chrome, yet its browser signature was missing three words that every real Chrome includes. Think of a fake police uniform with the badge on the wrong side. That was the first lesson: a bot's address changes all the time, but its habits often don't.

The guard was at the wrong gate

If you live in Lagos, you know how estates work. A guard at the main gate checks every car that comes in. For us, that guard was Cloudflare.
Now imagine your house also has a back fence onto another street. If someone knows your house number, they don't need the gate. They walk straight to your door.
That's what happens when a bot learns your server's real IP address. It skips Cloudflare entirely. Many of us put a site "behind Cloudflare" and assume we're covered. The front gate is. The back fence isn't.

A sticker only the guard hands out

The fix is simple to explain: only open the door for visitors carrying a pass that only the guard can give out.

  1. Route all traffic through Cloudflare.
  2. Have Cloudflare attach a secret header to every request it forwards. That's the sticker on the windscreen.
  3. On the server, turn away anything without the sticker before the app even wakes up. In Cloudflare, that's a Transform Rule that sets a request header. On the server, it's two lines: if ($http_x_origin_auth != "your-long-random-secret") { return 403; }

A request that came through Cloudflare carries the sticker. A bot hitting the IP directly doesn't, and gets turned away at the door.

By the next morning, server load was back to normal. Our host wrote back to say it was low and stable.

What went wrong on the way

It wasn't a clean fix, and I'd rather you learn from our mistakes than repeat them.

The bouncer was standing behind the door. We already had a long list of "block bad bots" rules. But they sat after the line that hands every request to the app, so they never ran. Order matters.

There was a side door. A folder on the server had its own rules file, so some requests skipped our new checks completely. We only found it because we tested.

We locked ourselves out. The next morning, a security tweak sent our own admin dashboard into an endless redirect loop. One missing exception, five minutes of panic. Test in a private window before you walk away.

The honest limits

A secret only works while it stays secret. Rotate it, and don't paste it into chats or tickets.
It also only protects website traffic. Email, FTP, and hosting control panels need their own protection: strong passwords and two-factor authentication.
If your host allows it, there are stronger options: a firewall that only accepts Cloudflare's IP addresses, Authenticated Origin Pulls, or Cloudflare Tunnel.

A quick checklist

â€Ē Every web record proxied through Cloudflare (the orange cloud)
â€Ē A secret header set by Cloudflare and checked on the server
â€Ē Security rules placed before your app's rewrite rules
â€Ē Sub-folders checked for their own rules files
â€Ē 2FA on every admin login: site, hosting, Cloudflare, and email
â€Ē Changes tested from a private window and from outside Cloudflare

Only one way in

Monday morning, the logs are quiet, apart from the odd bot knocking on a locked door.
The guard was always good. We just had to make sure there was only one way in.
Founders: When did you last check your back fence?

Top comments (2)

ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: discretematt/the bot that walked around cloudflare d - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ”
 
x1y1co profile image
X1Y1 •

The fake Chrome tell matches what we saw from the other side. In a pricing page test last week, Walmart let our honest bot user agent straight through and challenged the same request when it claimed to be Chrome. Pretending to be a browser is louder than saying who you are.

ðŸ”Ĩ āļ‚āđˆāļēāļ§āļ”āđˆāļ§āļ™: discretematt/the bot that walked around cloudflare d - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ”
 
ali_tahir_7 profile image
ali tahir •

The origin secret closes the back fence, and your write-up makes that easy to follow. The login attempts are a separate problem, though. Once the bot learns the secret header doesn't exist for it, it can just as easily come through the front gate over Tor and keep guessing names. The secret header doesn't change anything there.

Since the traffic now has to pass through Cloudflare, you can use that:

  1. With IP geolocation turned on, Cloudflare labels Tor exits with the country code T1. A WAF rule on the login path only, along the lines of (ip.src.country eq "T1" and http.request.uri.path contains "login") → Managed Challenge, stops the rotation trick without affecting the rest of the site.
  2. If you also want the flag inside the app (to log it next to failed logins, or to protect the hosting panel and email, which you mentioned sit outside Cloudflare), an IP security lookup (IPGeolocation.io/ip-security-api.html) returns is_tor, is_proxy, is_vpn and is_known_attacker for an address, plus a threat_score. It's on paid plans, and there's a bulk endpoint if you want to run the 58,887 requests from your log through it afterwards and see what share was Tor and what share came from somewhere else.

Did the names it tried come from public pages, like an author archive or a team page? If the site runs WordPress, /?author=1 and /wp-json/wp/v2/users hand out usernames by default, and closing those two removes the list the bot was working from.