Putting your site behind Cloudflare feels like locking the front door. Most people never notice the back door is still wide open.
I found this on my own blog during a hardening pass. Everything went through Cloudflare. The WAF was on, the caching was on, the dashboard looked great. And the origin server still answered any request sent straight to its IP address, no Cloudflare involved.
That means every protection I thought I had was optional. Optional for the attacker, that is.
How Attackers Find Your Origin
Cloudflare hides your server’s IP in DNS. It does not hide it everywhere else. The common leaks:
- Historical DNS. If the domain ever pointed directly at the server before you turned on the proxy, that record lives forever in DNS history databases.
- Internet-wide scanners. Services constantly scan every IPv4 address and record which certificates and page titles each one serves. If your origin presents a certificate for your domain, it is searchable.
- Unproxied subdomains. A mail record, an old staging host, a “direct” subdomain someone added for debugging. Same server, no orange cloud.
- Outbound requests. Webhooks, pingbacks, and emails sent from the server reveal where they came from.
Once someone has the IP, they skip your WAF, your rate limits, your bot protection, and your DDoS shield. They talk to your web server directly, with a Host header that says your domain.
The Fix: Only Talk to Cloudflare
The fix is a firewall rule that accepts web traffic only from Cloudflare’s published IP ranges. Everything else gets dropped. Cloudflare publishes the lists at cloudflare.com/ips-v4 and cloudflare.com/ips-v6.
On Ubuntu with ufw, the core of it looks like this:
# Keep SSH open FIRST, or you will lock yourself out
ufw allow 22/tcp
ufw default deny incoming
ufw default allow outgoing
for ip in $(curl -s https://www.cloudflare.com/ips-v4)
$(curl -s https://www.cloudflare.com/ips-v6); do
ufw allow proto tcp from "$ip" to any port 80,443 comment 'cloudflare'
done
ufw enableCode language: PHP (php)
Read that first line twice. If you enable a deny-by-default firewall over SSH without allowing SSH, you will spend the next hour in your provider’s web console. Better still, restrict SSH to your own address or put it behind a VPN or tunnel, but never remove it before you have a way back in.
Then test from somewhere outside Cloudflare:
curl -sk --max-time 5 https://YOUR_ORIGIN_IP -H "Host: example.com"Code language: JavaScript (javascript)
It should time out. If it returns your homepage, the back door is still open.
One trap worth knowing: if you run your app in Docker with published ports, Docker writes its own iptables rules and can bypass ufw entirely. Bind containers to localhost and let a reverse proxy on the host face the internet.
The Two Things People Forget
The ranges change. Not often, but they do. If Cloudflare adds a range and your firewall doesn’t know about it, some visitors get timeouts and you will have no idea why. Put the update in a small script that rebuilds the Cloudflare rules from the published lists, and run it on a schedule. Weekly is plenty. Have it fail loudly if the download comes back empty, so a network hiccup never wipes your allow list.
Certificates still need to renew. People worry that locking the origin breaks Let’s Encrypt. With the HTTP challenge it usually doesn’t, because the validation request goes to your domain, your domain resolves to Cloudflare, and Cloudflare forwards it to you through the allowed ranges. Just make sure the challenge path isn’t cached or redirected in a way that breaks it. If you’d rather avoid the question entirely, use a DNS challenge or a Cloudflare origin certificate.
Check Yours Today
This is a ten-minute check and a thirty-minute fix. I only went looking because a fishing bug bounty email made me audit the whole setup, and the origin leak was a bigger problem than anything in that email.
A CDN in front of an open server is a suggestion, not a defense.
When did you last try to reach your own origin directly?
If this resonated with you, I would love to hear your perspective. Drop me a message or connect with me on Twitter (X) or LinkedIn. I write regularly about the intersection of AI, software engineering, and leadership at ivanturkovic.com.

Leave a Reply
You must be logged in to post a comment.