-
Notifications
You must be signed in to change notification settings - Fork 207
CSP configuration and whitelist domains #1090
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
1a822c2
add CSP config page to docs.json
ethanpalm f99b40a
Create csp-configuration.mdx
ethanpalm 3b6eeab
update description
ethanpalm fe7f05e
add CSP header definitions
ethanpalm 2b6fad4
update conceptual info
ethanpalm 63ad984
combine testing/verification
ethanpalm b464ae5
update troubleshooting
ethanpalm f7ae744
use accordions for troubleshooting
ethanpalm 93fc558
: isntead of -
ethanpalm c39a3a4
update whitelist table
ethanpalm aff666d
💅
ethanpalm 1e3eef7
style and concision
ethanpalm b76ec6b
simplify troubleshooting
ethanpalm 42b6a03
remove protocol
ethanpalm cc2044c
remove protocol
ethanpalm 6d7f497
add `'unsafe-eval'`
ethanpalm 3110072
add blob in img-src
ethanpalm 3b8810b
make it more clear this is an edge case
ethanpalm 0992263
style
ethanpalm f1b7db3
update Cloudflare steps
ethanpalm 65c2e26
remove deprecated widget
ethanpalm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
--- | ||
title: "Content Security Policy (CSP) configuration" | ||
sidebarTitle: "CSP configuration" | ||
description: "Domain whitelist and header configurations for reverse proxies, firewalls, and networks that enforce strict security policies" | ||
--- | ||
|
||
Content Security Policy (CSP) is a security standard that helps prevent cross-site scripting (XSS) attacks by controlling which resources a web page can load. Mintlify serves a default CSP that protects most sites. If you host your documentation behind a reverse proxy or firewall, that overwrites the default CSP, you may need to configure CSP headers for features to function properly. | ||
|
||
## CSP directives | ||
|
||
The following CSP directives are used to control which resources can be loaded: | ||
|
||
- `script-src`: Controls which scripts can be executed | ||
- `style-src`: Controls which stylesheets can be loaded | ||
- `font-src`: Controls which fonts can be loaded | ||
- `img-src`: Controls which images, icons, and logos can be loaded | ||
- `connect-src`: Controls which URLs can be connected to for API calls and WebSocket connections | ||
- `frame-src`: Controls which URLs can be embedded in frames or iframes | ||
- `default-src`: Fallback for other directives when not explicitly set | ||
|
||
## Domain whitelist | ||
|
||
| Domain | Purpose | CSP directive | Required | | ||
|:-------|:--------|:--------------|:-------| | ||
| `d4tuoctqmanu0.cloudfront.net` | KaTeX CSS, fonts | `style-src`, `font-src` | Required | | ||
| `*.mintlify.dev` | Documentation content | `connect-src` | Required | | ||
| `d3gk2c5xim1je2.cloudfront.net` | Icons, images, logos | `img-src` | Required | | ||
| `unpkg.com` | Mintlify widget scripts | `script-src` | Required | | ||
| `www.googletagmanager.com` | Google Analytics/GTM | `script-src`, `connect-src` | Optional | | ||
| `cdn.segment.com` | Segment analytics | `script-src`, `connect-src` | Optional | | ||
| `plausible.io` | Plausible analytics | `script-src`, `connect-src` | Optional | | ||
| `tag.clearbitscripts.com` | Clearbit tracking | `script-src` | Optional | | ||
| `cdn.heapanalytics.com` | Heap analytics | `script-src` | Optional | | ||
| `chat.cdn-plain.com` | Plain chat widget | `script-src` | Optional | | ||
| `chat-assets.frontapp.com` | Front chat widget | `script-src` | Optional | | ||
|
||
## Example CSP configuration | ||
|
||
<Note> | ||
Only include domains for services that you use. Remove any analytics domains that you have not configured for your documentation. | ||
</Note> | ||
|
||
```text wrap | ||
Content-Security-Policy: | ||
default-src 'self'; | ||
script-src 'self' 'unsafe-inline' 'unsafe-eval' unpkg.com www.googletagmanager.com cdn.segment.com plausible.io tag.clearbitscripts.com cdn.heapanalytics.com | ||
chat.cdn-plain.com chat-assets.frontapp.com; | ||
style-src 'self' 'unsafe-inline' d4tuoctqmanu0.cloudfront.net; | ||
font-src 'self' d4tuoctqmanu0.cloudfront.net; | ||
img-src 'self' data: blob: d3gk2c5xim1je2.cloudfront.net; | ||
connect-src 'self' *.mintlify.dev www.googletagmanager.com cdn.segment.com plausible.io; | ||
frame-src 'self' *.mintlify.dev; | ||
``` | ||
|
||
## Common configurations by proxy type | ||
|
||
Most reverse proxies support adding custom headers. | ||
|
||
### Cloudflare configuration | ||
|
||
Create a Response Header Transform Rule: | ||
|
||
1. In your Cloudflare dashboard, go to **Rules > Overview**. | ||
2. Select **Create rule > Response Header Transform Rule**. | ||
3. Configure the rule: | ||
- **Modify response header**: Set static | ||
- **Header name**: `Content-Security-Policy` | ||
- **Header value**: | ||
```text wrap | ||
default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' unpkg.com; style-src 'self' 'unsafe-inline' d4tuoctqmanu0.cloudfront.net; font-src 'self' d4tuoctqmanu0.cloudfront.net; img-src 'self' data: blob: d3gk2c5xim1je2.cloudfront.net; connect-src 'self' *.mintlify.dev; frame-src 'self' *.mintlify.dev; | ||
``` | ||
4. Deploy your rule. | ||
|
||
### AWS CloudFront configuration | ||
|
||
Add a response headers policy in CloudFront: | ||
|
||
```json | ||
{ | ||
"ResponseHeadersPolicy": { | ||
"Name": "MintlifyCSP", | ||
"Config": { | ||
"SecurityHeadersConfig": { | ||
"ContentSecurityPolicy": { | ||
"ContentSecurityPolicy": "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' unpkg.com; style-src 'self' 'unsafe-inline' d4tuoctqmanu0.cloudfront.net; font-src 'self' d4tuoctqmanu0.cloudfront.net; img-src 'self' data: blob: d3gk2c5xim1je2.cloudfront.net; connect-src 'self' *.mintlify.dev; frame-src 'self' *.mintlify.dev;", | ||
"Override": true | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
### Vercel configuration | ||
|
||
Add to your `vercel.json`: | ||
|
||
```json | ||
{ | ||
"headers": [ | ||
{ | ||
"source": "/(.*)", | ||
"headers": [ | ||
{ | ||
"key": "Content-Security-Policy", | ||
"value": "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' unpkg.com; style-src 'self' 'unsafe-inline' d4tuoctqmanu0.cloudfront.net; font-src 'self' d4tuoctqmanu0.cloudfront.net; img-src 'self' data: blob: d3gk2c5xim1je2.cloudfront.net; connect-src 'self' *.mintlify.dev; frame-src 'self' *.mintlify.dev;" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
``` | ||
|
||
## Troubleshooting | ||
|
||
Identify CSP violations in your browser console: | ||
|
||
1. Open your browser's Developer Tools. | ||
2. Go to the **Console** tab. | ||
3. Look for errors starting with: | ||
- `Content Security Policy: The page's settings blocked the loading of a resource` | ||
- `Refused to load the script/stylesheet because it violates the following Content Security Policy directive` | ||
- `Refused to connect to because it violates the following Content Security Policy directive` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.