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

# Secure Token – IP & Cookie Lock

Learn how to configure IP- and cookie-bound signed URLs to protect CDN content for authenticated sessions.

Secure Token – IP & Cookie Lock restricts access to individual files using signed URLs bound to a viewer's IP address and session cookies.

Each signature includes the file path, expiration time, client IP address, and values of up to three configured cookies.

Medianova CDN validates these values before serving the requested content. A URL becomes invalid if a required cookie value or the viewer's IP address changes.

## How Secure Token – IP & Cookie Lock works

Your application generates a signed URL using a secret key and request-specific information.

The validation process follows these stages:

1. **Token generation:** Your backend signs the file path, expiration time, viewer IP address, and configured cookie values.
2. **Content request:** The viewer requests the signed URL, and the browser sends its applicable cookies.
3. **Token validation:** Medianova CDN recalculates the signature using the request IP address and received cookie values.
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%2FcCUNqFMw6RlnCKCenMLm%2Fimage.png?alt=media&amp;token=994459e8-f88a-4a00-85bf-f3f7026eae79" alt="" width="536"><figcaption><p><strong>Secure Token – IP &#x26; Cookie Lock</strong></p></figcaption></figure>

The IP address and cookie values are included in the signature but do not appear as separate URL parameters.

### Understand access restrictions

<table><thead><tr><th width="262.5">Restriction</th><th>Behavior</th></tr></thead><tbody><tr><td>File path</td><td>The token is valid for the signed file path.</td></tr><tr><td>IP address</td><td>The viewer must use the IP address included in the signature.</td></tr><tr><td>Cookie values</td><td>The request must contain the expected cookie values.</td></tr><tr><td>Expiration</td><td>The token must remain within its validity period.</td></tr></tbody></table>

{% hint style="info" %}
Cookie Lock can associate signed URLs with application sessions. It does not authenticate users independently. Your application remains responsible for session authentication.
{% endhint %}

## Supported CDN Resource types

Secure Token – IP & Cookie Lock is available for:

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

The feature applies to protected paths within the CDN Resource. Page Rules can provide exceptions for content that must remain public.

## Configure Secure Token – IP & Cookie Lock

