Skip to content

Commit 496b06a

Browse files
Copilotdanielpaul
andcommitted
Add CSP documentation page with nonce configuration guide
Co-authored-by: danielpaul <333233+danielpaul@users.noreply.github.com>
1 parent 49c6dda commit 496b06a

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

docs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@
6262
"docs/features/identify-users",
6363
"docs/advanced/custom-update-consent-button",
6464
"docs/advanced/custom-css",
65-
"docs/advanced/callbacks-events"
65+
"docs/advanced/callbacks-events",
66+
"docs/advanced/content-security-policy"
6667
]
6768
}
6869
]
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
title: "Content Security Policy (CSP)"
3+
description: "Configure CookieChimp to work with Content Security Policy using nonce attributes."
4+
icon: "shield"
5+
---
6+
7+
If your website uses Content Security Policy (CSP) with a `nonce` attribute, you can configure CookieChimp to work with it by adding a nonce to our script tag.
8+
9+
## How it Works
10+
11+
1. Add a `nonce` attribute to the CookieChimp script tag with your server-generated nonce value.
12+
2. CookieChimp will automatically detect the nonce and apply it to all dynamically created CSS and JavaScript elements.
13+
3. This ensures all our resources comply with your CSP policy.
14+
15+
## Example with Nonce
16+
17+
```html
18+
<script nonce="YOUR_SERVER_NONCE" src="https://cookiechimp.com/widget/abc123.js"></script>
19+
```
20+
21+
<Note>
22+
Replace `YOUR_SERVER_NONCE` with a cryptographically secure random value generated by your server for each page request.
23+
</Note>
24+
25+
## Required CSP Headers
26+
27+
Your Content-Security-Policy header must allow CookieChimp resources. Here's a recommended configuration:
28+
29+
```text
30+
Content-Security-Policy:
31+
script-src 'nonce-YOUR_SERVER_NONCE' https://cookiechimp.com https://*.cookiechimp.com;
32+
style-src 'nonce-YOUR_SERVER_NONCE' https://cookiechimp.com https://*.cookiechimp.com;
33+
connect-src https://cookiechimp.com https://*.cookiechimp.com;
34+
frame-src https://cookiechimp.com https://*.cookiechimp.com;
35+
```
36+
37+
### CSP Directives Explained
38+
39+
- `script-src` - Allows our widget script and dependencies from cookiechimp.com
40+
- `style-src` - Allows consent modal stylesheets from cookiechimp.com
41+
- `connect-src` - Allows API requests to log consent and fetch translations
42+
- `frame-src` - Allows rendering the preferences modal and embedding the privacy portal vendor list
43+
44+
<Tip>
45+
If you're using additional features like Meta Pixel integration, you may need to add `https://connect.facebook.net` to your `script-src` directive.
46+
</Tip>

0 commit comments

Comments
 (0)