Skip to main content
Token authentication protects content with time-limited signed URLs. Each URL carries an MD5-based token plus an expiry timestamp; the CDN edge validates both before serving the file. Links expire on schedule and cannot be tampered with — the secret never leaves your server. Use it for HLS / DASH streams, private downloads, embedded video players, and any media you want gated behind your application’s auth.

Request flow

The secret stays on your server. Clients only ever see the finished signed URL.

Enable token authentication

Token Authentication

Token Authentication

  1. Open CDNDistributions → select your distribution.
  2. Go to Access RulesAdd Access Rules (or open an existing rule).
  3. Set the Match Pattern to the path you want to protect (for example /videos/*).
  4. Toggle Token Authentication on.
  5. Click Generate Token to mint a Secret Token, then Copy Token.
  6. Click Create Access Rules to save.
Token authentication is configured per access rule, not globally. Each rule has its own secret, so you can scope tokens to a path prefix and rotate them independently.
Treat the secret like a database password. Store it in your secret manager (AWS Secrets Manager, GCP Secret Manager, Vault, Doppler, etc.), inject it via environment variable, and never commit it to a repo or expose it in client-side code.

URL anatomy

Signing algorithm

  1. Build the string {expires}{path} {secret} — note the single space before the secret.
  2. MD5 hash with raw binary output (16 bytes), not hex.
  3. Base64-encode the binary hash.
  4. Make the base64 URL-safe: replace +-, /_, strip = padding.
  5. Append ?md5={token}&expires={unix_timestamp} to the CDN URL.

Configuration

Drive everything from environment variables — never hard-code the secret.
.env

Generate signed URLs

Reference implementations live in the tenbyte-cdn-signed-url-example repo. Pick a language, copy the function, swap your config.

Verify with curl

Mint a URL, hit the edge, expect 200:
Negative tests — both should return 403:

Use the URL in a player

The signed URL is a normal HTTPS URL — drop it into any player. For HLS streams, sign the manifest only; segments inherit the rule as long as the Match Pattern covers them.

Operations

Choosing a TTL

Set TTL ≥ longest possible playback session. If a viewer pauses past the expiry, the next segment fetch returns 403 and the player stalls.

Clock skew

expires is compared against the edge’s wall clock. Servers signing URLs should run NTP. If your sign host drifts ahead, the edge sees a token that is “already expired”; if it drifts behind, tokens live longer than expected. A skew of ±60 seconds is usually invisible — anything more is a config issue.

Rotating the secret

The console only stores one active secret per access rule. Rotation is a hard cutover, so do it at low traffic and keep a short overlap by issuing short-TTL tokens leading up to the swap.

Multiple environments

Use one access rule per environment with its own secret and a path prefix that namespaces traffic — for example /prod/* and /staging/*. That way a leaked staging secret cannot sign production URLs.

Logging and observability

  • Log the path you signed and expires value, never the secret or the full signed URL — query strings often end up in access logs.
  • Track edge 403 rate per access rule. A spike usually means clock skew, expired tokens, or a bug in your signer.
  • For incident triage, keep the signing function pure (input in, URL out) so you can replay it offline against suspect timestamps.

Security checklist

  • Secret stored in a secret manager, injected via env var.
  • Signing happens only on the server. No browser code, no mobile-client embedded secrets.
  • Per-environment access rules with distinct secrets.
  • TTL is the shortest value your workload tolerates.
  • Rotation runbook documented and tested.
  • Application auth gates the signer endpoint — never let an unauthenticated request mint a URL.
  • Combine with Referrer, IP, or Country policies for defense in depth.

Troubleshooting