HTTP headers and security headers explained

How to read HTTP response headers and redirects, and what HSTS, CSP, X-Frame-Options and the other security headers do.

Every time a browser fetches a page, the server sends a set of response headers before the content itself. They tell the browser what kind of content it is getting, how long it may be cached, where to go next if the page has moved – and, increasingly, which security rules to apply. The "Get HTTP headers" tool on webstriker shows all of them, follows every redirect, and points out missing security headers.

Status codes and redirects

The first line of a response contains the status code:

webstriker requests one URL at a time and shows each step of the redirect chain separately. A good setup reaches the final page in one redirect – for example http://example.com → https://www.example.com/. Chains like http → https → www → /en/ → /en/home cost time on every first visit and are worth shortening.

Useful everyday headers

Advertisement

The security headers

Strict-Transport-Security (HSTS). Tells the browser to use HTTPS for this site for a period of time, even if someone types or links to http://. Example: max-age=31536000; includeSubDomains. Only send it once HTTPS works everywhere, including all subdomains if you use includeSubDomains – the browser will refuse plain HTTP for the full max-age.

Content-Security-Policy (CSP). The most powerful and the most work. It lists where scripts, styles, images, frames and other resources may be loaded from, which makes cross-site scripting attacks far harder. A strict CSP needs to be tailored to each site; start with Content-Security-Policy-Report-Only to see what would break before enforcing it. Sites with advertising or many third-party scripts need a broad policy.

X-Content-Type-Options: nosniff. Stops browsers from guessing the content type and, for example, executing an uploaded text file as a script. There is no reason not to set it.

X-Frame-Options (DENY or SAMEORIGIN) – or the modern equivalent, frame-ancestors in CSP. Prevents other sites from embedding yours in a frame, which protects against clickjacking.

Referrer-Policy. Controls how much of the current URL is sent to other sites when a visitor follows a link. strict-origin-when-cross-origin is the browser default today and a sensible explicit choice.

Permissions-Policy. Switches off browser features the site does not use, such as camera, microphone or geolocation: camera=(), microphone=(), geolocation=().

How to add them

The certificate

For HTTPS addresses, webstriker also shows the TLS certificate: whom it was issued to, which authority issued it, its validity dates and the host names it covers. A certificate that does not include the exact host name, or that has expired, causes the browser warning that makes most visitors leave. The CAA record in DNS controls which authorities may issue certificates for the domain at all.

Key takeaways

Try it yourself:
Advertisement

More guides