X-Vtoken — request signing against hotlinking
The token can be sent in the ?x-token= query string as well as in the X-Vtoken header (for HLS players that cannot set headers). A token with a valid signature that has expired receives 410 Gone; a missing or invalid token receives 403.
X-Vtoken signs each request with HMAC-SHA-256 through the X-Vtoken header or the ?x-token= query string. When it is turned on for a domain, every request must carry a token that the client signs with a secret issued specifically for that domain. The edge verifies the signature very early — before Bot Management, Rate Limit and the WAF. Result: a missing or invalid token → 403; a valid but expired token → 410 Gone (see Troubleshooting).
Use it to prevent hotlinking/leeching (stop other websites from embedding your images or videos), to prevent public sharing of URLs, and to prevent replay (the token has a nonce and a time window). Example: another site embeds your videos/images directly and uses up your bandwidth — turn on X-Vtoken so only your app or website (with the token-signing SDK built in) can load them.
Unlike Token V2 (which signs the URL and suits HLS/signed URLs — see its own article), X-Vtoken signs each request (passed in the X-Vtoken header or the ?x-token= query), has a key_id for real key rotation, and protects against replay.
Secret security — required reading. The vts_… secret is a server-side secret key. Keep it only on your website's backend and generate and sign X-Vtoken on the backend. Never embed the secret or sign tokens in the frontend (browser JavaScript, HTML, public web pages, SPA apps). Anyone can view browser-side source code and environment variables → the secret is exposed, attackers can sign valid tokens themselves, and hotlink protection is completely defeated.
- Web (browser): the backend signs
X-Vtokenin advance (or issues a short-lived token) and returns it to the page to request resources; the secret never leaves the server. - Mobile/native apps: still get the token from the backend; avoid hardcoding the secret in the app (it can easily be reverse engineered). If you must sign on the device, use a separate
key_id+ a short TTL + frequent key rotation, and accept the higher risk. - Store the secret in a secret manager / encrypted on the backend; do not commit it to git, do not write it to logs, and do not expose it in URLs or query strings.
Turning on (Enforce) X-Vtoken purges the domain's entire cache so that cached content is not served to requests without a token — plan for the cache to be refilled. Turning Enforce off does not purge the cache.
Before you start
- The domain has been added and points to VNIS.
- You must create at least 1 key before turning it on — if you turn it on without a usable key, saving returns 409.
- Your website's or app's backend must sign tokens with the secret (the
vts_…string) that you create in the keys step — sign on the server, not in the frontend (see the secret security note above). Without a valid token, even you receive 403.
How to configure
- Go to Domains → select a domain → vtoken tab (X-Vtoken request signing).

