Content Security Policy
Minimum Required Policy
Add these directives to your CSP header:Directive Breakdown
| Directive | Values | Purpose |
|---|---|---|
connect-src | https://*.meetchar.ai | HTTPS API requests |
connect-src | wss://*.meetchar.ai | WebSocket connection to Tool Hub |
script-src | https://unpkg.com | Agent script from CDN |
style-src | 'unsafe-inline' | Agent component styles |
About 'unsafe-inline' for Styles
The Char agent uses web components with shadow DOM, which inject styles dynamically. This currently requires 'unsafe-inline' in style-src.
While
'unsafe-inline' weakens CSP protection against style-based attacks, the primary security value of CSP comes from restricting script-src. Style injection attacks are significantly less severe than script injection. See OWASP CSP Cheat Sheet for context.'unsafe-inline', contact us about self-hosting options.
Self-Hosted Agent
If you bundle the agent with your application instead of loading from CDN:unpkg.com in script-src.
Strict CSP Starting Point
For applications starting with a strict policy, here’s a complete example:default-src 'none' and explicitly allowing only what’s needed is the recommended approach.
CORS Configuration
The Char API includes appropriate CORS headers for browser requests. Your server doesn’t need to proxy Char API calls.Reverse Proxy Considerations
If you’re running a reverse proxy or API gateway, ensure it doesn’t strip CORS headers from Char API responses: Nginx:CORS vs CSP
These are different mechanisms:| Mechanism | Controls | Direction |
|---|---|---|
| CORS | Which origins can read responses | Server → Browser |
| CSP | Which resources the page can load | Page → Browser |
connect-src does not bypass CORS. Both must allow the connection.
Troubleshooting
”Refused to connect to wss://”
Cause: WebSocket URL not inconnect-src.
Fix: Add wss://*.meetchar.ai to connect-src. Note that 'self' does not cover WebSocket schemes.
”Refused to load the script”
Cause: Script source not allowed byscript-src.
Fix: Add https://unpkg.com to script-src, or self-host the agent.
”Refused to apply inline style”
Cause:style-src doesn’t allow inline styles.
Fix: Add 'unsafe-inline' to style-src. This is currently required for the agent’s web components.
Agent loads but API calls fail
Cause: Reverse proxy stripping CORS headers. Fix: Configure your proxy to pass throughAccess-Control-* headers. Check the Network tab — responses should include Access-Control-Allow-Origin.
Mixed content errors
Cause: Page loaded over HTTPS but trying to connect via HTTP. Fix: Ensure all Char URLs usehttps:// and wss:// (not http:// or ws://).
Verifying Your Configuration
Open browser developer tools and check:- Console — No CSP violation errors (red text mentioning “Content Security Policy”)
- Network → Filter by “WS” — WebSocket connection shows status 101
- Network → Filter by domain — Requests to
meetchar.aireturn 200

