Content Security Policy for the Lucida browser SDK
A site with a strict Content-Security-Policy must allow the hosts the SDK talks to. Below, https://lc.example.com stands for your apiHost (the gateway, or...
A site with a strict Content-Security-Policy must allow the hosts the SDK talks to. Below, https://lc.example.com stands for your apiHost (the gateway, or your reverse proxy, see the self-hosting reverse-proxy guide). https://app.example.com stands for uiHost, the Lucida app/API host the toolbar talks to. If you leave uiHost unset, the toolbar uses apiHost instead.
The short version for each framework (install, init, CSP, proxy, consent) is on Install by framework. This page is the full list of directives.
Lucida does not collect CSP violation reports. Report ingestion belongs to Watchtower.
Minimal policy (capture, flags, replay, heatmaps)
script-src 'self';
connect-src 'self' https://lc.example.com;script-src: serve the SDK bundle yourself (npm build or
dist/lucida.js). Replay, the toolbar, the experiment editor and resource-center modules are lazy chunks. They load from the same origin as the bundle, so'self'(or your CDN host) covers them. The SDK never useseval, so it never needs'unsafe-eval'.connect-src: covers
/v1/capture,/v1/batch,/v1/replay(fetch, plussendBeaconon page hide),/v1/flags,/v1/flags/stream,/v1/configand/v1/guides. All of these go toapiHost.Hosted Lucida, npm package: every call above goes to
apiHost(https://capture.lucidace.com, or your proxy). The npm package never callshttps://lucidace.comon its own. That host is needed only (1) inscript-srcandconnect-srcfor the classic<script src="https://lucidace.com/lucida.js">loader and the modules andmanifest.jsonit fetches from there, and (2) inconnect-srcon pages where your team opens the toolbar (uiHost). The embed manifest (/.well-known/lucida-embed.json) has one surface per install:npm(onlyconnect-src https://capture.lucidace.com),browser(the classic snippet: both hosts) andtoolbar(https://lucidace.com). Itsstoragelist has one row per name and store, so it is longer than the list of names instorage.json; both come from the same file, andstorage.jsonis the source.worker-src: not needed for DOM replay, which compresses on the main thread. Only canvas recording (replay with
canvason and no canvas masking) starts oneblob:Web Worker, from the recorder's bundled rrweb code. If you record canvas under a strict CSP, addworker-src 'self' blob:.lucida doctor --site <url>warns when replay is on and the CSP givesblob:workers no source. It also fails when the site's origin is not incapture_allowed_origins.
Guides, web experiments and the toolbar
style-src 'self' 'nonce-{RANDOM}';
img-src 'self' https:;
media-src https:;
frame-src https://www.youtube-nocookie.com https://www.youtube.com https://player.vimeo.com https://www.loom.com https://fast.wistia.net;
connect-src 'self' https://lc.example.com https://app.example.com;style-src: guides (inside a shadow root) and the anti-flicker veil of web experiments each inject a
<style>element. Pass your per-response nonce to the SDK and every one of them carries it:init("lc_pk_...", { nonce: document.querySelector("meta[name=csp-nonce]")?.content });Without
noncethese elements need'unsafe-inline'. Note that browsers ignore'unsafe-inline'once a nonce or hash is listed, so a policy with a nonce always needs thenonceoption. The toolbar, the consent banner and appearance tokens style through CSSOM (element.style), which CSP does not restrict.Web-experiment custom code (per-variant page CSS and JS, P-H5): page CSS is a
<style>and page JS a<script>, both with the configurednonce, so a nonce-basedscript-src/style-srcadmits them without'unsafe-inline'. Page JS runs only when the project approved it (experiment.custom_codeapproval policy key: the API stampsapprovedon the change at start, and any value sent by a client is overwritten) and the site opts in withvisualChanges: { allowCustomJs: true }(default false). Inserted HTML is sanitized in the browser (no scripts, styles, frames, forms, SVG oron*handlers; links http(s), mailto, tel or relative; images http(s), relative or rasterdata:) and checked again by the API on save. Swapped images uploaded from the visual editor are served from{LC_PUBLIC_URL}/v1/experiment-assets/...; add that host toimg-src.img-src / media-src: guide media blocks load from the
httpsURLs authored in the guide. The SDK drops non-https media. To be stricter, list your asset hosts instead ofhttps:.frame-src: guide
embedblocks frame only the five hosts above, and the iframes are sandboxed. Omit any you do not use.connect-src: the toolbar calls
uiHost(/v1/toolbar/exchangeand the project API). AdduiHostonly for pages where your team opens the toolbar.script-src with modules: the classic script's
modulesoption loads ESM files fromassetHost(see Pinning the SDK version). Add that host toscript-src. A strict nonce-basedscript-srcwith'strict-dynamic'allows them, because the loader that imports them is trusted.
Checking
Open the page with the toolbar or ?__lc_debug=1, then look in the browser console for Refused to connect or Refused to load messages. Each message names the directive that blocked the request.
In debug mode the SDK adds its own hints (console only, nothing is sent):
CSP hint: this page's Content-Security-Policy blocks inline <style>: a<meta http-equiv="Content-Security-Policy">policy restricts inline styles and nononceis set. A policy sent as an HTTP header is invisible to scripts, so this check only sees meta policies.CSP hint: an inline style was blocked by style-src...: the browser refused a style. Setnonce, or check that it matches the nonce of the current response.
lucida doctor --site <url> checks the live page's policy against the loader script and the API host.
Capturing violations as events
Set captureCspViolations: true (or { maxPerPage: 50 }) to send a $csp_violation event for each violation the browser reports on the page: $csp_directive, $csp_blocked_uri, $csp_source_file (origin and path only, never a query string), $csp_line, $csp_column and $csp_disposition. The code sample and the referrer are never sent. Identical violations count once and a page sends at most 20 by default. It is off unless you set it, and respects consent like every other event. Blocked-resource reports from report-to endpoints and the full report pipeline stay in Watchtower.