{
    "title": "How to set up HTTP security headers on WordPress: CSP, HSTS and the rest",
    "seo_title": "How to set up HTTP security headers on WordPress",
    "h1": "How to set up HTTP security headers on WordPress: CSP, HSTS and the rest",
    "description": "CSP, HSTS, X-Frame-Options, Referrer-Policy, Permissions-Policy: what WordPress already sends, safe values and how to test them.",
    "lead": "What each HTTP security header does, what WordPress already sends, starting values, headers to drop and how to test without breaking the site.",
    "language": "en",
    "locale": "en-US",
    "type": "article",
    "url": "https://www.wp-feint.com/http-security-headers-wordpress/",
    "canonical": "https://www.wp-feint.com/http-security-headers-wordpress/",
    "markdown": "https://www.wp-feint.com/http-security-headers-wordpress/index.md",
    "json": "https://www.wp-feint.com/http-security-headers-wordpress/index.json",
    "published": "2026-09-13T07:00:00+00:00",
    "modified": "2026-11-22T14:32:27+00:00",
    "site": {
        "name": "WP Feint",
        "url": "https://www.wp-feint.com/"
    },
    "translations": [
        {
            "language": "en",
            "hreflang": "en-US",
            "title": "How to set up HTTP security headers on WordPress: CSP, HSTS and the rest",
            "url": "https://www.wp-feint.com/http-security-headers-wordpress/",
            "markdown": "https://www.wp-feint.com/http-security-headers-wordpress/index.md",
            "json": "https://www.wp-feint.com/http-security-headers-wordpress/index.json"
        },
        {
            "language": "fr",
            "hreflang": "fr-FR",
            "title": "Comment configurer les en-têtes de sécurité HTTP sur WordPress : CSP, HSTS et les autres",
            "url": "https://www.wp-feint.com/fr/en-tetes-securite-http-wordpress/",
            "markdown": "https://www.wp-feint.com/fr/en-tetes-securite-http-wordpress/index.md",
            "json": "https://www.wp-feint.com/fr/en-tetes-securite-http-wordpress/index.json"
        },
        {
            "language": "es",
            "hreflang": "es-ES",
            "title": "Cómo configurar las cabeceras de seguridad HTTP en WordPress: CSP, HSTS y las demás",
            "url": "https://www.wp-feint.com/es/cabeceras-seguridad-http-wordpress/",
            "markdown": "https://www.wp-feint.com/es/cabeceras-seguridad-http-wordpress/index.md",
            "json": "https://www.wp-feint.com/es/cabeceras-seguridad-http-wordpress/index.json"
        },
        {
            "language": "de",
            "hreflang": "de-DE",
            "title": "So richtest du HTTP-Sicherheits-Header in WordPress ein: CSP, HSTS und die anderen",
            "url": "https://www.wp-feint.com/de/http-sicherheits-header-wordpress/",
            "markdown": "https://www.wp-feint.com/de/http-sicherheits-header-wordpress/index.md",
            "json": "https://www.wp-feint.com/de/http-sicherheits-header-wordpress/index.json"
        },
        {
            "language": "it",
            "hreflang": "it-IT",
            "title": "Come configurare le intestazioni di sicurezza HTTP su WordPress: CSP, HSTS e le altre",
            "url": "https://www.wp-feint.com/it/intestazioni-sicurezza-http-wordpress/",
            "markdown": "https://www.wp-feint.com/it/intestazioni-sicurezza-http-wordpress/index.md",
            "json": "https://www.wp-feint.com/it/intestazioni-sicurezza-http-wordpress/index.json"
        },
        {
            "language": "pt",
            "hreflang": "pt-BR",
            "title": "Como configurar os cabeçalhos de segurança HTTP no WordPress: CSP, HSTS e os demais",
            "url": "https://www.wp-feint.com/pt/cabecalhos-seguranca-http-wordpress/",
            "markdown": "https://www.wp-feint.com/pt/cabecalhos-seguranca-http-wordpress/index.md",
            "json": "https://www.wp-feint.com/pt/cabecalhos-seguranca-http-wordpress/index.json"
        },
        {
            "language": "nl",
            "hreflang": "nl-NL",
            "title": "Zo stel je HTTP-beveiligingsheaders in op WordPress: CSP, HSTS en de rest",
            "url": "https://www.wp-feint.com/nl/http-beveiligingsheaders-wordpress/",
            "markdown": "https://www.wp-feint.com/nl/http-beveiligingsheaders-wordpress/index.md",
            "json": "https://www.wp-feint.com/nl/http-beveiligingsheaders-wordpress/index.json"
        }
    ],
    "headings": [
        {
            "level": 1,
            "text": "How to set up HTTP security headers on WordPress: CSP, HSTS and the rest"
        },
        {
            "level": 2,
            "text": "What these headers protect, and what they do not"
        },
        {
            "level": 2,
            "text": "What WordPress already sends"
        },
        {
            "level": 2,
            "text": "The six headers to know, with starting values"
        },
        {
            "level": 3,
            "text": "HSTS: powerful, but hard to undo"
        },
        {
            "level": 3,
            "text": "X-Frame-Options and frame-ancestors"
        },
        {
            "level": 3,
            "text": "Content-Security-Policy: start in report-only mode"
        },
        {
            "level": 2,
            "text": "Headers you should stop adding"
        },
        {
            "level": 2,
            "text": "Where to configure them: server, PHP or plugin"
        },
        {
            "level": 3,
            "text": "Apache or LiteSpeed (.htaccess)"
        },
        {
            "level": 3,
            "text": "Nginx"
        },
        {
            "level": 3,
            "text": "In PHP, in a custom plugin"
        },
        {
            "level": 2,
            "text": "Testing without breaking the site"
        },
        {
            "level": 2,
            "text": "With WP Feint"
        },
        {
            "level": 3,
            "text": "Key takeaways"
        },
        {
            "level": 2,
            "text": "Sources"
        }
    ],
    "body": "HTTP security headers are a few lines sent with every page. They do not repair a vulnerable plugin, but they tell your visitors' browsers to refuse certain dangerous behaviors: loading over HTTP, displaying the page inside a booby-trapped frame, running a script from somewhere else. This article explains what each header does, what WordPress already sends, sensible starting values and how to test them without breaking the admin area.\n\nQuick definition: [HTTP security headers](https://www.wp-feint.com/glossary/http-security-headers/). Ready-made solution: [WordPress security headers with WP Feint](https://www.wp-feint.com/features/security-headers/).\n\n## What these headers protect, and what they do not\n\nA security header is an instruction: the server sends it, the browser enforces it. The protection therefore applies to the **visitor** and to the way your pages are displayed. A bot attacking `wp-login.php` or a plugin directly ignores these instructions completely.\n\n- **They limit the impact** of an [XSS](https://www.wp-feint.com/glossary/xss/) flaw, [clickjacking](https://www.wp-feint.com/glossary/clickjacking/) or interception on public Wi-Fi.\n- **They do not block** [SQL injection](https://www.wp-feint.com/glossary/sql-injection/), a malicious file upload or privilege escalation in a plugin: only updating fixes those flaws.\n- **They add to** the other layers (updates, two-factor authentication, backups) without replacing them.\n\n![Diagram mapping six HTTP security headers to the risks they limit, with a green or orange dot depending on the risk of breaking something](https://www.wp-feint.com/media/carte-en-tetes-en.webp)\n\n## What WordPress already sends\n\nWordPress sets a few headers itself, but only on certain responses. Knowing them keeps you from adding duplicates with conflicting values.\n\n| Response | Header sent by WordPress | Since |\n| --- | --- | --- |\n| Admin area (`admin_init`) and login page (`login_init`) | `X-Frame-Options: SAMEORIGIN` | WordPress 3.1.3 |\n| Admin area and login page | `Content-Security-Policy: frame-ancestors 'self';` | WordPress 6.9 |\n| Admin area and login page | `Referrer-Policy: strict-origin-when-cross-origin` | WordPress 4.9 (current value since 4.9.5) |\n| REST API and `admin-ajax.php` | `X-Content-Type-Options: nosniff` | Present in the current code |\n| Public pages of the site | None of these headers by default |  |\n\n*Core functions send_frame_options_header() and wp_admin_headers(), checked in the WordPress 6.9 source code.*\n\nIn other words, it is your **public pages** that remain unprotected. That is where you need to act.\n\n## The six headers to know, with starting values\n\n| Header | Purpose | Starting value | Risk of breakage |\n| --- | --- | --- | --- |\n| `Strict-Transport-Security` | Enforces HTTPS for subsequent visits | `max-age=31536000` after a short trial period | Low if the whole site is on HTTPS, high if a subdomain is not |\n| `X-Content-Type-Options` | Stops the browser from guessing a file's type | `nosniff` | Very low |\n| `X-Frame-Options` | Prevents display inside another site's frame | `SAMEORIGIN` | Low; `DENY` would break the Customizer preview |\n| `Referrer-Policy` | Limits the URL passed to linked sites | `strict-origin-when-cross-origin` | Very low |\n| `Permissions-Policy` | Turns off sensitive browser APIs | `camera=(), microphone=(), geolocation=()` | Medium if a plugin uses geolocation or the camera |\n| `Content-Security-Policy` | Lists allowed sources (scripts, styles, frames, and so on) | Report-only mode first | High: must be built site by site |\n\n### HSTS: powerful, but hard to undo\n\n`Strict-Transport-Security` tells the browser to use only HTTPS for `max-age` seconds. The browser ignores this header if it arrives over HTTP, and the very first visit stays exposed until the browser has received it once. To turn HSTS off, you must send `max-age=0` over HTTPS: impossible if your certificate has expired in the meantime.\n\n![HSTS sequence between a browser and a WordPress site: HTTP request, 301 redirect, HTTPS request, then a response with the Strict-Transport-Security header](https://www.wp-feint.com/media/hsts-premiere-visite-en.webp)\n\nThe `hstspreload.org` preload list removes this weak spot, under strict conditions: a valid certificate, a redirect from HTTP to HTTPS on the same host, all subdomains on HTTPS, and a header with a `max-age` of at least 31536000 seconds (one year), `includeSubDomains` and `preload`. The site warns that inclusion cannot easily be undone and that removal takes months to reach users. Only request preloading if all your subdomains (webmail, staging, an old extranet) will stay on HTTPS for the long term.\n\n### X-Frame-Options and frame-ancestors\n\nBoth prevent another site from displaying yours inside an invisible frame to trick you into clicking. OWASP recommends the CSP `frame-ancestors` directive, which supersedes `X-Frame-Options` in browsers that support it. Sending both, with `SAMEORIGIN` and `'self'`, mirrors what WordPress already does for the admin area since version 6.9.\n\n### Content-Security-Policy: start in report-only mode\n\nCSP is the most effective header against injected scripts, and the trickiest on WordPress: core, themes and many plugins write inline scripts. A strict policy copied from a tutorial often blocks the editor, forms or analytics. The right method:\n\n1. Send `Content-Security-Policy-Report-Only`: the browser reports violations without blocking anything.\n2. Open the developer tools console on the home page, a post, the cart and the editor, and note every blocked source.\n3. To collect reports remotely, add `report-to` and the `Reporting-Endpoints` header: without a destination, no report is sent.\n4. Switch to `Content-Security-Policy` only once the console stays clean on every important user journey.\n\nSince WordPress 5.7, the `wp_get_script_tag()` and `wp_get_inline_script_tag()` functions and the `wp_script_attributes` filter let you add a `nonce` attribute to properly enqueued scripts. Scripts that a theme or plugin writes directly into the HTML do not benefit: that is why many WordPress policies keep `'unsafe-inline'` at first, which weakens the protection against XSS.\n\n```\nContent-Security-Policy-Report-Only: default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'self'\n```\n\nThis starting point is deliberately permissive: it is meant for measuring, not protecting. Then tighten it source by source (font domain, analytics tool, payment gateway).\n\n## Headers you should stop adding\n\nMany older guides and plugins still suggest abandoned headers. Adding them no longer protects anything, and one of them can even do harm.\n\n| Header | Current status | What to do |\n| --- | --- | --- |\n| `X-XSS-Protection` | Deprecated and non-standard (MDN). Can create XSS flaws on otherwise safe sites. | Do not send it, or send it set to `0`. Use a CSP. |\n| `Expect-CT` | Discouraged by OWASP, which recommends removing it. | Remove it. |\n| `Feature-Policy` | Replaced by `Permissions-Policy`, which uses a different syntax. | Convert it, for example `camera=()`. |\n| `X-Powered-By` and a detailed `Server` | Not security headers: they advertise the PHP or server version. | Remove them (`expose_php = Off` in PHP) or neutralize them. |\n\n## Where to configure them: server, PHP or plugin\n\nThe choice depends on your hosting. The general rule: the earlier the instruction is set, the more responses it covers.\n\n- **At the server level** (Apache or LiteSpeed `.htaccess`, Nginx configuration): also covers static files, errors and pages served by a page cache without going through PHP.\n- **In PHP** (the `send_headers` action): handy on hosting without access to the configuration, but missing from responses that do not load WordPress, such as a page served directly by a cache.\n- **Through a plugin**: same limitation as PHP, with an interface. Check that it does not add the deprecated headers listed above.\n\n### Apache or LiteSpeed (.htaccess)\n\nWith `mod_headers`, the `always` condition also adds the header to error responses and redirects, which the default condition does not.\n\n```\n<IfModule mod_headers.c>\r\n  Header always set Strict-Transport-Security \"max-age=31536000\"\r\n  Header always set X-Content-Type-Options \"nosniff\"\r\n  Header always set X-Frame-Options \"SAMEORIGIN\"\r\n  Header always set Referrer-Policy \"strict-origin-when-cross-origin\"\r\n  Header always set Permissions-Policy \"camera=(), microphone=(), geolocation=()\"\r\n</IfModule>\n```\n\n### Nginx\n\nWithout the `always` parameter (available since Nginx 1.7.5), `add_header` only applies to status codes 200, 201, 204, 206, 301, 302, 303, 304, 307 and 308. Another trap: a `location` block that defines its own `add_header` no longer inherits the headers from the `server` level. Nginx 1.29.3 added `add_header_inherit merge;` to change this behavior.\n\n```\nadd_header Strict-Transport-Security \"max-age=31536000\" always;\r\nadd_header X-Content-Type-Options \"nosniff\" always;\r\nadd_header X-Frame-Options \"SAMEORIGIN\" always;\r\nadd_header Referrer-Policy \"strict-origin-when-cross-origin\" always;\r\nadd_header Permissions-Policy \"camera=(), microphone=(), geolocation=()\" always;\n```\n\n### In PHP, in a custom plugin\n\n```\nadd_action( 'send_headers', function () {\r\n    header( 'X-Content-Type-Options: nosniff' );\r\n    header( 'Referrer-Policy: strict-origin-when-cross-origin' );\r\n    header( 'Permissions-Policy: camera=(), microphone=(), geolocation=()' );\r\n} );\n```\n\nDo not add HSTS in PHP if your host or CDN already sets it: two different values make troubleshooting harder.\n\n## Testing without breaking the site\n\n1. From the command line: `curl -I https://your-site.com/` shows the headers actually received. Also test a 404 page, an image from `wp-content/uploads` and `wp-login.php`.\n2. In the browser: the Network tab of the developer tools, then the response for the main document.\n3. With Mozilla's HTTP Observatory, part of MDN since July 2024, which grades the configuration and explains each point.\n4. Then walk through the sensitive features: block editor, Customizer, forms, checkout, video embeds.\n5. Clear every cache (plugin, host, CDN) before each test: a cached page can keep the old headers.\n\n*Talk in French: an overview of security headers (CSP, HSTS, X-Frame-Options, COxP) and the attacks they limit.*\n\n*AFUP talk (in French) on setting up a Content Security Policy in a PHP application.*\n\n## With WP Feint\n\nThe free plugin already adds `X-Content-Type-Options: nosniff` from level 1 of the Hardening module. [WP Feint Pro](https://www.wp-feint.com/features/security-headers/) manages security headers from the admin area (HSTS, X-Frame-Options, Referrer-Policy, CSP, and more) without editing server files. As with any PHP-based solution, a page served by an upstream cache may not carry these headers: check the result with `curl` and, if needed, see the [host and cache compatibility](https://www.wp-feint.com/features/hosting-and-cache-compatibility/) page. The [comparison](https://www.wp-feint.com/free-vs-pro/) details where the line falls between the free and Pro versions.\n\nA hosted cookie consent platform loads its script from its own domain, which must then be allowed in the CSP; our [comparison of cookie consent plugins](https://www.wp-feint.com/wordpress-cookie-consent-plugins-compared/) shows which solutions stay on your server.\n\n### Key takeaways\n\n- Security headers protect your visitors, not your code: they complement updates without replacing them.\n- WordPress already protects the admin area and login page against framing; your public pages have nothing by default.\n- Roll out nosniff, SAMEORIGIN, Referrer-Policy and Permissions-Policy first, as they rarely break anything.\n- Ramp up HSTS in stages and only request preloading if all subdomains are on HTTPS.\n- Build your CSP in report-only mode, page by page, before enforcing it.\n- Stop sending X-XSS-Protection, Expect-CT and Feature-Policy.\n\n## Sources\n\n- [MDN: Strict-Transport-Security](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Strict-Transport-Security)\n- [HSTS Preload List Submission (submission requirements)](https://hstspreload.org/)\n- [MDN: X-XSS-Protection](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-XSS-Protection)\n- [OWASP HTTP Headers Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/HTTP_Headers_Cheat_Sheet.html)\n\nOther sources consulted: official documentation.",
    "categories": [
        "Hardening"
    ],
    "format": "application/json"
}