
A paid file that sits at a plain URL is one forum post away from being a free file. Token authentication fixes that by making each download link carry a signature and an expiry time. The CDN, or your origin, accepts the link only while both check out.
What goes wrong with a plain download link?
Say a small studio sells a Windows installer for $29. The file is 1.2 GB and lives at https://cdn.studio.example/dl/setup.exe. Someone buys it, posts the URL, and 250 people download it from the CDN. The bandwidth is 250 x 1.2 GB = 300 GB. At the $0.060/GB entry rate on NetDNA's pricing page that's $18, which isn't the real loss. The real loss is 250 sales at $29, or $7,250 (250 x 29), that never happened.
NetDNA's EdgeSecurity add-on addresses this with time-limited links, authorised tokens and protection against hotlinking, and the developer center has a signed URL recipe that shows the idea in a few lines of PHP. This post explains why that recipe is built the way it is, and where a small change makes it tighter.
How does a signed URL work?
The server that sells the file creates a link containing an expiry time and a token. The token is a keyed hash of the path and the expiry, so changing either one invalidates it. Wikipedia's article on HMAC describes the building block: a hash-based message authentication code uses a cryptographic hash function and a secret key to verify both the integrity and the authenticity of a message, and it works with a shared secret, with no public-key infrastructure. Bellare, Canetti and Krawczyk published the construction in 1996 and wrote RFC 2104 in 1997.
The same article makes a point that surprises people: HMAC does not encrypt the message. The path and expiry travel in plain text in the URL, and that's fine, because nothing in them is secret. What can't be forged without the key is the match between the token and those values.
The recipe, in short:
$expires = time() + 600;
$token = hash_hmac('sha256', $path . '|' . $expires, $secret);
$url = "https://cdn.example.com{$path}?secure={$token}&expires={$expires}";
And the check, wherever the verification runs:
$expected = hash_hmac('sha256', $path . '|' . $expires, $secret);
$valid = hash_equals($expected, $token) && time() <= (int)$expires;
Two details differ from the bare recipe. The | separator closes an ambiguity: without it, path /dl/a with expiry 1750000000 and path /dl/a1 with expiry 750000000 build the same string, so a signature for one could validate the other. Real expiry values are the same length today, which hides the problem until someone changes the format. And hash_equals compares in constant time, so response timing doesn't leak how many characters matched.
How long should a link live?
Too short and paying customers fail; too long and the link spreads. The 1.2 GB installer shows the trade-off. At 20 Mbps, 1.2 GB (9,600 megabits) takes 9,600 / 20 = 480 seconds, or 8 minutes. The expiry is normally checked when the request starts, not when the transfer ends, so a 600-second link covers a click made up to 10 minutes after the page loads, even if the download then takes 8 minutes.
The catch is resumed downloads. A paused transfer that resumes after the expiry sends a new range request with the old link, and it fails. Issuing a fresh link from the customer's account page, rather than lengthening the lifetime to hours, keeps the window short and the support load low.
What should the token be bound to?
Binding to the file path and the expiry is enough for most cases. Binding to the visitor's IP address looks stricter, but mobile users switch networks mid-download and offices share one address among many people, so it blocks the buyers you want to keep. If you need per-buyer tracing, put an order ID in the signed string and log it.
The secret itself should live only on the server that signs links, never in JavaScript sent to the browser. To rotate it without breaking links in flight, accept two secrets for a few minutes: the new one and the old one.
Where token authentication stops
A signed link restricts when and where a file can be fetched, not what the buyer does with it afterwards. Someone who downloads a legitimate copy can still share the file itself. Token authentication stops the cheap, high-volume leak, a URL passed around forums and chat groups, and that's usually the one that costs the most.
A quick audit shows whether it works: request a signed link, change one character of the token, and confirm the edge answers 403. Then wait past the expiry and confirm the original link answers 403 as well.
Related: glossary: signed URLs, VOD zones for paid video, API authentication.
Blog