Documentation menu

Docs › Delivery

Signed URLs

Signed URLs let you share a link that works for a limited time, optionally only from one IP range or country. The edge validates the signature before serving anything.

How signing works

You sign the path, an expiry timestamp and any optional restrictions with an HMAC-SHA256 key that only you and Cache.bz know. The edge recomputes the signature on every request; if it does not match or the link has expired, the request is answered with 403 and never reaches your origin.

Turning it on

TOML
[[rules]]
match = "/downloads/*"
signed_urls = { key_id = "k2026", required = true }

Create a key in the dashboard or with cachebz keys create --type url-signing. Keep two keys active during rotation and reference the new one by its key_id.

Generating a URL

The string to sign is the path, the expiry and any restrictions joined by newlines. Here is a complete example in Python:

Python
import base64, hashlib, hmac, time

KEY_ID = "k2026"
SECRET = b"<your signing secret>"

def sign(path, ttl=3600, ip=None):
    exp = int(time.time()) + ttl
    msg = f"{path}\n{exp}\n{ip or ''}".encode()
    sig = hmac.new(SECRET, msg, hashlib.sha256).digest()
    token = base64.urlsafe_b64encode(sig).rstrip(b"=").decode()
    q = f"exp={exp}&kid={KEY_ID}&sig={token}"
    return f"{path}?{q}" + (f"&ip={ip}" if ip else "")

print(sign("/downloads/report-q3.pdf", ttl=900))
Output
/downloads/report-q3.pdf?exp=1796380000&kid=k2026&sig=Qm8z1yJ0f3nV2c...

Restrictions

ParameterDescription
expUnix timestamp after which the link is rejected. Required.
ipA single address or CIDR range, such as 203.0.113.0/24.
ccComma-separated ISO country codes allowed to use the link.
prefixSign a path prefix instead of one file, for HLS and DASH playlists and segments.

Caching signed content

The signature parameters are removed from the cache key automatically, so every visitor with a valid link shares the same cached object. Your origin receives the request without them.

Clock skew

The edge allows 30 seconds of clock skew. Generate expiry times from a server with a synchronised clock, not from the visitor's browser.

Was this page helpful? Tell us what was missing at support@cache.bz. Every message is read by the team that writes these docs.