> ## Documentation Index
> Fetch the complete documentation index at: https://docs.roolink.io/llms.txt
> Use this file to discover all available pages before exploring further.

# UTMVC

> Imperva's cookie challenge: generate the ___utmvc cookie from the Incapsula script and your session cookies, then activate it.

UTMVC is the older of Imperva's two challenges and still common. Instead of a token, the site wants a cookie named `___utmvc` (three underscores) whose value is computed from a script the page loads and from the cookies the site has already set. Roolink computes the value; you set the cookie and make one activation request.

## How to recognize it

The page loads a script from Imperva's resource endpoint, with a query parameter that starts with `SWJIYLWA`:

```html theme={null}
<script src="/_Incapsula_Resource?SWJIYLWA=5074a744497e4e65a8f5b9b3aa1a2b17,719d34d31c8e3a6e6fffd425f7e032f3"></script>
```

At the same time the site has set cookies whose names start with `incap_ses_` and `visid_incap_`. Those are the session cookies UTMVC is bound to.

## The flow

**1. Fetch the script**

`GET` the `_Incapsula_Resource` script URL from the page, through your session, with the script headers from your powhttp recording. Keep the body exactly as received.

**2. Ask Roolink for the cookie**

Call `/utmvc` with the script body and your session's cookies as one `document.cookie` string: every cookie the site has set so far, as `name=value` pairs separated by `; `. The `incap_ses_*` cookies are the ones the value is bound to, so make sure they are included. Roolink returns the cookie value plus a ready-made `cookie` header fragment and `setCookie` line.

```python Python theme={null}
cookie_string = "; ".join(f"{c.name}={c.value}" for c in site.cookies)
result = requests.post(f"{ROOLINK}/utmvc",
    headers={"x-api-key": os.environ["ROOLINK_API_KEY"]},
    json={"script": script.text, "cookies": cookie_string, "userAgent": UA},
).json()
site.cookies.set("___utmvc", result["value"], domain=host, path="/")
```

```go Go theme={null}
var parts []string
for _, c := range jar.Cookies(pageURL) {
    parts = append(parts, c.Name+"="+c.Value)
}
var result struct{ Value string `json:"value"` }
json.Unmarshal(callRoolink("/utmvc", map[string]any{
    "script": script, "cookies": strings.Join(parts, "; "), "userAgent": ua,
}), &result)
setCookie(jar, page, "___utmvc", result.Value, "")
```

```typescript TypeScript theme={null}
const jar = (await site.getCookiesFromSession(site.getSession(), PAGE)).cookies ?? [];
const cookieString = jar.map((c) => `${c.name}=${c.value}`).join("; ");
const result = await roolinkPost("/utmvc", { script: script.body, cookies: cookieString, userAgent: UA });
await site.addCookiesToSession(site.getSession(), PAGE, [{ name: "___utmvc", value: result.value, domain: host, path: "/" }]);
```

**3. Activate it**

Make one `GET` to the resource endpoint with the `SWKMTFSR` parameter and a random number, through the same session:

```http theme={null}
GET /_Incapsula_Resource?SWKMTFSR=1&e=0.8123456789 HTTP/2
```

If the cookie is accepted, the response clears `___utmvc` (it sets it to `a` with a zero lifetime) and upgrades the session cookies. That is success; the cleared cookie is expected.

**4. Load the page**

Request the page again. It should serve the real content. The session cookies now carry the trust, so you do not need to repeat this flow until the site challenges you again.

## Response fields

| Field | What it is |
| - | - |
| `name` | Always `___utmvc`. |
| `value` | The cookie value to set. |
| `cookie` | The same, as a `___utmvc=<value>` fragment ready for a `Cookie` header. |
| `setCookie` | A full `Set-Cookie` line, if you prefer to feed your jar that way. |
| `fingerprint`, `digest`, `signature`, `salt`, `key`, `version`, `windowKeyCount` | How the value was built. Informational. |

## Request fields

| Field | Required | What it does |
| - | - | - |
| `script` | yes | The `_Incapsula_Resource` script exactly as fetched. |
| `cookies` | yes | The session's cookies as a `document.cookie` string. An empty string is accepted but produces a value bound to no session. |
| `userAgent` | yes | The User-Agent your requests send. Roolink builds the value from a real collected browser with this exact User-Agent. |

## Troubleshooting

> [accordion] The activation request does not clear the cookie
>
> The value was not accepted. The usual cause is a `cookies` string that did not include the current `incap_ses_*` cookies, or included stale ones from an earlier session. Rebuild the string from the jar immediately before the call.

> [accordion] The page still shows the Incapsula block after activation
>
> Confirm the activation request went through the same session and proxy as the page load. If it did, the site is also running Reese84; look for the sensor script and follow the [Quickstart](https://docs.roolink.io/imperva/quickstart.md).

> [accordion] Roolink answers 422
>
> The script body is not a UTMVC script Roolink can parse, usually because it was re-encoded or truncated. Send it exactly as received.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.