Guide

security headers best practices

Security headers work best when you set priorities instead of adding everything at once. Start with the headers that change browser behavior the most.

Recommended priority

  • Content-Security-Policy for resource loading rules.
  • Strict-Transport-Security to keep browsers on HTTPS.
  • X-Content-Type-Options: nosniff to reduce content-type abuse.
  • Referrer-Policy to reduce referrer leakage.
  • X-Frame-Options or frame-ancestors for anti-clickjacking.
  • Permissions-Policy to disable browser features you do not need.

Rollout order

  1. Ship CSP in report-only mode.
  2. Observe violations for one or two days.
  3. Whitelist real dependencies only.
  4. Replace unsafe inline allowances.
  5. Enforce CSP and keep monitoring.

Official references