In short
Security headers are HTTP response headers that ask the browser to restrict what a page can do: forbid it from being displayed in an iframe on another site, refuse to guess a file's type, limit the information passed on to other sites, disable unneeded sensitive APIs and run only authorized scripts. This check consists of setting a common baseline on every response, then deploying a content security policy (CSP) in test mode before enforcing it. Expected result: an HTTP Observatory scan with no missing header, and no broken module on the site.
Why it matters
These headers do not fix a vulnerability: they limit its consequences. A script injected into a comment, a compromised plugin or a hacked third-party script has much less of a hold if the page refuses unauthorized scripts. A site displayed in an invisible iframe can no longer be used to trick its visitors into clicking (clickjacking).
The stake for visibility is indirect but real. A hacked site ends up with spam pages, hidden redirects or injected links; Google may then show a warning in its results or a Safe Browsing screen in Chrome, and Search Console reports a security issue. Generative engines, which fetch page content, may pick up injected content or rule out a source deemed dubious.
Google does not document any effect of security headers on rankings. Their benefit is risk reduction, not a gain in positions. Conversely, a badly configured header can do harm: an overly strict CSP blocks the analytics tool, the tag manager or the chat, and breaks rendering for visitors as well as for search engines that execute JavaScript.
What it improves
- Reduced injection risk An enforced CSP blocks unauthorized scripts.
- Protection against clickjacking
frame-ancestorsandX-Frame-Options. - Visitor privacy
Referrer-Policyavoids passing full URLs, with their parameters, to third-party sites. - Control over third-party scripts The CSP serves as an inventory of everything the site loads.
- Audits Security scanners, B2B customer questionnaires and insurers check these headers.
- Rankings and AI citations No direct effect; the effect is to avoid hacking and warnings.
How to check
curl -sI https://www.example.com/ | grep -i -E "^(content-security-policy|content-security-policy-report-only|x-content-type-options|x-frame-options|referrer-policy|permissions-policy|strict-transport-security|cross-origin-opener-policy|server|x-powered-by):"
Compliant result, at a minimum:
strict-transport-security: max-age=31536000; includeSubDomains
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
referrer-policy: strict-origin-when-cross-origin
permissions-policy: camera=(), microphone=(), geolocation=()
content-security-policy: … frame-ancestors 'self'; …
And neither x-powered-by nor a precise version in server. Also test a 404 error page, a static file and an API response: headers added by the application do not always apply to these responses.
Free tools: Mozilla's HTTP Observatory, hosted on MDN, gives a grade and explains each point; Security Headers gives a quick overview. Screaming Frog lists, in its Security tab, the pages missing these headers.
How to implement
Before you start
The baseline to set everywhere:
| Header | Recommended value | Purpose |
|---|---|---|
Strict-Transport-Security |
max-age=31536000; includeSubDomains |
Enforce HTTPS. Handled separately: see configure HSTS if appropriate (opens in a new tab) |
X-Content-Type-Options |
nosniff |
Forbid the browser from guessing a file's type |
X-Frame-Options |
SAMEORIGIN |
Forbid display in an iframe on another site (older browsers) |
Referrer-Policy |
strict-origin-when-cross-origin |
Send only the domain to other sites, nothing to HTTP |
Permissions-Policy |
camera=(), microphone=(), geolocation=(), payment=() |
Disable unneeded sensitive APIs; remove the ones the site uses |
Content-Security-Policy |
Policy specific to the site, in test mode first | Allow only the intended sources of scripts, styles and images |
No longer to be used: X-XSS-Protection (deprecated, MDN states that it can create vulnerabilities; omit it or set it to 0), Expect-CT and Public-Key-Pins (abandoned), Feature-Policy (replaced by Permissions-Policy).
Deploy the CSP in three stages:
- Inventory: send
Content-Security-Policy-Report-Onlywith a starting policy and a reporting address. Nothing is blocked; the console and the reports list what would be. - Adjustment: for one to two weeks, add the legitimate domains (analytics tool, tag manager, fonts, videos, payment, chat) and remove unknown scripts.
- Enforcement: switch to
Content-Security-Policy, possibly keeping the test version for a stricter policy.
Starting policy for a typical editorial site:
default-src 'self'; script-src 'self' https://www.googletagmanager.com; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self'; connect-src 'self' https://*.google-analytics.com; frame-src https://www.youtube-nocookie.com; frame-ancestors 'self'; base-uri 'self'; form-action 'self'; object-src 'none'; upgrade-insecure-requests
Sites with many inline scripts (WordPress with a page builder, a tag manager that injects code) will have to either allow 'unsafe-inline' in script-src, which weakens the protection, or move to a nonce-based CSP generated by the application on each request. The second route is the right one, but it requires development work.
Warning:
frame-ancestors 'none'orX-Frame-Options: DENYalso prevent your own tools from displaying the site in an iframe: a page builder's preview, an A/B testing tool, the CMS preview. Prefer'self'andSAMEORIGIN, and test the admin area after deployment.
Apache
Versions Apache 2.4.
Enable the module (sudo a2enmod headers), then create /etc/apache2/conf-available/security-headers.conf and enable it with sudo a2enconf security-headers, or paste the block into the HTTPS virtual host or .htaccess:
<IfModule mod_headers.c>
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=(), payment=()"
Header always set Content-Security-Policy-Report-Only "default-src 'self'; img-src 'self' data: https:; style-src 'self' 'unsafe-inline'; frame-ancestors 'self'; base-uri 'self'; form-action 'self'; object-src 'none'; upgrade-insecure-requests"
Header always unset X-Powered-By
Header unset X-Powered-By
</IfModule>
always also applies the header to error responses and redirects. To hide the Apache version, add ServerTokens Prod and ServerSignature Off to the global configuration (not in .htaccess), and expose_php = Off to php.ini. Reload with sudo apachectl configtest && sudo systemctl reload apache2.
Nginx
Versions Nginx 1.18 and later; add_header_inherit directive from Nginx 1.29.3.
Create /etc/nginx/snippets/security-headers.conf:
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=(), payment=()" always;
add_header Content-Security-Policy-Report-Only "default-src 'self'; img-src 'self' data: https:; style-src 'self' 'unsafe-inline'; frame-ancestors 'self'; base-uri 'self'; form-action 'self'; object-src 'none'; upgrade-insecure-requests" always;
Then in each HTTPS server block:
server_tokens off;
include snippets/security-headers.conf;
fastcgi_hide_header X-Powered-By;
proxy_hide_header X-Powered-By;
A classic trap: an add_header placed in a location block (for example for static file caching) cancels all those inherited from the server block. Add include snippets/security-headers.conf; in each of these location blocks. From Nginx 1.29.3 (1.30 stable branch), add_header_inherit merge; placed in the server block instead combines the headers from the upper levels with those of the location. Reload with sudo nginx -t && sudo systemctl reload nginx.
LiteSpeed
Versions LiteSpeed Web Server 6; OpenLiteSpeed 1.7 and later.
LiteSpeed reads Header directives from .htaccess: the block from the Apache section works as is. On OpenLiteSpeed, also add them in the virtual host, under Context > Header Operations, if .htaccess is not read.
Caddy
Versions Caddy 2.
In the Caddyfile:
www.example.com {
header {
X-Content-Type-Options "nosniff"
X-Frame-Options "SAMEORIGIN"
Referrer-Policy "strict-origin-when-cross-origin"
Permissions-Policy "camera=(), microphone=(), geolocation=(), payment=()"
Content-Security-Policy-Report-Only "default-src 'self'; img-src 'self' data: https:; style-src 'self' 'unsafe-inline'; frame-ancestors 'self'; object-src 'none'"
-Server
-X-Powered-By
}
root * /var/www/example
file_server
}
The - prefix removes a header. Reload with sudo systemctl reload caddy.
IIS
Versions IIS 10; removal of the Server header from IIS 10 version 1709 (Windows Server 2019 and later).
In web.config:
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<remove name="X-Powered-By" />
<add name="X-Content-Type-Options" value="nosniff" />
<add name="X-Frame-Options" value="SAMEORIGIN" />
<add name="Referrer-Policy" value="strict-origin-when-cross-origin" />
<add name="Permissions-Policy" value="camera=(), microphone=(), geolocation=(), payment=()" />
<add name="Content-Security-Policy-Report-Only" value="default-src 'self'; img-src 'self' data: https:; style-src 'self' 'unsafe-inline'; frame-ancestors 'self'; object-src 'none'" />
</customHeaders>
</httpProtocol>
<security>
<requestFiltering removeServerHeader="true" />
</security>
</system.webServer>
</configuration>
removeServerHeader is only supported from IIS 10 version 1709: on Windows Server 2016, remove this line, which would cause a configuration error.
Cloudflare
Versions Cloudflare dashboard, Transform Rules, all plans, November 2026.
Add the headers at the edge, without touching the server: from the rules overview, Create rule > Response Header Transform Rule.
- Rule name: “Security headers”.
- Apply to all incoming requests, or to a specific hostname.
- For each header in the table, “Set static” operation, name and value. Click “Set new header” to add another one; a rule accepts up to thirty modifications.
- Add a “Remove” operation for
X-Powered-By. - “Deploy”.
Cloudflare also offers an “Add security headers” managed transform, but it sets deprecated headers (X-XSS-Protection, Expect-CT) and a Referrer-Policy: same-origin that strips the referrer to other sites: the custom rule is preferable. HSTS is configured separately, under Edge Certificates.
AWS
Versions AWS console, Amazon CloudFront, November 2026.
On CloudFront, open Policies > Response headers. The SecurityHeadersPolicy managed policy sets Referrer-Policy: strict-origin-when-cross-origin, X-Content-Type-Options: nosniff and X-Frame-Options: SAMEORIGIN, but also X-XSS-Protection and a one-year HSTS (Strict-Transport-Security: max-age=31536000), with no CSP. Prefer a custom policy: “Create response headers policy”, security headers section for the known headers (including Content-Security-Policy), custom headers section for Permissions-Policy, and remove headers section for X-Powered-By and Server. Then attach it to each behavior of the distribution. Without CloudFront (Application Load Balancer only), set the headers on the web server or in the application.
Plesk
Versions Plesk Obsidian 18.0.
In Websites & Domains > your domain > Apache & nginx Settings, paste the add_header lines from the Nginx section into “Additional nginx directives”. If Nginx serves static files directly, its generated location blocks do not always inherit these headers: check a CSS file with curl and, if needed, also put the block from the Apache section in .htaccess.
cPanel
Versions cPanel & WHM 124 and later.
cPanel has no dedicated screen: paste the block from the Apache section into public_html/.htaccess via Files > File Manager (show hidden files). Then check with curl: if the host places Nginx as a proxy in front of Apache, static files may not receive the headers.
Shared hosting
The .htaccess from the Apache section works with most hosts, as the <IfModule> blocks prevent any error if mod_headers is missing. Some hosts already add some of these headers: check with curl that none appears twice with two different values.
Vercel
Versions Vercel platform, all plans, November 2026.
In vercel.json:
{
"headers": [
{
"source": "/(.*)",
"headers": [
{ "key": "X-Content-Type-Options", "value": "nosniff" },
{ "key": "X-Frame-Options", "value": "SAMEORIGIN" },
{ "key": "Referrer-Policy", "value": "strict-origin-when-cross-origin" },
{ "key": "Permissions-Policy", "value": "camera=(), microphone=(), geolocation=(), payment=()" }
]
}
]
}
Vercel already sends HSTS on custom domains.
Netlify
Versions Netlify platform, all plans, November 2026.
In a _headers file at the root of the publish directory:
/*
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
Referrer-Policy: strict-origin-when-cross-origin
Permissions-Policy: camera=(), microphone=(), geolocation=(), payment=()
Content-Security-Policy-Report-Only: default-src 'self'; img-src 'self' data: https:; frame-ancestors 'self'; object-src 'none'
WordPress
Versions WordPress 6.4 and later.
Set the headers on the server or the CDN (previous sections): they then also cover static files. Without server access, a snippet in a custom plugin or a must-use plugin (wp-content/mu-plugins/security-headers.php) adds the headers to pages generated by WordPress:
<?php
add_action('send_headers', function (): void {
header('X-Content-Type-Options: nosniff');
header('X-Frame-Options: SAMEORIGIN');
header('Referrer-Policy: strict-origin-when-cross-origin');
header('Permissions-Policy: camera=(), microphone=(), geolocation=(), payment=()');
});
For the CSP, WordPress and most themes and plugins inject inline scripts: start in Report-Only mode and test the admin area, the block editor and the WooCommerce checkout flow before enforcing anything.
Shopify
Versions Shopify, Wix and Squarespace, all plans; Webflow, Enterprise plan; November 2026.
Shopify does not let you add or modify HTTP headers on the store: the platform manages its own headers. Check with curl what it sends, and focus on sorting out apps and third-party scripts. Wix and Squarespace work the same way; on Webflow, custom security headers are reserved for the Enterprise plan.
Drupal
Versions Drupal 10 and 11; Security Kit module 2.x.
The Security Kit module (seckit) sets the anti-framing headers, X-Content-Type-Options and a CSP with a reporting address from the admin interface. Headers set at the server level remain preferable to cover static files.
Laravel
Versions Laravel 10 to 13; spatie/laravel-csp 2 (Laravel 10 and 11) and 3 (Laravel 12 and 13).
Create a middleware, app/Http/Middleware/AddSecurityHeaders.php:
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class AddSecurityHeaders
{
public function handle(Request $request, Closure $next): Response
{
$response = $next($request);
$response->headers->set('X-Content-Type-Options', 'nosniff');
$response->headers->set('X-Frame-Options', 'SAMEORIGIN');
$response->headers->set('Referrer-Policy', 'strict-origin-when-cross-origin');
$response->headers->set('Permissions-Policy', 'camera=(), microphone=(), geolocation=(), payment=()');
$response->headers->remove('X-Powered-By');
return $response;
}
}
For a nonce-based CSP, the spatie/laravel-csp package generates the policy and the nonce, to be used in Blade views. Since files in public/ are served by the web server, set the headers there too (Nginx or Apache section). All that remains is to register the middleware as global middleware, and this is where the versions differ.
Laravel 11 to 13
Register it in bootstrap/app.php:
use App\Http\Middleware\AddSecurityHeaders;
use Illuminate\Foundation\Configuration\Middleware;
return Application::configure(basePath: dirname(__DIR__))
// ->withRouting(...)
->withMiddleware(function (Middleware $middleware): void {
$middleware->append(AddSecurityHeaders::class);
})
// ->withExceptions(...)
->create();
An application upgraded from Laravel 10 without changing its structure can keep its app/Http/Kernel.php: in that case, follow the next tab.
Laravel 10
Add it at the end of the $middleware array in app/Http/Kernel.php:
protected $middleware = [
// … existing middleware
\App\Http\Middleware\AddSecurityHeaders::class,
];
Next.js
Versions Next.js 15 and 16, App Router and Pages Router.
In next.config.js, for all routes:
const securityHeaders = [
{ key: 'X-Content-Type-Options', value: 'nosniff' },
{ key: 'X-Frame-Options', value: 'SAMEORIGIN' },
{ key: 'Referrer-Policy', value: 'strict-origin-when-cross-origin' },
{ key: 'Permissions-Policy', value: 'camera=(), microphone=(), geolocation=(), payment=()' },
];
module.exports = {
poweredByHeader: false,
async headers() {
return [{ source: '/(.*)', headers: securityHeaders }];
},
};
poweredByHeader: false removes X-Powered-By: Next.js. For the CSP, the Next.js documentation describes two routes: a static policy in headers(), with 'unsafe-inline' for scripts, or a nonce-based policy generated in proxy.ts (middleware.ts before Next.js 16). Nonces require dynamic rendering of every page, and therefore the end of static rendering and CDN caching for those pages: weigh this performance cost.
Common mistakes
- Enforcing a CSP without a test phase: the analytics tool, the tag manager, videos or payment stop working, sometimes without anyone noticing.
- Two CSP headers (server and application): the browser applies both, and the stricter one wins for each directive.
- Forgetting
alwayson Nginx and Apache: error pages and redirects go out without headers. add_headerin an Nginxlocation: it silently erases the inherited headers.- Copying another site's policy: each CSP depends on the services actually used.
X-Frame-Options: DENYwhen the CMS displays the site in an iframe for previews.- Keeping
X-XSS-Protection: 1; mode=blockout of habit: a deprecated header, sometimes a source of vulnerabilities. - Believing headers replace updates: they limit the damage; they do not close the vulnerability of an outdated plugin.
Frequently asked questions
Do security headers improve SEO?
Not directly: Google does not document any effect of security headers on rankings. Their value for visibility is indirect. They reduce the consequences of a script injection or a hack, which can lead to spam pages, a warning in search results or a Safe Browsing screen in Chrome. Badly configured, they can on the contrary break rendering or the analytics tool.
Can a Content Security Policy block Google Analytics or Google Tag Manager?
Yes, if their domains are not included in the policy. Google Tag Manager must be allowed in script-src, and Google Analytics data collection in connect-src; each tag added in the tag manager may require other domains. That is why the CSP is first deployed in Content-Security-Policy-Report-Only mode, for one to two weeks, to list every legitimate source before blocking anything.
Is X-Frame-Options still needed if the CSP contains frame-ancestors?
Recent browsers apply frame-ancestors and ignore X-Frame-Options when both are present. Keeping X-Frame-Options: SAMEORIGIN costs nothing and protects older browsers. The two must remain consistent: allow 'self' in frame-ancestors and SAMEORIGIN in X-Frame-Options, unless you need to be displayed in an iframe by a specific partner, which must then be declared in frame-ancestors.
Which security headers should no longer be used?
X-XSS-Protection is deprecated and, according to MDN, can create vulnerabilities in otherwise safe sites: omit it or set it to 0, and rely on a Content Security Policy. Expect-CT and Public-Key-Pins have been abandoned by browsers, and Feature-Policy has been replaced by Permissions-Policy. Some ready-made configurations, including at major CDN providers, still add them.
Resources
- MDN: Practical security implementation guidesdeveloper.mozilla.org
- MDN: Content-Security-Policy and X-XSS-Protectiondeveloper.mozilla.org
- MDN: HTTP Observatorydeveloper.mozilla.org
- OWASP Secure Headers Projectowasp.org
- Cloudflare: Create a response header transform ruledevelopers.cloudflare.com
- Amazon CloudFront: Use managed response headers policiesdocs.aws.amazon.com
- Next.js: Content Security Policynextjs.org
- Nginx: headers module and Apache: mod_headersnginx.org
Updated on
Topic checklist (PDF)