Loading...

CDN.com.tr Help

Signed URLs: links that expire

Protect a file so it can only be fetched with a signature you generate, valid until a moment you choose. Unsigned requests get 403, expired ones get 410.

Signed URLs: links that expire

Protect a file so it can only be fetched with a signature you generate, valid until a moment you choose. Unsigned requests get 403, expired ones get 410.

Recommended next guide

Panel path

  1. Management Panel
  2. Delivery Rules
  3. Expiring links
  4. Secret

Prerequisites

  • An account with a delivery hostname
  • A place in your application to generate links

Decision model

Account-wide or one path?

The setting exists at both levels. Account-wide means every request needs a signature, which breaks ordinary pages. One rule for /downloads or /video is what most people want.

  • Account-wide: only for accounts that serve nothing but protected files
  • Per rule: the normal choice

How long should a link live?

Short enough that a leaked link is worthless, long enough that a slow connection can finish the download. Minutes for a document, hours for a large video.

  • Documents and images: 5-15 minutes
  • Large video or archives: 1-6 hours

Step-by-step guide

1

Turn it on for one path

Open Delivery Rules, add or edit the rule covering the path you want protected, enable the expiring-link option and set a secret. Use a long random string, not a word.

  • Delivery Rules → the rule for /downloads → enable expiring links → paste a random secret → Apply Changes

Expected result: After the configuration reaches the edges, a plain request to that path returns 403.

2

Generate a link in your application

The signature is the base64url form of the MD5 of the expiry, the path and the secret joined together, with a single space before the secret. Append it as md5 and the expiry as expires.

  • PHP: $expires = time() + 600; $token = rtrim(strtr(base64_encode(md5($expires . $uri . " " . $secret, true)), "+/", "-_"), "=");
  • Then: https://cdn.example.com/downloads/file.zip?md5=TOKEN&expires=EXPIRES

Expected result: The link is served until the expiry passes.

3

Verify all three outcomes

Check the failure cases as well as the success one, because they are what your support team will see in reports.

  • Fetch without parameters (403)
  • Fetch with a past expiry (410)
  • Fetch a valid link (200)

Expected result: Three different responses, so a user report can be classified from the status code alone.

Verification

  • curl -o /dev/null -w "%{http_code}" "https://cdn.example.com/downloads/file.zip" → 403
  • curl -o /dev/null -w "%{http_code}" "https://cdn.example.com/downloads/file.zip?md5=TOKEN&expires=PAST" → 410

Use cases

You sell a video, a report or a download and the link must not be shareable forever. Hotlink protection stops other sites embedding your files; a signed URL goes further and makes every link personal and time-limited.

Quick workflow

  1. Delivery rules → pick the account (or a single rule for one path) → turn on the expiring-link setting and set a secret.
  2. Your application builds the link: it hashes the expiry time, the path and the secret, then appends the signature and the expiry to the URL.
  3. The edge checks the signature before anything else. Valid links are served and cached normally; invalid ones never reach your origin.
  4. Rotate the secret when it leaks or when someone leaves. Every link signed with the old secret stops working immediately.

Checks

  • A link without the parameters returns 403.
  • A link whose expiry has passed returns 410 — a distinct code, so your own logs tell the two cases apart.
  • A link with a correct signature is served, and the response is cached like any other.