Access Control and Signed URLs
What you'll learn: How to securely grant time-limited access to private media files without routing requests through application servers.
The Challenge
When hosting images and videos, you often need fine-grained control over who can access specific files. Simply making everything public doesn't work for user uploads, paid content, or private galleries. But routing every media request through your application servers to check permissions creates massive bottlenecks—your app becomes a proxy, wasting bandwidth and compute.
Signed URLs: Security Without Proxying
A signed URL is a temporary, cryptographically secured link that grants access to a specific resource. Instead of checking permissions on every request, you generate URLs that contain:
- Resource path (which file)
- Expiration timestamp (how long it's valid)
- Signature (cryptographic proof it's authentic)
The CDN or object storage validates the signature directly, never hitting your application servers for the actual file transfer.
How It Works
- User requests access to
photo123.jpg - Your application checks if they have permission
- If authorized, generate a signed URL:
cdn.example.com/photo123.jpg?expires=1700000000&signature=abc123xyz - Return this URL to the user
- User accesses the CDN directly; CDN validates signature and expiration
- If valid, CDN serves the file—your app servers never see the bandwidth
Think of it like a hotel key card: the front desk (your app) verifies your identity once and gives you a temporary key. You then access your room (the media file) directly without involving the front desk again.
Implementation Patterns
Generate signatures using HMAC with a secret key only your application and CDN know. Set reasonable expiration windows (minutes to hours) based on use case. For extra security, bind signatures to specific IP addresses or user agents.
Key Takeaway: Signed URLs combine security with performance by offloading authorization validation to the edge, letting CDNs serve private content without application-layer proxying.