In short: HTTP security headers are lines your server adds to every response to tell the browser which protections to switch on. Six are worth sending today: Strict-Transport-Security, Content-Security-Policy, X-Content-Type-Options, X-Frame-Options, Referrer-Policy and Permissions-Policy. Each blocks a specific attack, and each has a safe production value you can copy below.
The hard part isn’t the syntax. It’s getting them onto every response without breaking a payment widget, a subdomain or a cached page. This guide gives the exact value for each header, a before and after view of a real response, and the misconfigurations that fail silently.
How HTTP security headers work
Every time a browser asks for a page, the server sends back an HTTP response with two parts: the content and a block of headers. Each HTTP header is a name and value pair, such as Content-Type: text/html; charset=UTF-8, and they describe how the browser should handle what follows. Most of them deal with caching, compression or cookies. Security headers are the HTTP response headers that turn on browser defences.
The mechanism is simple: server sends the header, browser stores or applies the rule, browser blocks anything that breaks it. That means the protection runs on the visitor’s machine. If an attacker manages to inject a malicious script tag, a good policy stops the browser from running it, even though your server delivered the page. Much the same conclusion turns up on really-simple-ssl.com.
Two limits follow from that design. First, headers are a second line of defence, not a fix for code vulnerabilities, broken access control or an outdated plugin. Second, they’re visible to anyone who requests your page, so automated scanners record missing headers across the whole web. A small site isn’t too small to be scanned.
The same logic answers a common question: is an HTTPS page 100% secure? No. HTTPS encrypts the connection between browser and server, so nobody on the network can read or alter the traffic. It says nothing about what the page itself does once it arrives, which is exactly the gap these headers cover.

The six headers worth sending, with production values
The table is the reference. The next section explains the two headers that need judgement.
| Header | Attack it blocks | Production value | Avoid |
|---|---|---|---|
| Strict-Transport-Security | Downgrade to plain HTTP, cookie theft on public Wi-Fi | max-age=31536000; includeSubDomains |
preload before every subdomain serves HTTPS |
| Content-Security-Policy | Cross-site scripting (XSS), injected content, framing | default-src 'self'; object-src 'none'; base-uri 'self'; frame-ancestors 'self', then extended |
'unsafe-inline' and 'unsafe-eval' in script-src |
| X-Content-Type-Options | Media type (MIME) sniffing: a file read as a different type | nosniff |
Nothing: there is one value |
| X-Frame-Options | Clickjacking through an invisible iframe | SAMEORIGIN (or DENY) |
ALLOW-FROM, which modern browsers ignore |
| Referrer-Policy | Leaking full URLs, tokens and query strings to other sites | strict-origin-when-cross-origin |
unsafe-url |
| Permissions-Policy | Third-party scripts reaching camera, microphone, geolocation | camera=(), microphone=(), geolocation=() |
Old Feature-Policy syntax such as camera 'none' |
Transport security and content policy: the two headers that need judgement
Strict-Transport-Security (HSTS)
HTTP Strict Transport Security (HSTS) tells the browser to use HTTPS only for your domain until max-age runs out. The Internet Engineering Task Force (IETF) published it as RFC 6797, one of its Request for Comments standards. After the first visit, the browser rewrites any http:// link to https:// before a single byte leaves the machine, so a network attacker can’t intercept the first unencrypted request.
Roll it out in steps, because a browser that has stored the rule won’t let visitors back over HTTP. Start with max-age=86400 (one day), check that nothing breaks, then move to one year. Add includeSubDomains only when every subdomain serves HTTPS.
The preload flag goes last: it asks browsers to ship your domain as HTTPS-only before anyone visits, and leaving that list is slow. The official submission site, hstspreload.org, requires a max-age of at least one year plus includeSubDomains and preload.
Content-Security-Policy (CSP)
Content Security Policy (CSP) is an allowlist for everything a page loads: scripts, styles, images, fonts, frames and connections. If an injected script points to a server that isn’t on the list, the browser refuses to run it. That makes CSP the strongest header against cross-site scripting and other code injection. In an XSS attack, someone slips their own JavaScript into your page, for example through a comment form or a vulnerable plugin.
It’s also the header that breaks sites. A typical agency build calls analytics, a tag manager, embedded videos, fonts and a chat widget, and each needs its source declared. Send the policy as Content-Security-Policy-Report-Only first: the browser logs violations without blocking anything. Read the reports for a week or two, add the sources you actually need, then switch to the enforcing header.
Three directives are easy to forget and matter a lot:
object-src 'none'blocks old plugin content.base-uri 'self'stops an injected<base>tag from rewriting every relative link.frame-ancestorscontrols who may frame your page, and the CSP specification makes it the modern replacement for X-Frame-Options.
For inline scripts you can’t remove, use a nonce (a random value the server stamps on each legitimate script tag) or a hash rather than 'unsafe-inline'.

