CDN Origin Protection: Shielding Your Server
Why Origin Protection Matters
Your CDN provides DDoS protection, WAF, and rate limiting — but only for traffic that goes through the CDN. If an attacker discovers your origin IP, they can bypass all CDN protections by connecting directly to your server.
How Origin IPs Get Exposed
- DNS history — Your domain's DNS records before CDN setup may still be in public databases (SecurityTrails, ViewDNS)
- Email headers — Outgoing email from your server reveals the server's IP in headers
- Subdomains —
api.example.com,mail.example.com, ordev.example.commay point directly to origin - Certificate transparency — CT logs show which IPs have served certificates for your domain
- Server-side requests — Webhooks, API callbacks from your server reveal its IP to the receiving party
IP-Based Protection
Configure your origin firewall to only accept connections from CDN IP ranges:
| Metric | Edge Processing | Origin Processing | Improvement |
|---|---|---|---|
| Latency (p50) | 8–15 ms | 120–300 ms | 15–20x faster |
| Cache Hit Ratio | 85–95% | N/A | Reduces origin load |
| TLS Handshake | 1–5 ms (nearby PoP) | 50–150 ms | 10–30x faster |
| Bandwidth Cost | $0.01–0.04/GB | $0.05–0.12/GB | 3–5x cheaper |
| Availability | 99.99% (multi-PoP) | 99.9% (single DC) | 10x fewer outages |
# iptables example for Cloudflare IPs
for ip in $(curl -s https://www.cloudflare.com/ips-v4); do
iptables -A INPUT -p tcp -s $ip --dport 443 -j ACCEPT
done
iptables -A INPUT -p tcp --dport 443 -j DROP
Major CDNs publish their IP ranges. CloudFront, Cloudflare, Fastly, and Akamai all provide IP lists that you can use in firewall rules.
Header-Based Authentication
Add a shared secret header that the CDN sends with every origin request. Your origin rejects requests without the correct header:
# CDN sends:
X-Origin-Auth: s3cr3t-t0k3n-value
# Origin nginx:
if ($http_x_origin_auth != "s3cr3t-t0k3n-value") {
return 403;
}
This works even if the attacker knows your origin IP — without the secret header, the request is rejected.
Origin Certificate Authentication
Use mutual TLS (mTLS) between CDN and origin. The CDN presents a client certificate; the origin verifies it. Without the correct certificate, the TLS handshake fails. This is the strongest origin authentication method.
Cloudflare-Specific Protection
- Authenticated Origin Pulls — CDN presents a Cloudflare client certificate; origin verifies it
- Cloudflare Tunnel — Origin connects outbound to Cloudflare; no inbound ports open at all. The origin has no public IP.
- Origin certificates — Certificates trusted only by Cloudflare, ensuring edge-to-origin encryption
Additional Measures
- Separate outgoing IP — Use a different IP for outgoing traffic (email, webhooks) than your web server
- Proxy subdomains — Put all subdomains behind the CDN, not just the main domain
- Remove DNS history — Change your origin IP after setting up the CDN to invalidate historical DNS records
- Monitor exposure — Regularly check if your origin IP appears in CT logs, Shodan, or DNS history databases
Testing Origin Protection
Verify your origin is properly protected:
- Try connecting to your origin IP directly — should fail or return a generic response
- Search your domain on Shodan, Censys, SecurityTrails — verify origin IP is not exposed
- Check all subdomains resolve through CDN, not directly
- Send a test request without the auth header — should be rejected