CSP tells browsers what resources can load and execute.
Example policy:
Content-Security-Policy:
default-src 'self';
script-src 'self' cdn.example.com;
style-src 'self' 'unsafe-inline';
Directives:
- script-src: Where scripts can load from
- style-src: Where styles can load from
- img-src: Where images can load from
- connect-src: Where fetch/XHR can connect
Benefits: Blocks injected scripts even if XSS vulnerability exists.
Interview tip: Mention CSP as defense-in-depth against XSS.