Development3 min read

Website Security Headers Explained

Understand CSP, HSTS, framing, referrer controls, permissions policy, and how to roll security headers out safely.

HTTP security headers tell browsers how a site expects content, framing, transport, and certain browser capabilities to behave. They are not a complete security system, but they can reduce the impact of common web mistakes when configured carefully.

Start with transport and content rules

Strict-Transport-Security tells supporting browsers to prefer HTTPS for the site after they have received the policy securely. Content-Security-Policy can restrict where scripts, styles, images, frames, and connections may come from. A strong CSP can reduce some cross-site scripting impact, but a careless policy can also break legitimate application behavior.

Control framing and information leakage

  • Use frame-ancestors in Content Security Policy to define whether other sites may frame your pages.
  • Use Referrer-Policy to limit how much URL information is sent as a referrer.
  • Use X-Content-Type-Options: nosniff to reduce MIME-type guessing.
  • Use Permissions-Policy to restrict browser capabilities the site does not need.

Roll out Content Security Policy safely

Sites with analytics, advertising, embedded media, and third-party widgets often need several external origins. Start by inventorying those dependencies. A report-only policy can help reveal required sources before enforcing a stricter policy, but reports should be reviewed because they can be noisy.

Avoid solving CSP errors by allowing every origin or broadly enabling unsafe script execution. That may restore functionality while removing much of the protection the policy was meant to provide.

Test the deployed response

Headers are an HTTP response property, so check the production response rather than only framework configuration. CDN rules, reverse proxies, and hosting platforms can add, remove, or override them after application code runs.

Sources and further reading

Primary documentation and references used to support this guide.