Content Security Policy (CSP)
Hyperscape implements a strict Content Security Policy to protect against XSS and other web vulnerabilities.Overview
The CSP is configured inpackages/client/vite.config.ts and enforced via HTTP headers in production deployments.
Current Policy
script-src
'self'- Same origin scripts'unsafe-inline'- Inline scripts (required for Vite HMR)'unsafe-eval'- eval() (required for WASM and some libraries)https://esm.sh- ES module CDNhttps://cdn.jsdelivr.net- CDN for dependencieshttps://unpkg.com- npm package CDNhttps://static.cloudflareinsights.com- Cloudflare analytics
style-src
'self'- Same origin styles'unsafe-inline'- Inline styles (required for styled-components)https://fonts.googleapis.com- Google Fonts CSS
font-src
'self'- Same origin fontsdata:- Data URLs for embedded fontshttps://fonts.gstatic.com- Google Fonts files
img-src
'self'- Same origin imagesdata:- Data URLs for embedded imagesblob:- Blob URLs for generated imageshttps://*.r2.cloudflarestorage.com- Cloudflare R2 CDNhttps://assets.hyperscape.club- Asset CDN
connect-src
'self'- Same origin connectionsws://localhost:*/wss://localhost:*- Local WebSocket (development)ws://*.hyperscape.gg/wss://*.hyperscape.gg- Production WebSockethttps://*.hyperscape.gg- Production APIhttps://api.privy.io- Privy authenticationhttps://auth.privy.io- Privy auth endpoints
worker-src
'self'- Same origin workersblob:- Blob URLs for workersdata:- Data URLs for WASM workers
child-src
frame-src
'self'- Same origin iframeshttps://verify.walletconnect.com- WalletConnect verificationhttps://verify.walletconnect.org- WalletConnect verificationhttps://auth.privy.io- Privy auth iframe
Recent Changes
February 2026 Updates
1. Cloudflare Insights Support
Commit:1b2e230bdb613dd3d1b04c12ae2c3d36ee3f0f81
Added https://static.cloudflareinsights.com to script-src for Cloudflare analytics.
2. Google Fonts Support
Commit:e012ed2203cf0e2d5b310aaf6ee0d60d0e056e8c
Added:
https://fonts.googleapis.comtostyle-srchttps://fonts.gstatic.comtofont-src
3. WASM Data URLs
Commit:8626299c98d3d346eaa6fcae63d9f27ef5f92c37
Added data: to worker-src for WASM loading.
Reason: PhysX WASM module uses data URLs for worker initialization.
Configuration
Vite Configuration
CSP is configured inpackages/client/vite.config.ts:
Production Headers
For Cloudflare Pages, CSP is set inpackages/client/public/_headers:
Troubleshooting
CSP Violation Errors
Symptom: Console shows CSP violation warnings Example:- Identify the blocked resource
- Verify it’s necessary and trusted
- Add to appropriate CSP directive
- Test in development
- Deploy to production
WASM Loading Blocked
Symptom: PhysX or other WASM modules fail to load Error:data: is in worker-src directive.
Font Loading Blocked
Symptom: Google Fonts don’t load Solution: Verify both directives are set:Security Best Practices
1. Minimize ‘unsafe-*’ Directives
Current necessary uses:'unsafe-inline'- Required for styled-components and Vite HMR'unsafe-eval'- Required for WASM and some dependencies
- Using nonces for inline scripts
- Migrating away from eval-dependent libraries
2. Restrict CDN Sources
Only allow trusted CDNs:- ✅
esm.sh- ES module CDN (trusted) - ✅
cdn.jsdelivr.net- npm CDN (trusted) - ✅
unpkg.com- npm CDN (trusted) - ❌
cdn.example.com- Unknown CDN (blocked)
3. Use Subresource Integrity (SRI)
For external scripts, use SRI hashes:4. Monitor CSP Reports
Future: Enable CSP reporting to track violations:Testing
Validate CSP
Test CSP Violations
References
- Configuration:
packages/client/vite.config.ts - Production Headers:
packages/client/public/_headers - CSP Spec: MDN Content Security Policy
- CSP Evaluator: Google CSP Evaluator