Smaller headers: what each line actually changes
X-Content-Type-Options: nosniff. Every response carries a Content-Type header, which declares the MIME type of the file, for example text/html or image/png. Some browsers used to guess the content type from the file itself instead, a behaviour called MIME sniffing. An attacker could upload a “photo” that really contains script and get it executed.
With nosniff, the browser refuses a script or stylesheet whose declared type doesn’t match.
X-Frame-Options. Clickjacking works by loading your page in a transparent iframe on another site, then tricking the visitor into clicking a button they can’t see. DENY forbids all framing. SAMEORIGIN allows your own pages to frame each other, which is what most sites need: the WordPress Customizer, for instance, previews the site inside a same-origin frame. Keep this header alongside frame-ancestors for older browsers; it costs one line.
Referrer-Policy. When a visitor clicks a link to another site, the browser sends referrer information, in a header spelled Referer, with the page they came from. That URL can contain search terms, reset tokens or customer IDs. strict-origin-when-cross-origin sends the full URL within your site but only the domain to others. It sends nothing at all when a link goes from HTTPS to HTTP. It also keeps referral data in your analytics, unlike no-referrer.
If your URLs ever carry personal data, a strict policy also supports the data minimisation principle of the GDPR (Article 5(1)(c)), since less of it reaches third parties.
Permissions-Policy. This header, formerly called Feature-Policy, lists which browser features your page and its embedded third parties may use. Empty parentheses mean “disabled for everyone”. If your site never asks for the camera, microphone or location, switch them off so that a compromised ad or widget script can’t ask either. The syntax changed with the rename: camera=() is correct, while camera 'none' belongs to the old header.
Headers to drop, and headers to stop copying
Many tutorials still paste headers that do nothing today or make things worse. Cleaning them up is part of the job.
- X-XSS-Protection. This header controlled a filter built into old browsers. Chrome removed that filter in version 78, Firefox never implemented it, and the filter itself created new leaks. Send
X-XSS-Protection: 0if a scanner insists, or leave it out and rely on CSP. - Expect-CT. It dealt with Certificate Transparency, the public logging of TLS (Transport Layer Security) certificates. Browsers now enforce that by default, and Mozilla’s developer documentation (MDN) marks the header as deprecated.
- Feature-Policy. Replaced by Permissions-Policy. Sending both just adds noise.
- X-Frame-Options: ALLOW-FROM. Obsolete. Use
frame-ancestors https://partner.examplein CSP instead.
Two headers should go for a different reason. Server: Apache/2.4.57 (Debian) and X-Powered-By: PHP/8.2.12 announce your exact software versions, which is precisely what automated scanners use to pick a known exploit. In Nginx, server_tokens off; hides the version. In Apache, ServerTokens Prod does the same, and expose_php = Off in php.ini removes the PHP banner.
Cross-origin headers, resource sharing and cookies
Three newer headers isolate your pages from other origins. An origin is the combination of scheme, domain and port, such as https://example.com.
- Cross-Origin-Opener-Policy (COOP):
same-origincuts the link between your page and windows it opens, which blocks cross-window attacks. It can break login or payment pop-ups that talk back to the opener. - Cross-Origin-Resource-Policy (CORP):
same-originstops other sites from embedding your files. - Cross-Origin-Embedder-Policy (COEP): the strictest of the three. You need it only for features such as
SharedArrayBuffer, and it breaks third-party embeds that don’t opt in.
For a brochure site or a shop, COOP is worth testing and COEP can usually wait. Web applications that rely on heavy client-side computation are the main case for the full trio.
Many lists file Cross-Origin Resource Sharing (CORS) under security headers, but it works the other way round. It relaxes the browser’s same-origin rule so that another site’s JavaScript can read your responses. The common mistake is Access-Control-Allow-Origin: * on an API that uses cookies; browsers refuse credentials with a wildcard anyway, so list the exact origins you trust.
Cookies have their own security settings, set in the Set-Cookie header. Secure keeps the cookie off plain HTTP, HttpOnly hides it from JavaScript, so an XSS bug can’t read a session cookie, and SameSite=Lax limits cross-site requests that carry it.
WordPress core already marks its login cookies HttpOnly, and Secure when the site runs on HTTPS. Cookies added by plugins or custom code don’t inherit these settings, since each Set-Cookie line carries its own, so check each one in the developer tools.

