Skip to content
Web Design & Development

A Practical Guide to HTTP Security Headers

Response headers that tell the browser to enforce security rules for a site, such as which sources scripts may load from and whether the site must always be reached over HTTPS.

MediaScaleUp Editorial Team 2 min read 10 views
A Practical Guide to HTTP Security Headers

What is at stake

They are a cheap server-side layer of defense against common attacks such as cross-site scripting and clickjacking, and anyone can check them from outside in seconds.

The playbook

  1. Roll out Content-Security-Policy in report-only mode first
  2. Enable HSTS only once every subdomain serves HTTPS
  3. Send nosniff on every response
  4. Restrict framing unless the site is meant to be embedded
  5. Recheck headers after any CDN or hosting change

Where it goes wrong

Avoid:

  • Policies that allow unsafe-inline and so defeat their own purpose
  • Submitting to the HSTS preload list before all subdomains support HTTPS
  • Headers set on the origin server but stripped by the CDN
  • Copying another site's policy without testing it on yours
What to do and what to avoid with HTTP security headers, side by side
Good practice against the usual mistakes, from the sources listed below.

The numbers behind it

Published figures for HTTP Security Headers
MeasureFigure
Content-Security-Policylimits where scripts, styles, images and frames may load from
Strict-Transport-Securitytells browsers to use only HTTPS for the site for the max-age given
X-Content-Type-Options: nosniffstops browsers guessing a file's type from its content
Clickjacking protectionthe CSP frame-ancestors directive, or the older X-Frame-Options header
Referrer-Policycontrols how much of the current URL is sent to other sites

Getting outside help

When to hand it over: Bring in help when a security scan flags missing headers, when a CSP breaks third-party tools, or before enabling HSTS preload on a domain with many subdomains.

Where this comes from

The figures and practices above come from the sources listed.

Working on something like this?

We take on Web Design & Development work for teams who want it done once, properly. Tell us what you are building and we will tell you honestly whether we are the right studio for it. Start a project.

Where to go next

Spotted something wrong? Report an error on this page. We correct on the page and say what changed.

All services

The work behind this article, and what it costs.

MediaScaleUp Editorial Team

Articles here are researched, written and checked by the MediaScaleUp studio team before they are published, and dated when they are reviewed.

Keep reading

More in Web Design & Development