In short
HTTP security headers are instructions that the server sends to the browser with each page to enable built-in protections: enforce HTTPS (HSTS), restrict allowed scripts (CSP), prevent display in third-party frames (X-Frame-Options), prevent misinterpretation of files (X-Content-Type-Options), control the information sent to other sites (Referrer-Policy), and disable unnecessary browser features (Permissions-Policy). While these measures do not fix a vulnerability, they significantly reduce its impact with minimal implementation effort.
The main headers and their recommended values
| Header | Role | Recommended value |
|---|---|---|
| Strict-Transport-Security (HSTS) | Forces the browser to use only HTTPS for the site, even if the user types http:// | max-age=63072000; includeSubDomains; preload |
| Content-Security-Policy (CSP) | Lists the authorized sources for scripts, styles, images, and frames; the primary defense against XSS exploitation | Specific to each site, for example: default-src 'self'; object-src 'none'; frame-ancestors 'none' |
| X-Frame-Options | Prevents the page from being displayed in a third-party frame, protecting against clickjacking | DENY (or SAMEORIGIN) |
| X-Content-Type-Options | Prevents the browser from guessing a file’s type (MIME sniffing) and executing it as a script or HTML page | nosniff |
| Referrer-Policy | Limits the origin address information transmitted to other sites | strict-origin-when-cross-origin (or stricter) |
| Permissions-Policy | Disables browser features that the site does not need (camera, microphone, geolocation) | camera=(), microphone=(), geolocation=() |
Headers to remove or stop using
- X-XSS-Protection: obsolete and sometimes a source of vulnerabilities; OWASP recommends not sending it, or setting it to 0.
- Public-Key-Pins (HPKP): Deprecated; it is no longer supported by modern browsers.
- Server and X-Powered-By: These headers reveal the software being used and sometimes its version; they should be removed or set to non-informative values.
Deploy without breaking the site
Most of these headers can be added with a single line in the configuration of the web server, CDN, or framework. Two require caution.
- HSTS: Once the header is received, the browser refuses HTTP requests for the entire duration of the `max-age`. The entire site—and all subdomains if `includeSubDomains` is enabled—must therefore operate over HTTPS prior to deployment. The `preload` option is used to request that the domain be added to the browser’s built-in list.
- CSP: It is first tested using the Content-Security-Policy-Report-Only header, which reports blockings without actually applying them, before switching to blocking mode.
Frequently asked questions
Are security headers sufficient to secure a website?
No. They enable browser protections that limit the exploitation of certain vulnerabilities (XSS, clickjacking, interception), but they do not fix the code or server-side access controls. This is a low-cost, defense-in-depth layer that should be combined with testing.
How can I view the headers sent by my site?
The browser’s developer tools (Network tab) display the headers for each response. The free test offered on this page checks them for your site.
Sources
Find out where an attacker would get in.
Our AI agents actually attack your scope, fully automated, and hand you the proof of every vulnerability.
