CDN Token Authentication: Securing Content Access

· Mei-Lin Wu · 4 min read

Why Token Authentication

Not all content should be publicly accessible. Premium videos, paid downloads, internal documents — these need access control. Token authentication lets the CDN verify that each request is authorized before serving content, without requiring every request to hit the origin. For foundational context, read CDN DDoS Protection: How CDNs Absorb Volumetric Attacks — FlyFish NWA.

Signed URLs

The origin generates a URL containing a cryptographic signature. The CDN verifies the signature before serving the content. If the signature is invalid or expired, the request is rejected at the edge.

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
# Generate signed URL (application server)
base_url = "https://cdn.example.com/premium/video.mp4"
expiry = int(time.time()) + 3600  # 1 hour
token = hmac_sha256(secret_key, f"{base_url}|{expiry}")
signed_url = f"{base_url}?expires={expiry}&token={token}"

# CDN validates:
# 1. Token matches HMAC of URL + expiry using shared secret
# 2. Current time < expiry
# 3. If both pass → serve content

Signed URL Parameters

ParameterPurposeExample
Expiry timeURL becomes invalid after this time3600 seconds from now
Client IPLock URL to specific IPPrevent URL sharing
Path prefixAllow access to a directory, not just one file/premium/season1/*
Country restrictionGeo-restrict accessUS, CA, UK only

JWT Validation at the Edge

For API-style access control, the CDN validates JSON Web Tokens at the edge:

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
# Request with JWT
GET /api/data HTTP/1.1
Authorization: Bearer eyJhbGciOiJSUzI1NiIs...

# CDN validates:
# 1. Signature valid (using public key)
# 2. Token not expired (exp claim)
# 3. Issuer matches (iss claim)
# 4. Required claims present
# → Forward to origin with validated claims in headers

JWT validation at the edge means unauthenticated requests never reach origin. The CDN can also extract claims and pass them as headers, so origin receives pre-validated identity information.

CDN Implementation

Signed Cookies vs Signed URLs

MethodBest ForLimitation
Signed URLsIndividual files (video, download)URL changes for each user/session
Signed cookiesAccess to multiple URLs (entire section)Requires cookie support in client

Token Security Best Practices

Token Authentication and Caching

Token-authenticated content can still be cached at the CDN. The key is separating the authentication check (per-request) from the content delivery (from cache). The CDN validates the token, then serves the content from cache if available. See cache key design — the token itself should NOT be part of the cache key.

External References

References & Standards: Cloudflare documentation · W3C Web Performance