Engineering 4 min read Updated
HTTP security headers worth setting
In short
Set Strict-Transport-Security, X-Content-Type-Options, Referrer-Policy and Permissions-Policy, roll each one out in a safe order and check that nothing breaks.
Response headers tell the browser how to treat a page. Most of them are a single line in the server configuration, and they protect visitors without changing the page itself. Start with four headers that suit most sites: Strict-Transport-Security, X-Content-Type-Options, Referrer-Policy and Permissions-Policy. Frame embedding is controlled by the frame-ancestors directive in the Content Security Policy header, which has its own article.
HTTPS first, then HSTS
Strict-Transport-Security tells the browser to reach the host only over HTTPS and to upgrade any later HTTP attempt. The browser will not let the visitor click past a secure connection error, such as an invalid certificate. The rule applies to a domain name, not to an IP address. The header must be sent over HTTPS, because browsers ignore it on plain HTTP. An HTTP address should answer with a permanent redirect to HTTPS, and that redirect must not carry the header.
| Directive | Effect | Caution |
|---|---|---|
| max-age | How long, in seconds, the browser remembers the HTTPS-only rule | Each response resets the countdown, so keep the value fixed. max-age=0 switches the rule off, but only after a response received over HTTPS |
| includeSubDomains | Applies the rule to every subdomain | Each subdomain must also send the header and serve HTTPS |
| preload | Requests inclusion in browser preload lists | Needs a max-age of at least 31536000 and includeSubDomains. The list is maintained by Google but is not part of the specification |
Begin with a short max-age while you confirm that every host serves HTTPS, then raise it once the setup is stable. You cannot switch HSTS off over plain HTTP.
Stop MIME sniffing with one header
X-Content-Type-Options has one value, nosniff. With it, the browser blocks a script unless its MIME type is a JavaScript type, and it blocks a stylesheet unless the type is text/css. For every other response, the browser stops guessing the content type and uses the declared Content-Type. The header helps only when your server declares the correct type. A script or stylesheet with a wrong type stops working once nosniff is added, which lets you find the problem before visitors do.
Working on something similar in your own product? A few honest sentences are enough – we read every enquiry and reply by email. Apply with your idea
The default referrer is usually enough
Referrer-Policy controls how much of the current address the browser sends to the next site. When no policy is given or the value is invalid, the default strict-origin-when-cross-origin applies. Under it, a same-origin request sends the full path and query, an HTTPS request to another site sends only the origin, and a move from HTTPS to HTTP sends nothing. The no-referrer value omits the referrer entirely.
| Value | What the other site receives |
|---|---|
| strict-origin-when-cross-origin (default) | The full address for the same site; only the origin across HTTPS sites; nothing when moving from HTTPS to HTTP |
| no-referrer | Nothing |
Keep the default unless a page has a reason to reveal less, for example when its address contains a private identifier. Check the change against your analytics and any partner links that depend on the referrer.
Switch off browser features the site does not use
Permissions-Policy controls which browser features the page and its iframes may use, such as the camera, microphone and geolocation. Each directive takes an allowlist. An empty pair of brackets disables the feature everywhere, self allows only the same origin, and an asterisk allows any origin. MDN gives the example microphone=(), geolocation=(), which disables both features. MDN lists the header as having limited availability, so treat it as a hardening step rather than the only control.
Roll out in this order
- Confirm that every page is served over HTTPS, and that HTTP redirects permanently.
- Set HSTS with a short max-age first, then raise it towards one year.
- Add includeSubDomains only after every subdomain serves HTTPS.
- Add nosniff, then check that scripts and stylesheets are served with the right types.
- Keep the Referrer-Policy default unless a page has a reason to change it.
- List the browser features the site never uses, and disable them in Permissions-Policy.
Certificate and transport setup is covered in HTTPS and certificates. Frame embedding and script control belong to the policy described in a Content Security Policy that holds, and the cookie attributes that interact with these headers are explained in Sessions and cookies done safely.
The header behaviour described here comes from MDN. Browser support varies, particularly for Permissions-Policy. The checklist summarises this article, and starting with a short max-age is general practice, not a quoted rule.
Common questions
- Can I switch HSTS off again?
- Yes, with max-age=0, but the browser must first receive that header over HTTPS. HSTS cannot be disabled over plain HTTP.
- Which Referrer-Policy should I use?
- Keep the default, strict-origin-when-cross-origin, unless a page has a reason to reveal less. no-referrer sends nothing at all.
- Can I rely on Permissions-Policy alone?
- MDN marks the header as having limited availability, so treat it as a hardening step rather than the only control.
Sources
- Strict-Transport-Security header - HTTP | MDN, Mozilla Developer Network (MDN). Accessed 24 November 2026
- X-Content-Type-Options header - HTTP | MDN, Mozilla Developer Network (MDN). Accessed 24 November 2026
- Referrer-Policy header - HTTP | MDN, Mozilla Developer Network (MDN). Accessed 24 November 2026
- Permissions-Policy header - HTTP | MDN, Mozilla Developer Network (MDN). Accessed 24 November 2026
Further reading
-
HTTPS and certificates: renewal, HSTS and mixed content
Automate renewal well before expiry, send HSTS only over HTTPS with a deliberate max-age, and serve every resource over HTTPS.
-
A Content Security Policy that holds in practice
A policy holds when inline scripts are gone, every nonce is fresh on each response, and the rules have been tested in report-only mode first.
-
CSRF protection in plain terms
Every state-changing request needs its own token; SameSite and an Origin check add layers of defence, but they do not replace the token.
Have an idea that should exist? Or a working product that needs more customers, a new website or a complete rework? Bring us anything. Apply with your idea