{
    "title": "Content Security Policy (CSP)",
    "seo_title": "Content Security Policy (CSP): definition and setup",
    "h1": "Content Security Policy (CSP)",
    "description": "CSP tells the browser which scripts and resources to load. Directives, nonces, report-only mode and pitfalls to avoid on WordPress.",
    "lead": "Content Security Policy (CSP) is an HTTP header through which a site tells the browser which sources of scripts, styles, images or frames it is allowed to load. Anything outside that list is blocked, which greatly limits the impact of a cross-site scripting (XSS) vulnerability.",
    "language": "en",
    "locale": "en-US",
    "type": "definition",
    "url": "https://www.wp-feint.com/glossary/content-security-policy/",
    "canonical": "https://www.wp-feint.com/glossary/content-security-policy/",
    "markdown": "https://www.wp-feint.com/glossary/content-security-policy/index.md",
    "json": "https://www.wp-feint.com/glossary/content-security-policy/index.json",
    "published": "2026-10-28T08:00:00+00:00",
    "modified": "2026-11-22T12:06:58+00:00",
    "site": {
        "name": "WP Feint",
        "url": "https://www.wp-feint.com/"
    },
    "translations": [
        {
            "language": "en",
            "hreflang": "en-US",
            "title": "Content Security Policy (CSP)",
            "url": "https://www.wp-feint.com/glossary/content-security-policy/",
            "markdown": "https://www.wp-feint.com/glossary/content-security-policy/index.md",
            "json": "https://www.wp-feint.com/glossary/content-security-policy/index.json"
        },
        {
            "language": "fr",
            "hreflang": "fr-FR",
            "title": "Content Security Policy (CSP)",
            "url": "https://www.wp-feint.com/fr/definitions/content-security-policy/",
            "markdown": "https://www.wp-feint.com/fr/definitions/content-security-policy/index.md",
            "json": "https://www.wp-feint.com/fr/definitions/content-security-policy/index.json"
        },
        {
            "language": "es",
            "hreflang": "es-ES",
            "title": "Content Security Policy (CSP)",
            "url": "https://www.wp-feint.com/es/glosario/content-security-policy/",
            "markdown": "https://www.wp-feint.com/es/glosario/content-security-policy/index.md",
            "json": "https://www.wp-feint.com/es/glosario/content-security-policy/index.json"
        },
        {
            "language": "de",
            "hreflang": "de-DE",
            "title": "Content Security Policy (CSP)",
            "url": "https://www.wp-feint.com/de/glossar/content-security-policy/",
            "markdown": "https://www.wp-feint.com/de/glossar/content-security-policy/index.md",
            "json": "https://www.wp-feint.com/de/glossar/content-security-policy/index.json"
        },
        {
            "language": "it",
            "hreflang": "it-IT",
            "title": "CSP (Content Security Policy)",
            "url": "https://www.wp-feint.com/it/glossario/content-security-policy/",
            "markdown": "https://www.wp-feint.com/it/glossario/content-security-policy/index.md",
            "json": "https://www.wp-feint.com/it/glossario/content-security-policy/index.json"
        },
        {
            "language": "pt",
            "hreflang": "pt-BR",
            "title": "Content Security Policy (CSP)",
            "url": "https://www.wp-feint.com/pt/glossario/content-security-policy/",
            "markdown": "https://www.wp-feint.com/pt/glossario/content-security-policy/index.md",
            "json": "https://www.wp-feint.com/pt/glossario/content-security-policy/index.json"
        },
        {
            "language": "nl",
            "hreflang": "nl-NL",
            "title": "Content Security Policy (CSP)",
            "url": "https://www.wp-feint.com/nl/woordenlijst/content-security-policy/",
            "markdown": "https://www.wp-feint.com/nl/woordenlijst/content-security-policy/index.md",
            "json": "https://www.wp-feint.com/nl/woordenlijst/content-security-policy/index.json"
        }
    ],
    "headings": [
        {
            "level": 1,
            "text": "Content Security Policy (CSP)"
        },
        {
            "level": 2,
            "text": "How a Content Security Policy works"
        },
        {
            "level": 2,
            "text": "Header, meta tag and report-only mode"
        },
        {
            "level": 2,
            "text": "For WordPress"
        },
        {
            "level": 2,
            "text": "Common mistakes"
        }
    ],
    "body": "In practice, a CSP is an allowlist sent by the server with every page. The browser reads it before running anything, then refuses whatever isn't on it: a script from an unknown domain, an injected style, a frame or a form pointing elsewhere. Its main benefit is to limit the damage of a [cross-site scripting (XSS) vulnerability](https://www.wp-feint.com/glossary/xss/): even if an attacker manages to slip code into a page, the browser can refuse to run it.\n\n## How a Content Security Policy works\n\nA policy is made of directives separated by semicolons. Each directive targets a type of resource and lists the allowed sources:\n\n- `default-src` serves as the fallback for every resource type that doesn't have its own directive;\n- `script-src`, `style-src`, `img-src`, `font-src` cover scripts, styles, images and fonts;\n- `frame-ancestors` says which sites can display the page in a frame, which protects against [clickjacking](https://www.wp-feint.com/glossary/clickjacking/);\n- `object-src 'none'`, `base-uri` and `form-action` close lesser-known injection paths.\n\nAs soon as a `script-src` or `default-src` directive exists, scripts written directly in the HTML and `onclick` attributes are blocked. The `'unsafe-inline'` keyword lifts that ban, but MDN points out that it cancels much of the benefit of CSP. The recommended method, called strict CSP, allows scripts through a [nonce](https://www.wp-feint.com/glossary/nonce/) (a random value that changes with every response, copied into the `<script>` tag) or through the script's SHA-256 hash.\n\n![Five-step diagram: the server sends the page with a Content-Security-Policy header, a script injected from an attacker's domain sits in the page, the browser compares its origin and nonce with the policy, refuses to run it and can send a violation report to the site](https://www.wp-feint.com/media/2026/10/csp-blocage-script-en.webp)\n\n## Header, meta tag and report-only mode\n\nThe policy is preferably sent in the `Content-Security-Policy` HTTP header. A `<meta http-equiv>` tag also works, but the W3C specification states that it ignores `frame-ancestors`, `sandbox` and `report-uri`, and that it can't carry a report-only policy.\n\nReport-only mode is the key to a rollout that doesn't break anything. With `Content-Security-Policy-Report-Only`, the browser blocks nothing: it only reports what it would have blocked, in the console or to an address declared with `report-to` and the `Reporting-Endpoints` header. You adjust the list, then switch to enforcing mode.\n\n```\nContent-Security-Policy-Report-Only: default-src 'self'; script-src 'self' 'nonce-r4nd0m'; object-src 'none'; base-uri 'self'; frame-ancestors 'self'\n```\n\n*Video: “Content Security Policy explained | how to protect against Cross Site Scripting (XSS)” (Jan Goebel)*\n\n## For WordPress\n\nWordPress is tough terrain for a strict CSP: core, themes and many plugins print inline scripts. Since WordPress 5.7, the `wp_get_inline_script_tag()` and `wp_print_inline_script_tag()` functions and the `wp_script_attributes` filter let you add a `nonce` attribute to scripts that are loaded properly, but not to those a theme hard-codes. That's why many sites start with `'unsafe-inline'` and then tighten things up page by page.\n\n- Test in report-only mode the home page, a post, the block editor, forms and checkout.\n- Set the policy at the server level (`.htaccess`, Nginx) if a cache serves pages without going through PHP.\n- Inventory third-party domains: fonts, analytics, videos, payment gateway.\n\nOur guide to [security headers for WordPress](https://www.wp-feint.com/http-security-headers-wordpress/) details a starter policy and the testing method, and the article on XSS vulnerabilities in WordPress shows what a CSP would have limited. CSP belongs to a broader family of [HTTP security headers](https://www.wp-feint.com/glossary/http-security-headers/).\n\n## Common mistakes\n\n- Copying a strict policy from a tutorial and applying it as is: the editor or the cart stops working.\n- Reusing the same nonce from page to page: it must be unpredictable and change with every response, which doesn't play well with page caching.\n- Believing CSP replaces data escaping: OWASP presents it as defense in depth, not as the only protection against XSS.\n\nWP Feint Pro offers a [basic CSP](https://www.wp-feint.com/features/security-headers/) that blocks browser plugins, protects the base URL and upgrades resources to HTTPS. It deliberately doesn't restrict scripts: a policy against XSS still has to be tailored, in the server or CDN configuration.\n\n## Related terms\n\n- [XSS (cross-site scripting)](https://www.wp-feint.com/glossary/xss/)\n- [HTTP security headers](https://www.wp-feint.com/glossary/http-security-headers/)\n- [Nonce](https://www.wp-feint.com/glossary/nonce/)\n- [Clickjacking](https://www.wp-feint.com/glossary/clickjacking/)\n- [HSTS](https://www.wp-feint.com/glossary/hsts/)\n\n\n## Sources\n\n- [MDN : Content Security Policy (CSP)](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP)\n- [W3C : Content Security Policy Level 3](https://www.w3.org/TR/CSP3/)\n- [OWASP : Content Security Policy Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Content_Security_Policy_Cheat_Sheet.html)\n- [Make WordPress Core : fonctions d’attributs de scripts dans WordPress 5.7](https://make.wordpress.org/core/2021/02/23/introducing-script-attributes-related-functions-in-wordpress-5-7/)",
    "definition": "Content Security Policy (CSP) is an HTTP header through which a site tells the browser which sources of scripts, styles, images or frames it is allowed to load. Anything outside that list is blocked, which greatly limits the impact of a cross-site scripting (XSS) vulnerability.",
    "group": "Web security",
    "aka": [
        "CSP",
        "Content-Security-Policy",
        "CSP header",
        "strict CSP"
    ],
    "related": [
        {
            "title": "XSS (cross-site scripting)",
            "url": "https://www.wp-feint.com/glossary/xss/",
            "markdown": "https://www.wp-feint.com/glossary/xss/index.md"
        },
        {
            "title": "HTTP security headers",
            "url": "https://www.wp-feint.com/glossary/http-security-headers/",
            "markdown": "https://www.wp-feint.com/glossary/http-security-headers/index.md"
        },
        {
            "title": "Nonce",
            "url": "https://www.wp-feint.com/glossary/nonce/",
            "markdown": "https://www.wp-feint.com/glossary/nonce/index.md"
        },
        {
            "title": "Clickjacking",
            "url": "https://www.wp-feint.com/glossary/clickjacking/",
            "markdown": "https://www.wp-feint.com/glossary/clickjacking/index.md"
        },
        {
            "title": "HSTS",
            "url": "https://www.wp-feint.com/glossary/hsts/",
            "markdown": "https://www.wp-feint.com/glossary/hsts/index.md"
        }
    ],
    "sources": [
        {
            "title": "MDN : Content Security Policy (CSP)",
            "url": "https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP"
        },
        {
            "title": "W3C : Content Security Policy Level 3",
            "url": "https://www.w3.org/TR/CSP3/"
        },
        {
            "title": "OWASP : Content Security Policy Cheat Sheet",
            "url": "https://cheatsheetseries.owasp.org/cheatsheets/Content_Security_Policy_Cheat_Sheet.html"
        },
        {
            "title": "Make WordPress Core : fonctions d’attributs de scripts dans WordPress 5.7",
            "url": "https://make.wordpress.org/core/2021/02/23/introducing-script-attributes-related-functions-in-wordpress-5-7/"
        }
    ],
    "format": "application/json"
}