> For the complete documentation index, see [llms.txt](https://clients.medianova.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://clients.medianova.com/products/security/security-token/secure-token-v2.md). Agents can also search and read this documentation through its [MCP server](https://clients.medianova.com/~gitbook/mcp).

# Secure Token v2

Learn how to configure Secure Token v2 and generate signed URLs for directory-level or path-independent content protection.

Secure Token v2 restricts access to CDN content using signed URLs with expiration times. It supports directory-based signing and path-independent signing.

With directory-based signing, one token can authorize multiple files in the same directory. With path-independent signing, the token can authorize any path within the CDN Resource until it expires.

## How Secure Token v2 works

Secure Token v2 generates an MD5 signature using an expiration timestamp, a secret key, and an optional directory path.

The signing process depends on the **Token URI** setting:

<table><thead><tr><th width="99">Token URI</th><th width="367.5">Signing behavior</th><th>Access scope</th></tr></thead><tbody><tr><td>Enabled</td><td>Signs the expiration time, Token Key, and directory path.</td><td>Files in the signed directory</td></tr><tr><td>Disabled</td><td>Signs the expiration time and Token Key.</td><td>All paths within the CDN Resource</td></tr></tbody></table>

<figure><img src="https://542970813-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtK7oIwmhUHdEJcaH4Hx8%2Fuploads%2FytVfWdFSwk3hVt0Mcj58%2Fimage.png?alt=media&amp;token=3019a8a8-803a-4e1f-aecf-e306e4b305f4" alt="" width="552"><figcaption><p>Access scope of Secure Token v2 with Token URI enabled and disabled, assuming a valid token.</p></figcaption></figure>

Medianova CDN validates the signature and expiration time before processing each protected request.

{% hint style="warning" %}
Disabling Token URI removes path restrictions from the signature. A valid token can authorize any path within the CDN Resource until expiration.
{% endhint %}

## Supported CDN Resource types

Secure Token v2 is available for the following CDN Resource types:

| CDN Resource type | Availability |
| ----------------- | ------------ |
| Small CDN         | Supported    |
| Large CDN         | Supported    |
| Large Streaming   | Supported    |

## Configure Secure Token v2

Use the [Medianova Control Panel](https://cloud.medianova.com) to configure Secure Token v2 for a supported CDN Resource.

{% stepper %}
{% step %}

### Select a CDN Resource

Open the CDN Resource you want to protect in the [Medianova Control Panel](https://cloud.medianova.com).
{% endstep %}

{% step %}

### Open Security settings

Navigate to **Security → General**.
{% endstep %}

{% step %}

### Enable Security Token

Enable the **Security Token** feature.
{% endstep %}

{% step %}

### Select Secure Token v2

Choose **Secure Token v2** from **Token Type**.

<figure><img src="https://542970813-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtK7oIwmhUHdEJcaH4Hx8%2Fuploads%2F9s9fxR5IbD21Tbz06AMn%2Fimage.png?alt=media&amp;token=be16e108-44f1-45fe-9388-5334c5c98c6f" alt=""><figcaption><p>Secure Token v2 configuration for a CDN Resource.</p></figcaption></figure>
{% endstep %}

{% step %}

### Configure the Token Key

Enter your secret key in **Token Key**.

Store the same key securely in your application backend.
{% endstep %}

{% step %}

### Configure Token URI

Enable **Token URI** for directory-based signing.

Disable it only when the token must authorize all paths within the CDN Resource.
{% endstep %}

{% step %}

### Save the configuration

Click **Save** to apply your settings.
{% endstep %}
{% endstepper %}

{% hint style="warning" %}
Keep your Token Key confidential. Replacing the key invalidates URLs generated with the previous key.
{% endhint %}

### Generate a signed URL

Secure Token v2 uses two required query parameters.

<table><thead><tr><th width="277.5">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>st</code></td><td>MD5 signature encoded using Base64URL without padding.</td></tr><tr><td><code>e</code></td><td>Expiration time as a Unix timestamp in seconds.</td></tr></tbody></table>

The signing input depends on whether Token URI is enabled.

### Generate a directory-based signature

When Token URI is enabled, Secure Token v2 includes the directory path in the signature.

Use this formula:

```
st = base64url(MD5(e + " " + KEY + " " + DIRECTORY))
```

Where:

* `e` is the expiration timestamp.
* `KEY` is the configured Token Key.
* `DIRECTORY` is the requested file's directory path.

Use exactly one space between each value.

For example, the directory of `/videos/sample.mp4` is `/videos/`.

**Verify the directory-based example**

Use these test values:

| Input           | Value                   |
| --------------- | ----------------------- |
| Token Key       | `ExampleKey2026`        |
| File path       | `/videos/sample.mp4`    |
| Directory       | `/videos/`              |
| Expiration      | `1798761600`            |
| Expiration date | 2027-01-01 00:00:00 UTC |

The signed string is:

```
1798761600 ExampleKey2026 /videos/
```

The expected signature is:

```
oG1tJMyqCSTmfqB7vBi3bA
```

The resulting URL is:

```
https://cdn.example.com/videos/sample.mp4?st=oG1tJMyqCSTmfqB7vBi3bA&e=1798761600
```

The same token can authorize other files in `/videos/` until expiration.

It does not authorize files in a different directory or a nested subdirectory.

### Generate a path-independent signature

When Token URI is disabled, Secure Token v2 does not include a path in the signature.

Use this formula:

```
st = base64url(MD5(e + " " + KEY))
```

Use exactly one space between the expiration timestamp and Token Key.

**Verify the path-independent example**

Use these test values:

| Input           | Value                   |
| --------------- | ----------------------- |
| Token Key       | `ExampleKey2026`        |
| Expiration      | `1798761600`            |
| Expiration date | 2027-01-01 00:00:00 UTC |

The signed string is:

```
1798761600 ExampleKey2026
```

The expected signature is:

```
spA8QDBr3G-ql2blrhCTzg
```

The resulting URL is:

```
https://cdn.example.com/videos/sample.mp4?st=spA8QDBr3G-ql2blrhCTzg&e=1798761600
```

This token can authorize other paths within the same CDN Resource until expiration.

{% hint style="warning" %}
The example key is for testing only. Never use it to protect production content.
{% endhint %}

## Generate signed URLs with Python

The following example supports both Token URI modes.

It reads the secret key from an environment variable and generates a URL valid for one hour.

```python
import base64
import hashlib
import os
import time


def sign_url(
    base_url: str,
    path: str,
    key: str,
    ttl: int,
    token_uri: bool = True,
) -> str:
    expiration = int(time.time()) + ttl

    if token_uri:
        directory = path[:path.rfind("/") + 1]
        signed_data = f"{expiration} {key} {directory}"
    else:
        signed_data = f"{expiration} {key}"

    digest = hashlib.md5(signed_data.encode()).digest()

    signature = (
        base64.urlsafe_b64encode(digest)
        .rstrip(b"=")
        .decode()
    )

    return (
        f"{base_url}{path}"
        f"?st={signature}&e={expiration}"
    )


url = sign_url(
    base_url="https://cdn.example.com",
    path="/videos/sample.mp4",
    key=os.environ["MN_TOKEN_KEY"],
    ttl=3600,
    token_uri=True,
)

print(url)
```

Set `MN_TOKEN_KEY` to the Token Key configured in the [Medianova Control Panel](https://cloud.medianova.com).

Replace `cdn.example.com` with your CDN hostname and `/videos/sample.mp4` with the requested file path.

Set `token_uri` to match the Token URI setting in the Control Panel.

The signature uses the raw 16-byte MD5 digest encoded with Base64URL. Remove trailing `=` padding characters.

{% hint style="info" %}
Generate signed URLs on a trusted backend. Never expose the Token Key in client-side code.
{% endhint %}

## Follow directory signing rules

When Token URI is enabled, the signed directory must match the directory of the requested file.

| Rule                          | Example                                            |
| ----------------------------- | -------------------------------------------------- |
| Begin the directory with `/`. | `/videos/`                                         |
| Include the trailing `/`.     | `/videos/`, not `/videos`                          |
| Exclude the hostname.         | Sign `/videos/`, not the full URL.                 |
| Exclude query parameters.     | Sign `/videos/` for `/videos/file.mp4?quality=hd`. |
| Preserve letter case.         | `/Videos/` differs from `/videos/`.                |
| Use the normalized path.      | Match the path expected by the CDN.                |

For `/videos/series/episode.mp4`, sign `/videos/series/`.

A token for `/videos/` does not cover `/videos/series/`.

{% hint style="info" %}
For the validated Small CDN implementation, unrelated query parameters are not included in the signature.
{% endhint %}

## Manage token expiration

The `e` parameter defines the expiration time as a Unix timestamp in seconds.

Calculate the expiration using the current Unix time and the required validity period.

For example, a one-hour token uses:

```
EXPIRATION = CURRENT_UNIX_TIME + 3600
```

Use a synchronized system clock when generating signatures.

After expiration, the CDN rejects new requests using the expired token.

A request that begins before expiration can complete. However, a new request requires a valid token.

{% hint style="info" %}
Use UTC-based Unix timestamps for signing. The source guide recommends UTC for the Token Timezone setting.
{% endhint %}

## Deploy Secure Token v2 safely

Enabling Security Token causes unsigned requests to fail for protected paths.

Prepare signed URLs before enabling token enforcement.

{% stepper %}
{% step %}

### Generate a Token Key

Create a secure key for your application and CDN Resource.
{% endstep %}

{% step %}

### Implement URL signing

Add Secure Token v2 signature generation to your application backend.
{% endstep %}

{% step %}

### Validate the signing implementation

Compare your generated signatures with the worked examples on this page.
{% endstep %}

{% step %}

### Deploy signed URLs

Update your application to distribute signed URLs for protected content.
{% endstep %}

{% step %}

### Configure public path exceptions

Create the required Page Rules for content that must remain publicly accessible.
{% endstep %}

{% step %}

### Enable Secure Token v2

Apply the prepared Token Key and Token URI configuration in the [Medianova Control Panel](https://cloud.medianova.com).
{% endstep %}

{% step %}

### Verify protected requests

Test valid, invalid, and expired URLs after enabling the feature.
{% endstep %}
{% endstepper %}

{% hint style="warning" %}
Unsigned links in bookmarks, emails, applications, or third-party websites may stop working after enforcement begins.
{% endhint %}

## Validate Secure Token v2 requests

For the validated Small CDN implementation:

| Condition                      | HTTP response                        |
| ------------------------------ | ------------------------------------ |
| Valid signature and expiration | Request proceeds to content delivery |
| Missing token                  | 403 Forbidden                        |
| Invalid signature              | 403 Forbidden                        |
| Expired token                  | 410 Gone                             |

A successful token validation does not guarantee an HTTP 200 response. Content availability and other CDN settings still affect the final response.

## Troubleshoot Secure Token v2

### HTTP 403 Forbidden

The CDN rejects requests with missing or invalid token information.

Check the following:

* The URL contains both `st` and `e`.
* The application uses the correct Token Key.
* The signed values use exactly one space as a separator.
* The Token URI setting matches the signing method.
* The signed directory matches the requested path.
* The signature uses the raw MD5 digest.
* Base64URL encoding excludes `=` padding.
* The expiration timestamp has not changed after signing.

Compare your output with the worked signatures:

| Token URI | Expected signature       |
| --------- | ------------------------ |
| Enabled   | `oG1tJMyqCSTmfqB7vBi3bA` |
| Disabled  | `spA8QDBr3G-ql2blrhCTzg` |

### HTTP 410 Gone

For the validated Small CDN implementation, HTTP 410 indicates an expired token.

Generate a new signed URL with a future expiration timestamp.

Verify that the application clock is synchronized.

### A token works for unexpected paths

Check the Token URI setting.

When Token URI is disabled, the signature does not include a directory path.

Enable Token URI when access must remain restricted to a specific directory.

### Signed URLs stop working after a key change

Changing the Token Key invalidates URLs generated with the previous key.

Update the signing key in your application and generate new URLs.

## Security recommendations

* Store the Token Key in a secure backend environment.
* Use Token URI when directory-level restrictions are required.
* Avoid path-independent signing unless the use case requires it.
* Select expiration periods appropriate for the content.
* Use HTTPS when delivering protected content.
* Coordinate Token Key changes with application updates.
* Test the configuration before enabling enforcement.

{% hint style="warning" %}
Disabling Security Token removes token validation for protected paths. The validated Small CDN implementation also clears the stored Token Key.
{% endhint %}

## Related token types

For additional access restrictions, consider:

* [**Standard Secure Token**](https://clients.medianova.com/products/security/security-token/standard-secure-token.md)**:** Sign individual file paths.
* [**Secure Token v2 – IP Lock**](https://clients.medianova.com/products/security/security-token/secure-token-v2-ip-lock.md)**:** Bind signed access to a client IP address.
* [**Secure Token v2 – Country Lock**](https://clients.medianova.com/products/security/security-token/secure-token-v2-country-lock.md)**:** Restrict signed access by country.

{% hint style="info" %}
For general feature configuration, refer to the [Security Token](https://clients.medianova.com/products/security/security-token.md) page.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://clients.medianova.com/products/security/security-token/secure-token-v2.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