Use the [Medianova Control Panel](https://cloud.medianova.com) to configure the token and select the cookies included in its signature.

{% 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 **Security Token**.
{% endstep %}

{% step %}

### Select Secure Token – IP & Cookie Lock

Choose **Secure Token – IP & Cookie Lock** from **Token Type**.

<figure><img src="https://542970813-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtK7oIwmhUHdEJcaH4Hx8%2Fuploads%2F9YcbqgeOt3dOm2MGJed0%2Fimage.png?alt=media&amp;token=57b203fc-19c9-4ff0-85e6-72f7bb170d9a" 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 the cookies

Specify the names of the cookies to include in the signature.

Configure up to three cookie names. Preserve their order when generating signed URLs.
{% endstep %}

{% step %}

### Save the configuration

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

{% hint style="warning" %}
Changing the Token Key invalidates URLs signed with the previous key. Changing configured cookie names or their order also affects signature validation.
{% endhint %}

## Understand cookie configuration

Secure Token – IP & Cookie Lock supports up to three configured cookies.

The cookie names determine which values the CDN includes during signature validation.

| Setting                | Requirement                                 |
| ---------------------- | ------------------------------------------- |
| Maximum cookies        | Three                                       |
| Cookie name characters | Letters, digits, and underscores (`_`)      |
| Cookie order           | Must match the configured order             |
| Missing cookie         | Contributes an empty value to the signature |
| Cookie value           | Must match the value received by the CDN    |

For example, suppose you configure these cookie names:

```
session_id
user_token
```

Your application must sign their values in the same order:

```
<SESSION_ID_VALUE><USER_TOKEN_VALUE>
```

Do not insert separators between cookie values.

{% hint style="warning" %}
The browser must send the configured cookies to the CDN hostname. A correct signature cannot compensate for cookies missing from the request.
{% endhint %}

## Generate a signed URL

Secure Token – IP & Cookie Lock uses two required query parameters.

<table><thead><tr><th width="270">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 signature includes the Token Key, file path, expiration time, viewer IP address, and cookie values.

### Calculate the signature

Use the following formula:

```
st = base64url(
    MD5(KEY + PATH + EXPIRATION + IP + COOKIE_VALUES)
)
```

Where:

* `KEY` is the configured Token Key.
* `PATH` is the requested file path.
* `EXPIRATION` is the Unix expiration timestamp.
* `IP` is the viewer's IP address as seen by the CDN.
* `COOKIE_VALUES` contains the configured cookie values in order.

Concatenate all values without separators.

Use the raw 16-byte MD5 digest. Encode it using Base64URL and remove trailing `=` padding.

The resulting signature contains 22 characters.

### Verify the signature example

Use these values to test your implementation:

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

The signed string is:

```
ExampleKey2026/videos/sample.mp41798761600203.0.113.10abc123
```

The expected signature is:

```
jAGiY02CXPPuVlOKq2eX-w
```

The resulting URL is:

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

The URL is valid only when the request matches the signed values and has not expired.

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

## Generate signed URLs with Python

The following example generates a signed URL valid for one hour.

It accepts the viewer's IP address and configured cookie values as inputs.

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


def sign_url(
    base_url: str,
    path: str,
    key: str,
    ttl: int,
    viewer_ip: str,
    cookie_values: list[str],
) -> str:
    expiration = int(time.time()) + ttl

    signed_data = (
        f"{key}"
        f"{path}"
        f"{expiration}"
        f"{viewer_ip}"
        f"{''.join(cookie_values)}"
    )

    digest = hashlib.md5(
        signed_data.encode("utf-8")
    ).digest()

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

    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",
    cookie_values=["abc123"],
)

print(url)
```

Set `MN_TOKEN_KEY` to the Token Key configured in the Medianova Control Panel.

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

Pass cookie values in the same order as their names appear in the token configuration.

{% hint style="info" %}
Generate signed URLs on your application backend. Never expose the Token Key in browser scripts, mobile applications, or client-side configuration.
{% endhint %}

## Follow IP address and cookie rules

### Match the viewer's IP address

Sign the IP address the viewer uses to reach Medianova CDN.

Do not sign your application's load balancer address or another intermediate server address.

If your application uses a reverse proxy, obtain the client IP address from a trusted proxy configuration.

Do not trust arbitrary client-supplied forwarding headers.

IP mismatches can occur when:

* A viewer switches between Wi-Fi and mobile data.
* A VPN or proxy changes the visible IP address.
* The application and CDN use different IP address families.
* An application signs an incorrect forwarded IP address.

Generate a new signed URL when the viewer's IP address changes.

{% hint style="info" %}
For IPv6 addresses, use a consistent compressed representation, such as `2001:db8::1`.
{% endhint %}

### Ensure the browser sends cookies

The browser sends cookies only when their domain, path, and applicable security attributes permit it.

For example, if your website uses `www.example.com` and your CDN uses `cdn.example.com`, a cookie restricted to `www.example.com` is not sent to the CDN.

A cookie scoped to `.example.com` can be sent to both subdomains when its other attributes allow it.

Use browser developer tools to inspect the actual request sent to the CDN.

{% hint style="warning" %}
Some native media players and HTTP clients do not automatically forward application cookies. Verify cookie delivery before using this token type.
{% endhint %}

### Preserve cookie values

Sign the exact cookie values expected in the CDN request.

For example, if the configured cookies are:

```
session_id
user_token
```

And their values are:

```
abc123
xyz789
```

The combined cookie input is:

```
abc123xyz789
```

Do not include cookie names, delimiters, or additional whitespace.

If a configured cookie is missing, use an empty value in its position.

### Follow file path rules

The signed path must match the requested file path.

| Rule                      | Example                                        |
| ------------------------- | ---------------------------------------------- |
| Begin the path with `/`.  | `/videos/sample.mp4`                           |
| Exclude the hostname.     | Sign `/videos/sample.mp4`.                     |
| Exclude query parameters. | Sign `/video.mp4` for `/video.mp4?quality=hd`. |
| Preserve letter case.     | `/Video.mp4` differs from `/video.mp4`.        |
| Sign the decoded path.    | Sign `/my file.mp4` for `/my%20file.mp4`.      |

Each file path requires its own signature.

A token for `/videos/sample.mp4` does not authorize `/videos/other.mp4`.

## 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 started before expiration can complete. However, seeking, resuming, or starting a new range request requires a valid token.

{% hint style="info" %}
Use UTC-based Unix timestamps. The existing technical guide recommends keeping the Token Timezone setting at UTC.
{% endhint %}

## Deploy Secure Token – IP & Cookie Lock safely

Prepare signed URLs and cookie delivery before enabling token enforcement.

{% stepper %}
{% step %}

### Generate a Token Key

Create a secure key and store it in your application's secret management system.
{% endstep %}

{% step %}

### Configure application cookies

Ensure your application issues the required cookies for the CDN hostname.
{% endstep %}

{% step %}

### Implement URL signing

Add IP- and cookie-bound signature generation to your backend.
{% endstep %}

{% step %}

### Verify the signing implementation

Compare the generated signature with the worked example on this page.
{% endstep %}

{% step %}

### Deploy signed URLs

Update your application to distribute signed URLs to authenticated viewers.
{% endstep %}

{% step %}

### Configure public path exceptions

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

{% step %}

### Enable Secure Token – IP & Cookie Lock

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

{% step %}

### Test protected requests

Verify valid, invalid, expired, IP-mismatched, and cookie-mismatched requests.
{% endstep %}
{% endstepper %}

{% hint style="warning" %}
Enabling Security Token can cause existing unsigned URLs to fail. Deploy signed URLs and verify cookie delivery before enforcement.
{% endhint %}

## Validate protected 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                        |
| IP address mismatch            | 403 Forbidden                        |
| Cookie value 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 – IP & Cookie Lock

### HTTP 403 Forbidden

The CDN rejects requests that fail token validation.

Check the following:

* The URL contains both `st` and `e`.
* The Token Key matches the configured key.
* The signed file path matches the requested path.
* The signed IP address matches the IP address seen by the CDN.
* The browser sends the configured cookies.
* Cookie values appear in the correct order.
* The signature uses the raw MD5 digest.
* Base64URL encoding excludes `=` padding.
* No extra separators appear in the signed string.

Compare your output with the expected example signature:

```
jAGiY02CXPPuVlOKq2eX-w
```

### 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 your application clock is synchronized.

### A URL works after login but fails later

The application may have changed or renewed a session cookie.

Generate a new signed URL using the current cookie values.

### A URL fails in a browser

Check whether the browser sends the required cookies to the CDN hostname.

Inspect the request headers in browser developer tools.

Verify cookie domain, path, and security attributes.

### A URL fails in a media player

The player may not forward the configured cookies.

Inspect the requests generated by the player.

Use another token type if the client cannot send the required cookies.

### A URL fails after a network change

The viewer's IP address may have changed.

Generate a new URL using the current IP address.

### Signed URLs stop working after a key change

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

Update your application's signing key and generate new URLs.

## Security recommendations

* Store Token Keys in a secure backend environment.
* Use trusted sources to determine client IP addresses.
* Configure cookies with appropriate domain and security attributes.
* Use HTTPS for protected content.
* Keep token expiration periods appropriate for the content.
* Regenerate signed URLs after session cookie changes.
* Test cookie delivery across supported browsers and clients.
* Coordinate Token Key changes with application updates.

{% hint style="warning" %}
Cookie-based signing does not replace application authentication or session management. Protect the cookies themselves and invalidate application sessions when necessary.
{% endhint %}

## Related token types

For different access requirements, consider:

* [**Standard Secure Token**](https://clients.medianova.com/products/security/security-token/standard-secure-token.md)**:** Protect individual files without IP or cookie restrictions.
* [**Secure Token v2**](https://clients.medianova.com/products/security/security-token/secure-token-v2.md)**:** Protect directories or an entire CDN Resource.
* [**Secure Token v2 – IP Lock**](https://clients.medianova.com/products/security/security-token/secure-token-v2-ip-lock.md)**:** Restrict signed URLs to a client IP address without requiring cookies.
* [**Secure Token v2 – Country Lock**](https://clients.medianova.com/products/security/security-token/secure-token-v2-country-lock.md)**:** Restrict signed URLs to a 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-ip-and-cookie-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.