Before and after: one response header set
Here’s an example of what curl -sI https://example.com returns for a typical small business site on shared Apache hosting, before any work:
HTTP/2 200
server: Apache/2.4.57 (Debian)
x-powered-by: PHP/8.2.12
content-type: text/html; charset=UTF-8
x-xss-protection: 1; mode=block
It leaks two version numbers, keeps a dead header and sends none of the six that matter. After the rollout described below, the same request returns:
HTTP/2 200
server: Apache
content-type: text/html; charset=UTF-8
strict-transport-security: max-age=31536000; includeSubDomains
content-security-policy: default-src 'self'; script-src 'self' https://www.googletagmanager.com; img-src 'self' data: https:; object-src 'none'; base-uri 'self'; frame-ancestors 'self'
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
referrer-policy: strict-origin-when-cross-origin
permissions-policy: camera=(), microphone=(), geolocation=()
The CSP line is the one that will differ on your site. It reflects the scripts and images that the report-only phase actually found, not a generic template.
Which setup fits your site
Where you set the headers depends on who controls the final response. Pick the layer closest to the visitor that you can actually edit.
| If your site is… | Do this | Avoid |
|---|---|---|
| WordPress on shared Apache or LiteSpeed hosting | Add the headers in .htaccess, so cached pages get them too |
Pasting the block into wp-config.php; paying for a plugin that only writes these six lines |
| Behind Cloudflare | Set HSTS in the dashboard and the rest with a response header rule | Setting the same header at the origin and the edge with different values |
| On a virtual private server (VPS) with Nginx | One include file, with always on every line |
Scattering add_header across locations |
| A shop or site full of third-party scripts | CSP in report-only for two weeks, checkout tested by hand | Enforcing a copied CSP on launch day |
| A widget or page embedded by partners | frame-ancestors listing each partner domain |
X-Frame-Options: DENY on the embedded pages |
| An app on Next.js, Express or Django | Framework config or middleware (Helmet for Express), checked against what the proxy adds | A second copy of each header from the web server |
How to add security headers on Apache, Nginx and Cloudflare
Apache. Put this block in the virtual host or in the .htaccess file at the site root. It needs mod_headers. If your host doesn’t enable that module, the IfModule wrapper skips the block without an error, so always check the result. The always keyword also covers error and redirect responses.
<IfModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
Header always set X-Content-Type-Options "nosniff"
Header always set X-Frame-Options "SAMEORIGIN"
Header always set Referrer-Policy "strict-origin-when-cross-origin"
Header always set Permissions-Policy "camera=(), microphone=(), geolocation=()"
Header always set Content-Security-Policy-Report-Only "default-src 'self'; object-src 'none'; base-uri 'self'; frame-ancestors 'self'; report-uri /csp-report"
</IfModule>
Browsers ignore HSTS received over plain HTTP, so the line is harmless on the HTTP side of a site that redirects everything to HTTPS.
Nginx. Save the lines below as /etc/nginx/snippets/security-headers.conf and add include snippets/security-headers.conf; in the server block. Then run nginx -t and reload.
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always;
add_header Content-Security-Policy-Report-Only "default-src 'self'; object-src 'none'; base-uri 'self'; frame-ancestors 'self'; report-uri /csp-report" always;
Without always, Nginx adds the headers only to a list of success and redirect codes, so your 404 and 500 pages go out unprotected.
Cloudflare. Turn on HSTS under SSL/TLS, then Edge Certificates, in the HTTP Strict Transport Security section. For the other headers, create a response header transform rule in the Rules section, choose the “Set static” operation, then enter each header name and its value. Set the rule to apply to all incoming requests so that it covers the whole zone.
On WordPress without server access, the send_headers action lets a small plugin call PHP’s header() function. It works, with one condition covered in the next section.

