How to Configure a Content Security Policy (CSP) for Captain Compliance

Edited

A Content Security Policy (CSP) is an HTTP response header that tells browsers which origins may load resources on your site. CSP is opt-in: if your site does not send a Content-Security-Policy header, no configuration is needed and Captain Compliance loads without restriction.

If your site does send a CSP, its directives must allow the Captain Compliance origins. Otherwise browsers may block Captain Compliance scripts, API calls, and geolocation lookups, and the consent banner can fail silently or log console errors.

Required origins

Origin

Purpose

*.cptn.co

Loads the Captain Compliance script bundle, posts consent records, and pulls banner styles and assets.

api.ipify.org

Returns the visitor’s public IP address as JSON. Used alongside Cloudflare headers to detect the visitor’s jurisdiction.

Directives to update

Add the origins to the directives your policy already uses. If your policy only sets default-src, add them there.

Directive

Add

Why

script-src

https://*.cptn.co

Loads the banner script and the regional consent defaults.

connect-src

https://*.cptn.co https://api.ipify.org

Sends API requests, consent records, and the geolocation lookup.

img-src

https://*.cptn.co

Loads banner images and assets.

style-src

'unsafe-inline'

The banner injects its styles as inline style elements at runtime. A style-src directive without this keyword blocks them.

frame-src

https://*.cptn.co

Only needed if you embed a hosted privacy notice in an iframe.

Example directives to merge into your existing policy:

script-src 'self' https://*.cptn.co;
connect-src 'self' https://*.cptn.co https://api.ipify.org;
img-src 'self' https://*.cptn.co;
style-src 'self' 'unsafe-inline';
frame-src 'self' https://*.cptn.co

If you deploy through Google Tag Manager, your policy must also allow GTM itself. See Google’s guide to using Tag Manager with a Content Security Policy.

Other Captain Compliance features

Verify

  1. Load your site in a private or incognito browser window.

  2. Open browser developer tools and select the Console tab.

  3. Look for Content Security Policy errors that mention cptn.co or ipify.org. Each error names the directive that blocked the request, so add the origin to that directive.

  4. Confirm the consent banner appears and responds to clicks.

Related articles