Answer
CSP is an HTTP header (or <meta>) that whitelists where content can load from, reducing XSS blast radius even if attacker injects HTML.
Common directives:
default-src 'self'— fallback for other directivesscript-src 'self' 'nonce-abc123'— only trusted scriptsstyle-src,img-src,connect-src(XHR/fetch),frame-ancestors(clickjacking)report-uri/report-to— violation telemetry
Modes:
- Enforce — blocks violations
- Report-Only — logs without blocking (rollout)