- Create a key first: click Create key.
key_idis optional — give it your own name (for exampleprod-v2) or leave it empty to have the system generate one (for examplek1a2b3c4d); optionally add alabelandexpires_at. - Save the
vts_…secret immediately when it appears — it is shown only once. Hand it to your backend team for integration (see the note above — do not put the secret in the frontend). - Turn on Enforce X-Vtoken on this domain (Enabled). Optionally set Token lifetime, Bind to client IP, Whitelisted IPs and Exempt paths.
- Click Save. Wait a few seconds for it to sync (and for the cache to be purged).
Signing tokens — full specification and key rules
The full signing specification is in the portal: open the "X-Vtoken Signing → How to sign requests" tab to see the token structure, the HMAC-SHA256 algorithm, sample Python code and a sample token for comparison. This page is only a summary — sign tokens exactly according to the specification in that tab (do not rely only on the "embed the SDK" description).
- Only the path part of the URL is signed — the query string is not part of the signature. A token signed for
/img/a.jpgalso works for/img/a.jpg?x=123(200), but not for/img/b.jpg(403). (The?x-token=parameter is a special case: it is removed from the URL before path/cache matching, so it does not break the signature — see "Passing the token in the query string".) - Clock skew: a token with a timestamp in the future is accepted up to +120 seconds (or up to the ttl if the ttl is < 120s); beyond that it is treated as expired →
410 Gone. A token past its lifetime → also410 Gone.
Two signing modes: exact-path and prefix (important for HLS/video)
X-Vtoken has 2 modes, chosen by the token at signing time (not by server configuration):
1) Exact-path (default — signs exactly 1 path): the token signs one exact request path and can be used only once (replay protection with a nonce). Sending the same token again → 403 replay. Consequence for HLS with exact-path: each segment/manifest needs a new token signed for its exact path — if you use 1 fixed token for every segment, the first segment returns 200 and the following segments return 403. ⇒ Not recommended for HLS.
2) Prefix mode (recommended for HLS/video): the token signs a path prefix ending in / (the directory containing the manifest). A single token is then valid for the manifest and every segment under the prefix; the token can be used many times and is exempt from replay protection (which matches how a player requests the manifest + many segments + ranges + retries with the same token). Paths outside the prefix → 403.
How to use it for HLS: the backend signs one prefix token for the whole viewing session — prefix = the manifest's directory (for example /vod/course-1/, must end in /), with a ttl long enough for the video duration plus a buffer — and the player attaches the same token in the X-Vtoken header to every request. Example with hls.js:
// token issued by the BACKEND (prefix-signed). Do not sign in the browser (see the note above).
const hls = new Hls({
xhrSetup: (xhr) => xhr.setRequestHeader('X-Vtoken', token), // hls.js < 1.5
fetchSetup: (ctx, init) => { init.headers = { ...init.headers, 'X-Vtoken': token }; return new Request(ctx.url, init); }, // hls.js >= 1.5
});
hls.loadSource('https://example.com/vod/course-1/manifest.m3u8');
→ this header is sent with both the manifest and every segment → all are verified with the same token.
- Native players (AVPlayer on iOS / ExoPlayer on Android) often cannot easily add a header to each segment → use the
?x-token=query string (section below) or Token V2 (signed URL, signed on the URL — see its own article). Bind to client IP: if on, the prefix token must embed the viewer's real IP, and the IP must stay stable for the whole session (switching between 4G and Wi-Fi, or CGNAT → segment 403). For HLS, you should usually turn off bind_client_ip.
Passing the token in the query string ?x-token= (for players that cannot set headers)
In addition to the X-Vtoken header, the edge also accepts the same token in the ?x-token=<token> query. The value is identical to the header token (base64url-nopad); only the transport differs — convenient for HLS on native players and <video> tags that cannot add custom headers.
- The edge removes
x-tokenfrom the URL before the cache key, the origin and the access log, so the token does not fragment the cache, does not reach the origin, and is masked as[REDACTED]in logs. That way, one token per viewer still shares a single cached copy. - The header always wins over the query: if a request has both an
X-Vtokenheader and?x-token=, the edge uses the header (the query is still removed). 2 or moreX-Vtokenheaders →403. - Parameter name rules (strict): the name must be exactly
x-tokenin lowercase; other spellings are not accepted as a token. An empty or malformed value, or more than one?x-token=, is treated as an invalid token (403). Requests on Exempt paths or from Whitelisted IPs still go straight through. - Replay protection still applies to the query: an exact-path token can be used once (sending it again →
403 replay), so for HLS you must use prefix mode (one prefix token for the whole session) — just as with the header.
HLS with ?x-token=: the backend signs one prefix token (with a ttl long enough for the session) and appends ?x-token=<token> to the manifest URL. Important: segment URLs in the playlist are usually relative and do not carry the query automatically — the player must add ?x-token= to every request itself (through a loader/xhrSetup), or the packager/origin must write ?x-token= into each URL line of the playlist. Otherwise the manifest returns 200 but the segments return 403.
A token in the URL is exposed through browser history, the Referer header and client-side proxy logs → it is weaker than the header. Use a short ttl + a narrow prefix, and still sign on the backend (do not sign in the frontend).
Sample X-Vtoken signing code — on the backend (Python / PHP / Node.js)
Always sign on the backend, never in the frontend. The functions below take secret from a server-side environment variable. Never send the secret or this signing code to the browser or app (JS, HTML, SPA, mobile) — an exposed secret makes hotlink protection useless. The browser only receives tokens already signed by the backend.
Token structure (matches the edge specification): token = base64url_nopad(BODY || HMAC_SHA256(secret, BODY)), where
BODY = ver(0x02) | Flags(0x01=prefix) | Key_id_len|key_id | Ts(u64 BE) | Os_len(=0) | Uri_len(u16 BE)|uri | Ip_len(0|4|16)|ip | Nonce(8) | Ttl(u32 BE).
uri = a prefix ending in / (prefix mode, used for HLS). secret uses the whole vts_… string as the HMAC key (no hex decoding). ttl is clamped to [30, the domain's ttl_secs]. (For exact mode on a single file: set flags=0x00 and uri = the exact path.)
Only pass client_ip if the domain has Bind to client IP turned on.
Python
import base64, hashlib, hmac, ipaddress, os, struct, time
def make_vtoken(secret, key_id, prefix, ttl=3600, client_ip=None):
assert prefix.startswith("/") and prefix.endswith("/"), "prefix must start & end with '/'"
ttl = max(30, min(86400, int(ttl)))
ip = b""
if client_ip:
a = ipaddress.ip_address(client_ip)
if isinstance(a, ipaddress.IPv6Address) and a.ipv4_mapped:
a = a.ipv4_mapped
ip = a.packed # 4 bytes (v4) / 16 bytes (v6)
kid, uri = key_id.encode(), prefix.encode()
body = bytes([0x02, 0x01, len(kid)]) + kid # ver, flags=prefix, key_id
body += struct.pack(">Q", int(time.time())) # ts u64 BE
body += bytes([0]) # os_len = 0
body += struct.pack(">H", len(uri)) + uri # uri_len u16 BE + uri
body += bytes([len(ip)]) + ip # ip_len + ip
body += os.urandom(8) # nonce
body += struct.pack(">I", ttl) # ttl u32 BE
mac = hmac.new(secret.encode(), body, hashlib.sha256).digest()
return base64.urlsafe_b64encode(body + mac).rstrip(b"=").decode()
# prefix = the manifest's directory, ending in '/'
# make_vtoken(os.environ["VTS_SECRET"], "v01", "/vod/course-1/", ttl=7200)
PHP
<?php
function make_vtoken(string $secret, string $keyId, string $prefix, int $ttl = 3600, ?string $clientIp = null): string {
if ($prefix[0] !== '/' || substr($prefix, -1) !== '/')
throw new InvalidArgumentException("prefix must start & end with '/'");
$ttl = max(30, min(86400, $ttl));
$ip = '';
if ($clientIp !== null) { // IPv4 'a.b.c.d' -> 4 bytes; IPv6 -> 16 bytes
$ip = inet_pton($clientIp);
if ($ip === false) throw new InvalidArgumentException("invalid client_ip");
}
$body = pack('C', 0x02) . pack('C', 0x01); // ver, flags = prefix
$body .= pack('C', strlen($keyId)) . $keyId; // key_id_len + key_id
$body .= pack('J', time()); // ts u64 BE
$body .= pack('C', 0); // os_len = 0
$body .= pack('n', strlen($prefix)) . $prefix; // uri_len u16 BE + uri
$body .= pack('C', strlen($ip)) . $ip; // ip_len + ip
$body .= random_bytes(8); // nonce
$body .= pack('N', $ttl); // ttl u32 BE
$mac = hash_hmac('sha256', $body, $secret, true);
return rtrim(strtr(base64_encode($body . $mac), '+/', '-_'), '=');
}
// make_vtoken(getenv('VTS_SECRET'), 'v01', '/vod/course-1/', 7200);
Node.js
const crypto = require('crypto');
function makeVtoken(secret, keyId, prefix, ttl = 3600, clientIp = null) {
if (!prefix.startsWith('/') || !prefix.endsWith('/'))
throw new Error("prefix must start & end with '/'");
ttl = Math.max(30, Math.min(86400, ttl | 0));
const kid = Buffer.from(keyId, 'ascii');
const uri = Buffer.from(prefix, 'utf8');
let ip = Buffer.alloc(0);
if (clientIp) ip = Buffer.from(clientIp.split('.').map(n => parseInt(n, 10))); // IPv4; for IPv6, parse into 16 bytes yourself
const tsb = Buffer.alloc(8); tsb.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)));
const ulb = Buffer.alloc(2); ulb.writeUInt16BE(uri.length);
const ttlb = Buffer.alloc(4); ttlb.writeUInt32BE(ttl);
const body = Buffer.concat([
Buffer.from([0x02, 0x01, kid.length]), kid, // ver, flags=prefix, key_id
tsb, // ts u64 BE
Buffer.from([0x00]), // os_len = 0
ulb, uri, // uri_len u16 BE + uri
Buffer.from([ip.length]), ip, // ip_len + ip
crypto.randomBytes(8), // nonce
ttlb, // ttl u32 BE
]);
const mac = crypto.createHmac('sha256', Buffer.from(secret, 'utf8')).update(body).digest();
return Buffer.concat([body, mac]).toString('base64url');
}
// makeVtoken(process.env.VTS_SECRET, 'v01', '/vod/course-1/', 7200);
The three functions above produce identical tokens (for the same input). Send the result in the header: X-Vtoken: <token>.
Configuration fields
| Field | Meaning | Values | Default | Notes |
|---|---|---|---|---|
| Enabled | Turns on signature verification for the whole domain | On/off | Off | Turning it on requires at least 1 usable key (409 otherwise); turning it on purges the domain's entire cache (turning it off does not) |
| Bind to client IP | Requires the IP in the signed token to equal the connecting IP | On/off | Off | Token without an IP or with a different IP → 403. Avoid turning it on for mobile/NAT/CGNAT (client IPs change often) |
Token lifetime (ttl_secs) | Accepted token age window | Seconds, 30–86400 | 300 | Out of range when saving → 400 error; a token past its age → 410 Gone. The ttl in the token is clamped to [30, the domain's ttl_secs] — if the domain ttl is short (for example 300), a token "signed long for a video" still expires partway through → 410; to keep long sessions, increase ttl_secs or have the backend issue a new token |
| Whitelisted IPs | IPs/CIDRs that skip signature checks entirely | ≤500 entries | — | CIDRs broader than v4 /8 or v6 /16 are rejected; ::ffff: and /0 prefixes are not allowed |
| Exempt paths | Path prefixes exempt from signature checks (prefix matching: exempting /health also exempts /healthz) | ≤100 entries | — | Each entry must start with / or be exactly * (exempt everything). / on its own is rejected (use * to exempt everything); * in the middle or at the end (for example /pub*) is not supported. Paths containing ./.. are never exempt; /.well-known/acme-challenge/ is always exempt |
(Key) key_id | Key identifier (for key rotation) | ^[A-Za-z0-9._-]{1,32}$ | Auto-generated (for example k1a2b3c4d) | Optional — if left empty, the system generates one. Used in the token to select the right secret; a duplicate key_id → 409 |
(Key) label | Note | ≤100 characters | — | — |
(Key) expires_at | Key expiry | A future time | — | Expired keys are not pushed to the edge |
| (Key) secret | vts_… signing string | Generated automatically | — | Shown in plaintext exactly once at creation; GET never returns the secret |
Key limits: ≤10 active keys, ≤50 keys in total (including revoked ones) — exceeding these returns 409. Key lifecycle: create → revoke → (only once revoked) delete.
Validation errors in this tab return HTTP 400 and name the invalid field — for example ttl_secs outside 30–86400, an incorrectly formatted exempt path, an incorrectly formatted key_id, a label > 100 characters, or an expires_at in the past. Only a duplicate key_id or exceeding the limit of 10 active keys (creating an 11th key) returns 409.
Configuration examples
Example 1 — Prevent hotlinking of images/videos, but allow the health-check page.
- Create key
prod-v2→ take thevts_…secret and give it to the SDK. - Enabled: on · Token lifetime:
300· Exempt paths:/health,/.well-known/. - Result: requests for images/videos without a valid
X-Vtoken→ 403;/health*requests go straight through without a token. - How to check:
curl -I https://example.com/video/a.m3u8(no token) → 403;curl -I https://example.com/health→ 200.
Example 2 — Rotate keys without interruption.
- Key
prod-v1is in use. Create another key,prod-v2(there are now 2 active keys), and update the SDK to usekey_id=prod-v2. - Once you are sure all traffic has moved over, revoke
prod-v1. - Result: during the transition, tokens signed with any active key are valid (the edge selects the secret by the
key_idin the token). - How to check: send tokens signed with both keys → both return 200; after revoking
prod-v1→ old tokens return 403.
Example 3 — Exempt an office or partner CDN IP range.
- Whitelisted IPs:
203.0.113.0/24(remember: no broader than /8 for v4 or /16 for v6). - Result: requests from this range skip the signature check and go straight through; other IPs still need to sign.
- How to check: request a resource without a token from an IP in the range → 200; from an IP outside → 403.
Order of checks inside X-Vtoken: the token source is chosen first (the X-Vtoken header wins; ?x-token= is used only when there is no header) and x-token is removed from the URL; requests on Exempt paths or from Whitelisted IPs go straight through; every other request needs a valid token (missing or invalid → 403, expired → 410).
Order of evaluation
- X-Vtoken runs after Access Control, and before Token V2 / Bot-mgmt / Rate Limit / WAF.
- Access Control
allowalso bypasses X-Vtoken (a matchingallowlets the request straight through, skipping vtoken). So do notallowbroad ranges if you still want to require a token. - Firewall Rules
allow/bypassdo not bypass X-Vtoken — requests let through by the firewall still need a valid token. - The header wins over the query: the
X-Vtokenheader token always takes precedence over?x-token=; the query is used only when there is no header. Either way,x-tokenis removed from the URL before cache/origin/log. - The token is not forwarded to your origin.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| Turning on Enabled returns 409 | No usable key | Create at least 1 key (not expired) and turn it on again |
| Turning on Enabled returns 503 | The cache purge before enabling failed | Try again later; if it keeps happening, contact support (it cannot be turned on, to avoid leaking cached content) |
| Saving returns 400 when adding to the whitelist | CIDR broader than /8 (v4) / /16 (v6), or in ::ffff://0 form | Narrow the range |
| Creating a key returns 409 | Over the limit of ≤10 active or ≤50 total keys | Revoke/delete some old keys |
| Mobile visitors often get 403 | Bind to client IP is on and NAT/CGNAT changes the IP | Turn off Bind to client IP |
| Request returns 410 Gone | The token has expired (past its ttl, or the ttl was clamped to a short domain ttl) — the token was genuinely signed | Have the backend issue a new token; if you need longer sessions, increase the domain's ttl_secs. 410 is a final status; the player does not retry automatically (unlike 408) |
| A newly issued token still returns 403 (not 410) | The key_id in the token has been revoked or the key has expired | Sign with a valid key_id (not revoked, not past expires_at) |
| HLS: manifest returns 200 but segments return 403 | Exact-path tokens are used (replay), or segments do not carry ?x-token= | Sign in prefix mode and make sure the player/origin adds ?x-token= to every segment |
?X-Token= (uppercase) has no effect | The parameter name is case-sensitive; only x-token is accepted | Use exactly x-token (lowercase) |
The vts_… secret is lost | The secret is shown only once | Create a new key, update the SDK, then revoke the old key |
FAQ
- What does the client need to do to get through? The backend signs
X-Vtokenwith the secret +key_id, and the client sends it in the header; without a valid token, access is denied (that is the point of hotlink protection). - Should I sign
X-Vtokenin browser JavaScript / the frontend? No. That requires embedding the secret in the frontend → anyone can see it and sign tokens themselves, which defeats the protection entirely. Always sign on the backend; the browser only receives signed tokens (or short-lived tokens issued by the backend). - What if I already put the secret in the frontend? Treat it as exposed: revoke that key immediately, create a new
key_id, move signing to the backend, then update the clients. - How is it different from Token V2? X-Vtoken signs each request (through the
X-Vtokenheader or the?x-token=query; with nonce/replay protection and key rotation); Token V2 signs the URL — suitable for shared links and HLS. See the Token V2 article. - Can I retrieve an old secret? No. GET does not return the secret, and it is shown only once at creation. You must create a new key.
- Will my website be slower once it is turned on? Every request must be verified, and the cache is refilled after the purge; consider turning it on only for domains that really need hotlink protection.
- Should I use the header or
?x-token=? Prefer theX-Vtokenheader (safer, not exposed through the URL). Use?x-token=only when the client cannot set headers (native HLS,<video>tags); in that case use a short ttl + a narrow prefix. - How do I handle
410? 410 = the token has expired (genuinely signed but past its ttl). Have the backend issue a new token and reload; because 410 is not retried automatically, it is a clear signal to "request a new token" (410 was chosen over 408 because players and browsers retry 408 automatically, causing loops). - Want a custom error page for 410? Custom error pages (Error Pages) match the exact status code — add a page for status 410 if you want to show a "token expired" message instead of the default 410 page.