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

# Content Security Policy (CSP)

The Content-Security-Policy HTTP response header helps you reduce XSS risks on modern browsers by declaring which dynamic resources are allowed to load.

If you are making use of CSP, you must add the following directives to your CSP header:

```javascript theme={null}
frame-src 'self' https://*.gleap.io;
```

```javascript theme={null}
script-src 'self' 'unsafe-inline' https://*.gleap.io;
```

```javascript theme={null}
style-src 'self' 'unsafe-inline' https://*.gleap.io;
```

```javascript theme={null}
font-src 'self' https://*.gleap.io data:;
```

```javascript theme={null}
connect-src 'self' https://*.gleap.io wss://ws.gleap.io wss://sockets.gleap.io;
```

```javascript theme={null}
media-src 'self' https://*.gleap.io;
```

```javascript theme={null}
img-src 'self' https://*.gleap.io data: blob:;
```

<Note>
  `script-src` needs `'unsafe-inline'` **or** a nonce (see [Nonce-based and `strict-dynamic` policies](#nonce-based-and-strict-dynamic-policies) below). The SDK loads the messenger into a frame that inherits your page's policy, and it writes one small inline script into that frame to set the messenger's route. Without `'unsafe-inline'` or a nonce that inline script is blocked, and features that open on a specific route (banners, modals, direct links to a conversation) can render the wrong view. If you would rather not allow `'unsafe-inline'` at all, use a nonce.
</Note>

<Info>
  We strongly recommend using the `https://*.gleap.io` and `wss://*.gleap.io` wildcards. The SDK contacts several Gleap subdomains (`api.gleap.io`, `ws.gleap.io`, `sockets.gleap.io`, `messenger-app.gleap.io`, `outboundmedia.gleap.io`, `app.gleap.io`, `js.gleap.io`), and the list may grow as we ship new features. Note that the `https://` wildcard does **not** cover WebSocket connections — `wss://` origins must be allowed separately.
</Info>

### WebSockets in `connect-src`

Gleap uses two WebSocket endpoints, and both must be allowed:

* `wss://ws.gleap.io` — session and event streaming used by the JavaScript SDK.
* `wss://sockets.gleap.io` — realtime delivery of conversations and notifications in the messenger.

If you'd rather not list them individually, allow `wss://*.gleap.io`.

<Note>
  Gleap previously relied on [Pusher](https://pusher.com) for realtime messaging, which required `*.pusher.com` entries in `connect-src`. Realtime traffic now runs entirely on Gleap infrastructure (`wss://sockets.gleap.io`), so any `https://*.pusher.com` or `wss://*.pusher.com` entries you added for Gleap can be removed.
</Note>

### Nonce-based and `strict-dynamic` policies

If your policy is nonce-based, the SDK can carry your nonce on everything it creates, including the messenger bundle and the inline route script described above. This requires SDK **16.3.4 or newer**.

The simplest setup is to put your nonce on the SDK's own `<script>` tag. The SDK reads it from there automatically, and no further configuration is needed:

```html theme={null}
<script nonce="YOUR_NONCE" src="https://sdk.gleap.io/latest/index.js"></script>
```

If your loader cannot put the nonce on that tag (some tag managers and bundlers cannot), pass it explicitly **before** calling `Gleap.initialize()`:

```javascript theme={null}
Gleap.setCSPNonce("YOUR_NONCE");
Gleap.initialize("YOUR_API_KEY");
```

With a nonce in place you no longer need `'unsafe-inline'` in `script-src`, and you do not need to allowlist a content hash for the inline script.

<Warning>
  If your policy uses `'strict-dynamic'`, a nonce is **required**. `'strict-dynamic'` tells the browser to ignore host-based sources entirely, so `https://*.gleap.io` in `script-src` / `script-src-elem` has no effect and the messenger will not load without one. Hash-pinning the messenger bundle is not a workaround: its filename carries a build hash that changes with every release, and a hash source for an external script is only honored when the tag also carries a matching `integrity` attribute.
</Warning>

Note that `'strict-dynamic'` only applies to script directives. `frame-src`, `connect-src`, `img-src`, `font-src` and `media-src` still need the origins listed above.

### Strict CSPs without wildcards

If your security policy forbids wildcards, here is the full explicit allowlist the SDK uses today:

```javascript theme={null}
https://api.gleap.io
wss://ws.gleap.io
wss://sockets.gleap.io
https://js.gleap.io
https://app.gleap.io
https://messenger-app.gleap.io
https://outboundmedia.gleap.io
```

<Warning>
  This explicit list can change without notice as we add features or migrate infrastructure. The `https://*.gleap.io` and `wss://*.gleap.io` wildcards are the safest choice.
</Warning>

Depending on your setup you might need to do some further customizations. Please check the browser console for any CSP errors and add the reported origins to the matching directive.
