Glossary
SECURITY HEADERS

CSP

Content Security Policy — an HTTP response header that whitelists trusted sources of scripts, styles, images, and connections. The single biggest anti-XSS defence.

CSP (Content Security Policy, W3C spec + RFC 7762) is an HTTP response header that tells browsers which sources of scripts, styles, images, fonts, connections, and frames are trusted. When properly deployed, CSP eliminates the vast majority of XSS attacks even when the underlying application has an injection vulnerability.

Header Format

Content-Security-Policy: default-src 'self'; script-src 'self' https://cdn.example.com; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; frame-ancestors 'none';

Common Directives

DirectivePurpose
default-srcFallback for every fetch directive
script-srcAllowed script sources
style-srcAllowed CSS sources
img-srcAllowed image sources
connect-srcAllowed fetch / XHR / WebSocket targets
frame-ancestorsWho can embed this page in a frame (replaces X-Frame-Options)
report-uri / report-toWhere to send violation reports

Deployment Pattern

Start with Content-Security-Policy-Report-Only — same syntax, no blocking, sends violation reports. Watch reports for a week. Fix real violations. Then flip to enforcing Content-Security-Policy.

Common Miss

  • 'unsafe-inline' on script-src — kills most of CSP’s XSS protection
  • Missing frame-ancestors — clickjacking still possible via X-Frame-Options gaps

Validate your CSP with the security headers audit.

Check the HSTS glossary entry, the X-Frame-Options entry, and read the HTTP security headers explainer.