CDN Hotlink Protection: Preventing Bandwidth Theft

· Alex Petrov · 4 min read

What Is Hotlinking

Hotlinking occurs when another website embeds your content (images, videos, files) directly using your URLs. Their visitors consume your CDN bandwidth while their site gets the benefit of displaying your content. For foundational context, read CDN DDoS Protection: How CDNs Absorb Volumetric Attacks — FlyFish NWA.

<!-- On someone-else.com -->
<img src="https://your-cdn.com/photos/product.jpg">
<!-- You pay for every view on their site -->

Impact

Protection Methods

Referer Header Checking

The simplest method: check the HTTP Referer header and block requests from unauthorized domains.

Performance Comparison: Edge vs Origin Processing
Metric Edge Processing Origin Processing Improvement
Latency (p50)8–15 ms120–300 ms15–20x faster
Cache Hit Ratio85–95%N/AReduces origin load
TLS Handshake1–5 ms (nearby PoP)50–150 ms10–30x faster
Bandwidth Cost$0.01–0.04/GB$0.05–0.12/GB3–5x cheaper
Availability99.99% (multi-PoP)99.9% (single DC)10x fewer outages
CDN Security Architecture — Defense-in-depth protection layersCDN Security Architecture — Defense-in-depth protection layers CDN Security Layers — Defense in Depth DDoS Mitigation Web Application Firewall Bot Detection & Rate Limiting SSL/TLS Encryption Origin Server DDoS ✕ Attack ✕ SQLi ✕ PROTECTED
Figure 1: CDN Security Architecture — Defense-in-depth protection layers
# Nginx configuration
valid_referers none blocked server_names
  *.yourdomain.com
  yourdomain.com;

if ($invalid_referer) {
  return 403;
}

CDN configuration equivalent — allowlist your domains, block everything else.

Limitations: Referer can be spoofed. Some browsers and privacy tools strip the Referer header (requests without a Referer should be allowed, as they may be direct visits).

Signed URLs

Use signed URLs with short expiry times. Hotlinked URLs expire quickly, while your application generates fresh signed URLs for legitimate users.

CDN-Level Hotlink Protection

Granular Protection

Not all content needs hotlink protection. Apply it selectively:

Secure Request Flow — How requests pass through security layersSecure Request Flow — How requests pass through security layers CDN Request Flow — From Browser to Edge CDN Request Lifecycle Step 1 DNS Lookup Step 2 TCP Connect Step 3 TLS Handshake Step 4 Edge Server Step 5 Cache Check Step 6 Response Cache HIT → 5ms response Cache MISS → Fetch origin 0ms ~50ms (cache hit) ~200ms (cache miss)
Figure 2: Secure Request Flow — How requests pass through security layers
ContentProtect?Reasoning
Product imagesYesExpensive to serve, frequently hotlinked
CSS/JS assetsNoSmall files, rarely hotlinked
VideosYes (signed URLs)Very expensive to serve at scale
Logos/iconsMaybeSmall files, but may want to control usage
Downloadable filesYesLarge files, direct cost per download

Replacement Image Strategy

Instead of returning a 403 error, some sites serve a replacement image for hotlinked requests — a small image saying "Image hosted by [your-domain]" or a watermarked version. This deters hotlinking while potentially driving traffic to your site.

Allowlist Configuration

When configuring hotlink protection, allowlist:

Monitoring Hotlinking

Check your CDN analytics for: requests with unfamiliar Referer domains, unexplained bandwidth spikes on specific assets, popular files that shouldn't be popular. Use CDN monitoring to set up alerts for unusual referral patterns.

External References

References & Standards: Cloudflare documentation · HTTP/2 specification