Question
Does Segment Analytics.js support strict Content Security Policy (CSP) with per-request nonces, and are nonces propagated to scripts loaded by destinations?
Product
Segment
Environment
Segment Console
Answer
Analytics.js supports the use of strict Content Security Policy (CSP) with per-request nonces. When a nonce is included on the initial Analytics.js script tag, the same nonce is propagated to all scripts dynamically loaded by Analytics.js, including bundles and device-mode destination SDKs. In addition to allowing the main analytics.min.js script, your CSP should cover the following paths and endpoints:
- https://cdn.segment.com/v1/projects//settings
- https://cdn.segment.com/analytics-next/bundles/*
- https://cdn.segment.com/next-integrations/integrations/*
- api.segment.io
- cdn.segment.com
The nonce attribute on your Segment script tag must match the value specified in your CSP header. Nonces are propagated to the bundles and destination scripts that Analytics.js loads from cdn.segment.com at runtime. As long as your initial script tag includes the correct nonce, subsequent scripts injected by Analytics.js will also use the same nonce, ensuring compatibility with your strict CSP.