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 (0)