> 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-ip-lock.md). Agents can also search and read this documentation through its [MCP server](https://clients.medianova.com/~gitbook/mcp).

# Secure Token v2 – IP Lock

Learn how to configure Secure Token v2 – IP Lock and generate signed URLs restricted to a specific client IP address.

Secure Token v2 – IP Lock protects CDN content using signed, time-limited URLs bound to the viewer's IP address.

Medianova CDN validates the signature, expiration time, and client IP address before serving protected content. A URL generated for one IP address cannot be used from another IP address.

The token can protect a directory or an entire CDN Resource, depending on the **Token URI** setting.

## How Secure Token v2 – IP Lock works

Secure Token v2 – IP Lock generates an MD5 signature using the expiration timestamp, Token Key, and viewer's IP address.

When Token URI is enabled, the signature also includes the requested file's directory.

The validation process follows these stages:

1. **Token generation:** Your application generates a signature using the expiration time, secret key, client IP address, and optional directory.
2. **Content request:** The viewer requests content using a URL containing `st` and `e`.
3. **Token validation:** Medianova CDN calculates the signature using the IP address of the incoming request.
4. **Request handling:** The CDN processes valid requests and rejects requests that fail validation.

<figure><img src="https://542970813-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtK7oIwmhUHdEJcaH4Hx8%2Fuploads%2FD7hVGyWzAXrDDsidKcTp%2Fimage.png?alt=media&amp;token=24ee3569-fc92-4965-9fba-39302861955b" alt="" width="543"><figcaption><p><strong>Secure Token v2 – IP Lock</strong></p></figcaption></figure>

The viewer's IP address is part of the signature but does not appear as a separate URL parameter.

#### Understand Token URI behavior

<table><thead><tr><th width="91.5">Token URI</th><th width="299">Signed values</th><th>Access scope</th></tr></thead><tbody><tr><td>Enabled</td><td>Expiration, Token Key, IP address, directory</td><td>Files in the signed directory, from the specified IP</td></tr><tr><td>Disabled</td><td>Expiration, Token Key, IP address</td><td>All paths within the CDN Resource, from the specified IP</td></tr></tbody></table>

{% hint style="warning" %}
A token becomes invalid when the viewer's IP address changes. Generate a new signed URL after a network change.
{% endhint %}

## Supported CDN Resource types

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

| CDN Resource type | Availability  |
| ----------------- | ------------- |
| Small CDN         | Supported     |
| Large CDN         | Supported     |
| Large Streaming   | Supported     |
| Streaming         | Not supported |
| VOD               | Not supported |

{% hint style="info" %}
Available settings and validation behavior may vary by CDN Resource type.
{% endhint %}

## Configure Secure Token v2 – IP Lock

Use the [Medianova Control Panel](https://cloud.medianova.com) to configure Secure Token v2 – IP Lock.

{% 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 – IP Lock

Choose **Secure Token v2 – IP Lock** from **Token Type**.

<figure><img src="https://542970813-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtK7oIwmhUHdEJcaH4Hx8%2Fuploads%2FtohDs6kSh8Us80NaconY%2Fimage.png?alt=media&amp;token=db804b8b-fcb7-4c96-9b42-1dc3c31b8c3d" alt=""><figcaption></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. Changing the key invalidates URLs generated with the previous key.
{% endhint %}

## Generate a signed URL

Secure Token v2 – IP Lock uses two required query parameters.

<table><thead><tr><th width="264">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 IP address is included in the signing input, not in the URL.

### Generate a directory-based signature

When Token URI is enabled, include the directory path and client IP address in the signature.

Use this formula:

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

Where:

* `e` is the expiration timestamp.
* `KEY` is the configured Token Key.
* `IP` is the viewer's IP address as seen by Medianova CDN.
* `DIRECTORY` is the requested file's directory path.

Use exactly one space between each value.

**Verify the directory-based example**

Use the following values to test your implementation:

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

The signed string is:

```
1798761600 ExampleKey2026 203.0.113.10 /videos/
```

The expected signature is:

```
CXRYMgpsMa439oYn8osFNQ
```

The resulting URL is:

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

The same token can authorize other files in `/videos/` when requests originate from `203.0.113.10`.

A request from another IP address fails token validation.

### Generate a path-independent signature

When Token URI is disabled, exclude the directory path from the signature.

Use this formula:

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

Use exactly one space between the values.

**Verify the path-independent example**

Use the following values:

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

The signed string is:

```
1798761600 ExampleKey2026 203.0.113.10
```

The expected signature is:

```
oqtrmtv19UzsDr790A-P9g
```

The resulting URL is:

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

This token can authorize other paths within the CDN Resource when requests originate from the specified IP address.

{% hint style="warning" %}
The example key and IP address are for testing only. Never use example credentials in production.
{% endhint %}

## Generate signed URLs with Python

The following example generates signed URLs using either Token URI mode.

It reads the Token Key from an environment variable and creates 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,
    viewer_ip: str,
    token_uri: bool = True,
) -> str:
    expiration = int(time.time()) + ttl

    signed_data = f"{expiration} {key} {viewer_ip}"

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

    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,
    viewer_ip="203.0.113.10",
    token_uri=True,
)

print(url)
```

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

Replace the example hostname, file path, and IP address with your actual values.

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="warning" %}
Generate signed URLs on a trusted backend. Never expose the Token Key in client-side code or public repositories.
{% endhint %}

## Follow IP address and directory rules

Secure Token v2 – IP Lock requires the signing application to use the same IP address that Medianova CDN identifies for the incoming request.

### Match the viewer's IP address

Use the client's IP address as it appears to the CDN.

The token fails validation if the signed IP address differs from the request IP address.

Common causes include:

* The viewer switches between Wi-Fi and mobile networks.
* The viewer connects through a VPN.
* A proxy changes the IP address visible to the CDN.
* The application signs an incorrect client IP address.

Generate a new token when the client's IP address changes.

### Match the signed directory

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

<table><thead><tr><th width="348">Rule</th><th>Example</th></tr></thead><tbody><tr><td>Begin the directory with <code>/</code>.</td><td><code>/videos/</code></td></tr><tr><td>Include the trailing <code>/</code>.</td><td><code>/videos/</code>, not <code>/videos</code></td></tr><tr><td>Exclude the hostname.</td><td>Sign <code>/videos/</code>, not the full URL.</td></tr><tr><td>Exclude query parameters.</td><td>Sign <code>/videos/</code> for <code>/videos/file.mp4?quality=hd</code>.</td></tr><tr><td>Preserve letter case.</td><td><code>/Videos/</code> differs from <code>/videos/</code>.</td></tr><tr><td>Use the normalized path.</td><td>Match the path expected by the CDN.</td></tr></tbody></table>

A token generated for `/videos/` does not authorize files in `/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.

{% 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 – IP Lock safely

Prepare your application 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 IP-bound signature generation to your application backend.
{% endstep %}

{% step %}

### Validate the signing implementation

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

{% step %}

### Deploy signed URLs

Update your application to distribute signed URLs using the viewer's current IP address.
{% endstep %}

{% step %}

### Configure public path exceptions

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

{% step %}

### Enable Secure Token v2 – IP Lock

Apply the prepared configuration in the Medianova Control Panel.
{% endstep %}

{% step %}

### Verify protected requests

Test valid, invalid, expired, and IP-mismatched URLs.
{% endstep %}
{% endstepper %}

{% hint style="warning" %}
Enabling Security Token can cause existing unsigned URLs to fail. Deploy signed URL generation before enforcing validation.
{% endhint %}

## Validate Secure Token v2 – IP Lock requests

For the validated Small CDN implementation:

| Condition                                   | HTTP response                        |
| ------------------------------------------- | ------------------------------------ |
| Valid signature, expiration, and IP address | Request proceeds to content delivery |
| Missing token                               | 403 Forbidden                        |
| Invalid signature                           | 403 Forbidden                        |
| IP address mismatch                         | 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 – IP Lock

### HTTP 403 Forbidden

The CDN rejects requests that fail token validation.

Check the following:

* The URL contains both `st` and `e`.
* The application uses the correct Token Key.
* The signed IP address matches the client's IP address as seen by the CDN.
* 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.

Compare your generated signature with the worked examples:

| Token URI | Expected signature       |
| --------- | ------------------------ |
| Enabled   | `CXRYMgpsMa439oYn8osFNQ` |
| Disabled  | `oqtrmtv19UzsDr790A-P9g` |

### 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 URL stops working after a network change

The viewer's IP address may have changed.

Generate a new signed URL using the current client IP address.

### 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.
* Determine the viewer's IP address from a trusted source.
* 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.
* Regenerate tokens when client IP addresses change.
* Test the configuration before enabling enforcement.

{% hint style="warning" %}
IP-based restrictions may interrupt access for users with frequently changing IP addresses. Consider this behavior before enabling IP Lock.
{% endhint %}

## Related token types

For different access requirements, consider:

* [**Secure Token v2**](https://clients.medianova.com/products/security/security-token/secure-token-v2.md)**:** Protect directories without binding tokens to an IP address.
* [**Secure Token v2 – Country Lock**](https://clients.medianova.com/products/security/security-token/secure-token-v2-country-lock.md)**:** Restrict access based on the viewer's country.
* [**Secure Token – IP & Cookie Lock**](https://clients.medianova.com/products/security/security-token/secure-token-ip-and-cookie-lock.md)**:** Bind file access to an IP address and configured cookie values.

{% 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-ip-lock.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.
