Content Security Policy
Add TalkJS domains to your Content Security Policy allow list.
If you use a Content Security Policy (CSP) header, you may need to add TalkJS to an allow list. The rules you need depend on which TalkJS SDK you use:
- The React components and Web Components run chat directly in your page.
- The Classic SDKs run chat inside an iframe.
The CSP directives each SDK needs, without the optional ones.
We recommend *.talkjs.com over a specific subdomain like app.talkjs.com, because we may change which data gets served from which subdomains in the future.
The Web Components and React components don't use an iframe, so you don't need frame-src. They still connect to TalkJS and load a few files at runtime, even when you install them from npm:
- connect-src: The components connect to the TalkJS servers over HTTPS and secure WebSockets, and the emoji picker loads its emoji data from jsDelivr:
connect-src https://*.talkjs.com wss://*.talkjs.com https://cdn.jsdelivr.net
- script-src: The emoji picker loads its code from jsDelivr:
script-src https://cdn.jsdelivr.net
- style-src: The emoji picker adds its own
<style>elements, sostyle-srcneedsunsafe-inline:style-src 'unsafe-inline'
- font-src: The components use the Inter font from the TalkJS CDN, unless your page already loads Inter:
font-src https://*.talkjs.com
If you load the components from jsDelivr, as the installation guide does, add https://cdn.jsdelivr.net to style-src for their stylesheet. The import map and module script from that guide are inline scripts, so give them a nonce or a hash in script-src. Here's the full policy for that setup. Replace <nonce> with your nonce:
Content-Security-Policy: default-src 'self'; script-src 'self' 'nonce-<nonce>' https://cdn.jsdelivr.net; connect-src 'self' https://*.talkjs.com wss://*.talkjs.com https://cdn.jsdelivr.net; style-src 'self' 'unsafe-inline' https://cdn.jsdelivr.net; font-src https://*.talkjs.com; img-src 'self' https://*.talkjs.comIf you signed up with TalkJS before October 2025, you're likely using one of the Classic SDKs, which run chat inside an iframe. The rules below are only for those SDKs.
The simplest way to allow the Classic SDKs is to add TalkJS to your default-src directive:
Content-Security-Policy: default-src https://*.talkjs.com wss://*.talkjs.com https://firebasestorage.googleapis.comThe Classic SDKs don't require unsafe-inline or unsafe-eval in script-src.
Note: If you followed the Classic JavaScript SDK's Getting Started guide to the letter, you'll have added one or two <script> elements.
You'll need to move that code into a .js file before it'll work with a CSP header that disallows unsafe-inline.
If you need more control than default-src, you can further specify things per directive:
- script-src: Allow loading TalkJS JavaScript files:
script-src https://*.talkjs.com
- connect-src: Let our SDK connect directly to the TalkJS servers via HTTPS and secure WebSockets:
connect-src https://*.talkjs.com wss://*.talkjs.com
- frame-src: Let TalkJS mount an iframe with the chat UI:
frame-src https://*.talkjs.com
You may omit these if you do not depend on the features listed:
- The Popup loads a little bit of CSS and two SVG images into your page:
img-src https://*.talkjs.comstyle-src https://*.talkjs.com
- file sharing uses Google Cloud. If you use file sharing, also add this:
img-src https://firebasestorage.googleapis.com https://*.tjstatic.netmedia-src https://firebasestorage.googleapis.com https://tjstatic.net
- notifications play a sound (if desktop notifications are enabled):
media-src https://*.talkjs.com
- Error Tracking TalkJS uses TrackJS to keep track of errors in the client.
script-src https://cdn.trackjs.com; connect-src https://capture.trackjs.com; img-src https://usage.trackjs.com; img-src https://fault.trackjs.com
All the optional and required directives shown above make up this CSP policy:
default-src 'none';
script-src https://*.talkjs.com;
connect-src https://*.talkjs.com wss://*.talkjs.com;
frame-src https://*.talkjs.com;
media-src https://*.talkjs.com https://firebasestorage.googleapis.com https://*.tjstatic.net;
style-src https://*.talkjs.com;
img-src https://*.talkjs.com https://firebasestorage.googleapis.com https://*.tjstatic.net;
script-src https://cdn.trackjs.com; connect-src https://capture.trackjs.com; img-src https://usage.trackjs.com; img-src https://fault.trackjs.comOr, as a valid single-line HTTP header:
Content-Security-Policy: default-src 'none'; script-src https://*.talkjs.com https://cdn.trackjs.com; connect-src https://*.talkjs.com wss://*.talkjs.com https://capture.trackjs.com; frame-src https://*.talkjs.com; media-src https://*.talkjs.com https://firebasestorage.googleapis.com; style-src https://*.talkjs.com; img-src https://*.talkjs.com https://firebasestorage.googleapis.com https://fault.trackjs.com https://usage.trackjs.com;