# Configure security headers

- Check 09.05 · Security and infrastructure · Critical
- Source: https://checklist-seo-geo.com/en/security-infrastructure/configure-security-headers
- Add X-Content-Type-Options, Referrer-Policy, Permissions-Policy, framing protection and CSP on Apache, Nginx, Cloudflare, AWS, WordPress, Laravel or Next.js.
- Updated on 2026-11-25
- Licence: CC BY 4.0. Credit “Checklist SEO & GEO” with a link to https://checklist-seo-geo.com/en/security-infrastructure/configure-security-headers.
- Plugin checklist-seo-geo: 1.3.1 · https://github.com/maximegaul/checklist-seo-geo

## 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-ancestors` and `X-Frame-Options`.
- **Visitor privacy**: `Referrer-Policy` avoids 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

```bash
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:

```txt
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](https://checklist-seo-geo.com/en/security-infrastructure/configure-hsts-if-appropriate) |
| `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:

1. **Inventory**: send `Content-Security-Policy-Report-Only` with a starting policy and a reporting address. Nothing is blocked; the console and the reports list what would be.
2. **Adjustment**: for one to two weeks, add the legitimate domains (analytics tool, tag manager, fonts, videos, payment, chat) and remove unknown scripts.
3. **Enforcement**: switch to `Content-Security-Policy`, possibly keeping the test version for a stricter policy.

Starting policy for a typical editorial site:

```txt
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'` or `X-Frame-Options: DENY` also 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'` and `SAMEORIGIN`, 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`:

```apache
<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`:

```nginx
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:

```nginx
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`:

```txt
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`:

```xml
<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](https://dash.cloudflare.com/?to=/:account/:zone/rules/overview), `Create rule > Response Header Transform Rule`.

1. Rule name: “Security headers”.
2. Apply to all incoming requests, or to a specific hostname.
3. 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.
4. Add a “Remove” operation for `X-Powered-By`.
5. “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`:

```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:

```txt
/*
  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
<?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
<?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`:

```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`:

```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:

```js
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 `always`** on Nginx and Apache: error pages and redirects go out without headers.
- **`add_header` in an Nginx `location`**: it silently erases the inherited headers.
- **Copying another site's policy**: each CSP depends on the services actually used.
- **`X-Frame-Options: DENY`** when the CMS displays the site in an iframe for previews.
- **Keeping `X-XSS-Protection: 1; mode=block`** out 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 guides](https://developer.mozilla.org/en-US/docs/Web/Security/Practical_implementation_guides)
- [MDN: Content-Security-Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Security-Policy) and [X-XSS-Protection](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-XSS-Protection)
- [MDN: HTTP Observatory](https://developer.mozilla.org/en-US/observatory)
- [OWASP Secure Headers Project](https://owasp.org/www-project-secure-headers/)
- [Cloudflare: Create a response header transform rule](https://developers.cloudflare.com/rules/transform/response-header-modification/create-dashboard/)
- [Amazon CloudFront: Use managed response headers policies](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-managed-response-headers-policies.html)
- [Next.js: Content Security Policy](https://nextjs.org/docs/app/guides/content-security-policy)
- [Nginx: headers module](https://nginx.org/en/docs/http/ngx_http_headers_module.html) and [Apache: mod_headers](https://httpd.apache.org/docs/2.4/mod/mod_headers.html)

Next steps: [configure HSTS if appropriate](https://checklist-seo-geo.com/en/security-infrastructure/configure-hsts-if-appropriate), [limit third-party scripts](https://checklist-seo-geo.com/en/performance-core-web-vitals/limit-third-party-scripts) and [update the CMS, plugins and dependencies](https://checklist-seo-geo.com/en/security-infrastructure/update-cms-plugins-dependencies).
