Redirects and security headers
Updated
Typing a website's name rarely goes straight to the page. The browser usually asks for the plain http address first, is told to go to https, may be told to move from the bare name to www, and only then receives the page. Each step is a redirect, and each one costs the visitor a little time.
Redirects
- 301 and 308 mean a permanent move: browsers and search engines remember it
- 302 and 307 mean a temporary move: they ask again next time
- http should lead to https in one step, so anyone who skips the s is still protected
- A redirect that leads back to an earlier address is a loop, and the page never loads
What a header is
Along with the page, a server sends headers: small notes about the response. A few of them tell the visitor's browser to turn on protections, so they matter even though no one sees them.
- Strict-Transport-Security: use only https for this site from now on
- Content-Security-Policy: only load scripts and content from these places, which makes injected code much harder to run
- X-Content-Type-Options: nosniff: trust the declared type of a file instead of guessing
- X-Frame-Options or frame-ancestors: do not let other sites show this page inside a frame to trick clicks
- Referrer-Policy: share less of the page's address with the next site
Strict-Transport-Security: max-age=31536000; includeSubDomains X-Content-Type-Options: nosniff Referrer-Policy: strict-origin-when-cross-origin
What headers give away
Headers also tell visitors what a site is built with. The Server header often names the web server, X-Powered-By can name a language or framework, and cookie names or special headers can point to a platform or content system. Sites can hide all of this, and hiding it is a small hardening step, since it stops advertising which software version to attack.
Adding them
Each header is a line in the web server's or hosting service's settings. Add them one at a time and test, because a strict Content-Security-Policy can block scripts the site itself needs. Start with the easy ones: nosniff, a framing rule and a referrer policy, then Strict-Transport-Security, then a policy.
Good to know. Headers tell the browser to help protect the visitor. They do not make a site secure, and a site with all of them can still have other weaknesses.
Related
- TLS certificates explainedWhat the padlock in a browser means, how a certificate and its chain prove a site is genuine, why they expire, and the usual reasons one fails.
- Who hosts a website, and what a CDN hidesHow a domain name leads to a hosting network, why the answer is often a content delivery network, and what you can and cannot learn from it.
- A domain health checklist: what to check and whyThe handful of public records that say whether a domain is set up sensibly for email, registration and DNS, and what each one protects against.