Five misconfigurations that silently break sites
None of these throws an error. You find them only by checking the live response.
1. The headers are in .htaccess but the scanner sees none. Cause: the server isn’t Apache. An .htaccess file only works on Apache and LiteSpeed; Nginx, Caddy and many managed hosts ignore it completely. Fix: read the server line in curl -sI, then use the right method above or the host’s own header settings.
2. Headers appear when you’re logged in, then vanish for visitors. Cause: the headers come from PHP, but a page cache serves stored HTML files straight from disk, so PHP never runs for those visitors. Fix: move the headers to the web server or the CDN (content delivery network), which see every response, cached or not.
3. “Headers already sent”, or the page layout breaks. Cause: PHP’s header() must run before any output, and a blank line, a byte-order mark or a closing ?> at the end of an include counts as output. Fix: call it first, start every file with <?php and drop trailing ?> tags.
4. Some Nginx pages lose all their headers. Cause: Nginx inherits add_header from the parent level only when the current level has none. One add_header Cache-Control inside a location block wipes the security headers for that location. Fix: include the snippet again in every location that adds its own header.
5. A subdomain or a payment step stops loading. Cause: includeSubDomains reached a staging or legacy subdomain still on HTTP, or an enforced CSP blocked a script from a payment, booking or chat provider. Fix: for HSTS, issue a certificate for the subdomain, because visitors stay locked to HTTPS until max-age expires. For CSP, return to report-only and add the missing source.
Duplicates deserve a last word. When a framework, the server and a CDN each add a CSP, the browser enforces all of them, so a resource must pass every policy. The result is stricter than any single policy and hard to debug. Pick one layer per header.
Testing and monitoring your headers
Start with the raw response. In a terminal, curl -sI https://yourdomain.com prints the headers of the home page. In the browser, open the developer tools, go to the Network tab, click the first request and read the response headers. The Console tab lists every CSP violation with the directive that blocked it.
Then use a grader. securityheaders.com, created by Scott Helme, gives a letter from A+ to F. Mozilla’s MDN HTTP Observatory scores the site and explains each test.
In our view, treat the grade as a summary, not the goal: the explanation of each test teaches more than the letter. For directive details and browser support, the HTTP Headers Cheat Sheet from OWASP (Open Worldwide Application Security Project) and MDN Web Docs are the references to keep open.
Test more than the home page. Check a 404 page, a file in the uploads folder, the login page and an API endpoint, because headers often reach HTML pages and nothing else. Re-run the checks after every server update, configuration change, CDN change or plugin install, since any of them can remove a header without notice. In our view, a monthly check is enough for sites that rarely change. The HTTP security headers that earn their place covers this in more depth.
For CSP, the report count is your indicator. During the report-only phase, watch it fall as you add legitimate sources. After enforcement, a sudden jump usually means a new script was added, or someone is trying to inject one.
Rollout order and checklist
Start with the headers that can’t break anything, and leave the ones that can lock you in for last. This order reaches a good grade quickly while you take your time on CSP.
- Run
curl -sIand a grader to record the current state. - Remove version banners and dead headers (X-XSS-Protection, Expect-CT, Feature-Policy).
- Add
X-Content-Type-Options: nosniff. - Add
X-Frame-Options: SAMEORIGIN, orframe-ancestorsfor embedded pages. - Add
Referrer-Policy: strict-origin-when-cross-origin. - Add
Permissions-Policyfor the features you don’t use. - Add HSTS with a one-day
max-age, then one year once every subdomain serves HTTPS. - Deploy CSP in report-only mode and collect reports for one to two weeks.
- Enforce CSP, then test login, forms, checkout and embeds by hand.
- Re-test a 404 page, an upload and an API response, not just the home page.
- Consider
preloadonly when the one-year HSTS has run cleanly. - Schedule a re-check after each server, CDN or plugin change.
FAQ
Do HTTP security headers help SEO?
Not directly, in our reading. Google describes HTTPS as a lightweight ranking signal, and HSTS helps keep visitors on it, but it doesn’t present the other headers that way. The real benefit is indirect: a site that doesn’t get defaced or hijacked keeps its traffic.
Can I set security headers with an HTML meta tag?
Only partly. A <meta http-equiv="Content-Security-Policy"> tag works, but it can’t carry frame-ancestors or report-only mode. Browsers ignore HSTS and X-Frame-Options in meta tags, so these must come from the server.
Do I need a paid plugin to add security headers?
No. The six headers fit in a few lines of server config, and free options exist on most hosts and CDNs. What’s worth paying for, if anything, is the time to build and test a CSP that matches your third-party scripts.
Do APIs need security headers too?
Yes, though a shorter set. A JSON API should send nosniff and HSTS, and a strict Content-Security-Policy: default-src 'none'; frame-ancestors 'none' costs nothing because it never renders HTML. Add careful CORS rules if browsers call it from other origins.
Will a big CSP slow my site down?
Headers travel with every response, so a policy of several kilobytes adds weight to each request. In practice that’s rarely noticeable on a normal site. If yours grows large, you can send CSP on HTML pages only, since that’s where the policy does its work.
The quickest win is the first half of the checklist: four one-line headers and a cleanup of old ones, done in an afternoon on any server. Plan CSP as its own small project, with a report-only phase and a test of every form and checkout. If you build sites for clients, put the snippet in your launch template so every new project starts with it.
Want more practical web development guides like this one? Browse the rest of our blog for build, hosting and performance checklists you can reuse on your next project.

