HTTP security headers that still matter: a defender’s configuration guide
TL;DR. Security headers are instructions a browser can follow after it already reached your site. They will not fix a broken access check, but they can shrink the damage of a script injection, a click on the wrong frame, or an accidental downgrade. This guide covers a practical set for 2026: HTTPS with HSTS, a considered Content-Security-Policy, frame controls, a referrer policy, and a few companions — plus how to roll them out without breaking your own front end. Configure them on systems you operate; do not use this as a way to probe someone else’s site.
What a header can and cannot do
A response header is a promise about this response and, sometimes, about future visits. The browser is the audience. A crawler, a native app, or a misbehaving integration may ignore the same header. Treat headers as a layer around a correctly written application, not as the application’s conscience.
Before you add policy, serve the site over HTTPS with a valid certificate and redirect insecure requests. Most of the useful headers assume that the user landed on the real origin, not on a look-alike.
A practical set, one at a time
HTTPS and HTTP Strict Transport Security (HSTS)
HSTS tells a supporting browser to use HTTPS for a period you choose, and optionally to include subdomains. Start with a short max-age on a staging host you control, confirm that nothing legitimate still needs plain HTTP, then raise the age. Only request preload when you understand that removal is slow and that every subdomain must be ready. A mistaken HSTS policy can lock users out of an intranet name you did not intend to cover.
Content-Security-Policy (CSP)
CSP restricts where scripts, styles, images and frames may come from, and can turn off dangerous inline patterns if you design the front end for it. A useful CSP is built from a report-only period: you collect violations, you adjust, you enforce.
Avoid “easy” policies that allow every inline script and every https: host; they look strict and do little. Prefer nonce- or hash-based script policy when you can change the templates. If a third-party widget will not work without a wide exception, isolate that widget on a dedicated page or origin rather than punching a hole in the whole site.
Frame controls
X-Frame-Options and the CSP frame-ancestors directive limit who may embed your pages. Use them unless embedding is a product requirement, in which case allow only the origins you intend. This is one of the simplest defences against click-jacking style tricks.
Referrer-Policy
Browsers may send the previous URL to the next site. A conservative policy (for example, sending a full referrer only on the same origin, and a stripped one or nothing on downgrades and cross-origin requests) reduces accidental token leaks in query strings. Check that analytics you truly need still receive what they are contractually supposed to receive — not every internal path.
Other companions that usually pay their way
- X-Content-Type-Options: nosniff reduces content-type guessing on some responses.
- Permissions-Policy (the successor to Feature-Policy) can turn off camera, microphone and similar capabilities the page does not need.
- Cross-Origin opener and resource policies are worth a careful look if you run applications that should not share a browsing context with untrusted windows. Add them with a test pass; they can surprise integrations.
- Cache-Control on responses that contain private data should not invite a shared cache to keep a user’s page.
Cookies are not “headers for the sake of a list,” but they belong in the same review: Secure, HttpOnly where JavaScript does not need the value, and a SameSite choice you can explain.
A rollout table
| Header or policy | Good first move | Typical breakage if rushed |
|---|---|---|
| HTTPS + redirect | Do this before the rest | Mixed-content warnings if assets still load over HTTP |
| HSTS, short max-age | Staging, then production, then a longer age | An overlooked HTTP-only subdomain or an internal name |
| CSP in report-only | A week of reports, then enforce a tight script policy | A blocked payment widget or an admin theme |
| frame-ancestors / X-Frame-Options | Deny or allow-list known portals | A partner dashboard that legitimately embeds you |
| Referrer-Policy | Conservative default, then exceptions | Marketing attribution you promised a vendor |
| Cookie flags | Secure + HttpOnly on session cookies | A front-end that was reading the session cookie in JavaScript |
How to ship this without a Friday outage
- Inventory response headers on the production host you operate, from a staging check or an official internal scan, not by surprising a third party.
- Add one policy on staging. Click through login, payment, file upload, and the admin theme.
- For CSP, spend time in report-only. A policy you flip to enforce on Friday afternoon will fail on an obscure page on Monday.
- Document exceptions with an owner and a review date. Permanent
unsafe-inlineis a debt, not a setting. - Re-check after each front-end release; a new analytics tag is a common CSP regress.
Official documents from MDN, from your framework, and from OWASP’s header cheat sheets are better references than a random gist. Prefer the current text; advice from 2016 will recommend obsolete headers and miss new ones.
When you draft a change ticket, describe the user-visible risk you are reducing, not only the header name. SiberAI can help you turn a staging report into a short note for the front-end team. Do not paste full production CSP violation reports if they contain user URLs or tokens; trim them first, as the security notes would suggest. The quickstart is enough if you only need a workspace to edit the ticket.
Key takeaways
- Headers shrink browser-side damage; they do not replace authorization or patching.
- HTTPS and a careful HSTS policy are the foundation.
- CSP is valuable when it is designed and observed in report-only first.
- Roll out one control at a time and give every exception an owner.
- Recheck after front-end changes; headers rot quietly.
Last updated: November 2026.
FAQ
Q: Will a perfect CSP stop all cross-site scripting?
A: No. It can make many classes of injection much harder, especially if you eliminate wide inline exceptions. The application must still encode output and treat data as data.
Q: Should we still send X-XSS-Protection?
A: Modern guidance generally advises against relying on it; some browsers have removed the XSS auditor. Invest in CSP and safe rendering instead.
Q: Is a Content-Security-Policy required by law?
A: Requirements vary by sector and contract. Even when no law names CSP, it is a reasonable control for a public web application. Talk to your compliance owners about what you must document.
Q: Can I copy another company’s header set?
A: You can read public advice, but their widget list is not yours. A copied CSP will break your site or do nothing useful.
Q: Where should the headers be set — application, reverse proxy, or CDN?
A: One place should be authoritative, and the others should not silently override it. Many teams set them at the reverse proxy or CDN and keep a test that fails if they disappear.
Q: What about APIs that only speak JSON?
A: Browser-facing documentation sites still need headers. For a pure API, focus on CORS as a deliberate allow-list, cache policy, and not leaking tokens in referrers when a browser client is involved.
Q: How do I test without scanning other people’s sites?
A: Use your staging origin, your lab, or a local server. Developer tools in the browser will show which policy blocked which resource.
Yorumlar
Yorum Gönder