Skip to main content
wp-config.org

Search tools

Security and SSL

Free CSP generator for WordPress security headers

Build a Content Security Policy and the other security headers your WordPress site should send. Every directive and keyword is explained in plain English, presets for Google, Stripe, PayPal, Cloudflare and others come from each vendor’s own documentation, and the result is ready to paste into Nginx, Apache, Cloudflare, Caddy or WordPress.

  • CSP builder
  • Vendor presets
  • Nginx, Apache, Cloudflare
  • WordPress plugin

Free, no sign-up. The builder runs in your browser.

This tool needs JavaScript. Turn JavaScript on and reload the page.

Security headers & CSP generator

1. Start from your site (optional)

Enter one page of your site to see the security headers it sends now, what its HTML loads from other websites and how much inline code it has. You get a suggested starting policy you can send to the builder in one click.

2. Build your headers

Choose a starting point, add the services you use, adjust each directive and header, then copy the result for your server, Cloudflare or WordPress. Everything here happens in your browser; nothing you type is sent anywhere.

CSP source keywords and their risk

CSP sources, their risk and what they allow
SourceRiskWhat it allows
'self' Low risk Your own site: the same scheme, host and port as the page (and its https:// version). Not subdomains.
'none' No risk Nothing at all. Must be the only source in its directive; with anything else it is ignored.
'unsafe-inline' High risk Inline <script> and <style> blocks, event handler attributes and javascript: links. In script-src it lets injected script run, which is what CSP is meant to stop. Ignored by modern browsers when a nonce or hash is also listed.
'unsafe-eval' High risk eval(), new Function() and setTimeout with a string: turning text into running code. Injected text can become script.
'strict-dynamic' Low risk Scripts allowed by a nonce or hash may load further scripts. Browsers that support it then ignore host and scheme sources, 'self' and 'unsafe-inline' in that directive, so a nonce or hash is required.
'wasm-unsafe-eval' Medium risk WebAssembly compilation, without allowing JavaScript eval().
'unsafe-hashes' Medium risk Lets a hash also allow matching event handler attributes (onclick="…") and style="" attributes. Safer than 'unsafe-inline', but those attributes are hard to keep safe.
'report-sample' No risk Adds the first 40 characters of blocked inline code to violation reports. Changes nothing that is allowed.
'inline-speculation-rules' Low risk Inline <script type="speculationrules"> blocks (prefetch and prerender rules) without allowing other inline scripts.
'trusted-types-eval' Medium risk eval() with Trusted Types objects only, when Trusted Types are enforced.
'report-sha256' No risk Adds a SHA-256 hash of each script file to violation reports. Changes nothing that is allowed.
'report-sha384' No risk Adds a SHA-384 hash of each script file to violation reports.
'report-sha512' No risk Adds a SHA-512 hash of each script file to violation reports.
'nonce-R4nd0m…' Low risk Allows the inline or external <script> or <style> that carries nonce="R4nd0m…". The value must be random and new for every response, so only an application that writes each page can use it; a fixed nonce in a server configuration protects nothing.
'sha256-…' Low risk Allows the inline block whose contents have exactly this SHA-256, SHA-384 or SHA-512 hash (Base64). Any change to the code, even a space, needs a new hash.
https://cdn.example.com Low risk One host. Without a path, every file on it is allowed; with a path ending in /, that folder; with a full path, that file only.
https://*.example.com Medium risk Every subdomain of example.com (not example.com itself). In script-src, only safe if nobody else can put files on any of them.
https: High risk A scheme: every address that starts with it. https: in script-src allows script from any website on the internet.
data: High risk Addresses holding their own content. Fine in img-src and font-src; in script-src or object-src it lets injected code run.
blob: Medium risk Files made in the page by script. Needed by some image editors and workers; avoid it in script-src.
* High risk Any http:, https:, ws: and wss: address (not data: or blob:). In script-src it removes the protection.

WordPress, WooCommerce and page builders

  • Public pages only. wp-admin and the block editor rely on inline scripts and eval-style code, so a CSP strict enough to protect your public pages breaks them. Every output here leaves /wp-admin/ and wp-login.php out: the server and Cloudflare outputs by address, the WordPress ones because the send_headers hook only runs for public pages.
  • 'unsafe-inline' is normal at first. WordPress core, themes and blocks print inline <script> and <style> blocks (script data, global styles from theme.json, block supports), and core does not add nonces to them. Start with the WordPress template; removing 'unsafe-inline' from script-src later needs a theme and plugins that support nonces or hashes.
  • WooCommerce. Checkout loads your payment gateway’s scripts and frames: tick its preset (Stripe, PayPal) and test a full order, including 3D Secure, in Report-Only mode first. Add any other services your gateway, tax or shipping plugins call, as the reports show them.
  • Elementor, Divi and other page builders. Their front ends add inline styles and often inline scripts, so expect to keep 'unsafe-inline'. Their editors show your public page inside the editor (in a frame, or on the page itself for signed-in editors), so the public page’s policy applies there too: keep frame-ancestors at 'self' (not 'none'), and if an editor breaks, use a WordPress output with “no CSP for signed-in users”. Some features use eval-style code and need 'unsafe-eval'; add it only when a report shows it is needed.
  • Page caching. Headers sent from PHP (functions.php or the plugin) are missing on pages a caching plugin or host serves straight from disk. Use the server or Cloudflare output in that case, and check a cached page with the HTTP headers tool.
  • Security plugins and hosts. Some already send HSTS, X-Frame-Options and others. Send each header from one place only.

Rolling out a policy without breaking your site

  1. Start with Report-Only (Content-Security-Policy-Report-Only). It blocks nothing; browsers report what the policy would block.
  2. Collect reports with a reporting address, or open your browser’s developer console (F12) and browse every kind of page: home, posts, forms, search, shop, cart, checkout, account, and as a signed-in user.
  3. For each report, decide: add the source if it is a service you use, or find out why the page loads it if you do not recognise it.
  4. When the reports stop, switch to Enforce. Keep the reporting address, so you hear about anything a later plugin update needs.
  5. For HSTS, start with a short max-age and raise it step by step, as hstspreload.org recommends.

What you can do

  • Build a Content Security Policy directive by directive, with warnings

  • Add Google Analytics, Stripe, PayPal and more from vendors’ own lists

  • Start from the headers and sources your own page has now

  • HSTS, Referrer-Policy, Permissions-Policy and more, with safe defaults

  • Copy it for Nginx, Apache, Cloudflare, Caddy or a meta tag

  • Download a small WordPress plugin or paste a functions.php snippet

How to make your security headers

  1. Start from your site or a template

    Enter your home page to see the security headers it sends and what its HTML loads, then press “Use this in the builder”. Or keep the WordPress public site template the builder opens with.

  2. Add your services and check the warnings

    Tick the presets for the services you use, adjust the directives and the other headers, and read the check under the output: each problem says what to change.

  3. Install it in Report-Only mode first

    Choose your server, Cloudflare or WordPress and follow the steps. Browse your site with the browser console open, or collect reports, add what is missing, then switch the policy to Enforce.

What security headers do

Security headers are instructions your server sends with every page, telling browsers how to protect your visitors. The most powerful is the Content Security Policy (CSP): a list of the places your pages may load scripts, styles, images, fonts and frames from. If an attacker manages to inject a script into a page, through a vulnerable plugin or a hacked advertisement, the browser refuses to run it because it is not on the list.

The other headers

Strict-Transport-Security (HSTS) makes browsers use only HTTPS for your site. X-Content-Type-Options stops browsers guessing file types. X-Frame-Options and the CSP’s frame-ancestors stop other sites showing your pages in a frame to trick visitors into clicking (clickjacking). Referrer-Policy limits how much of your page addresses other sites see, and Permissions-Policy turns off browser features such as the camera and microphone that your site never uses.

Why the builder starts in Report-Only mode

A policy that is too strict blocks parts of your own site: a chat widget, a payment form, a font. In Report-Only mode browsers block nothing and report what they would have blocked, so you can add what is missing before anything breaks. Browse every kind of page, including forms, checkout and pages you see signed in, before you switch to Enforce.

Why there is no nonce option for server files

A nonce is a random value that must be new for every page view and match the nonce on your own script tags. A server configuration file, a Cloudflare rule or a WordPress snippet sends the same text every time, so a nonce there would be a fixed value anyone can copy. The builder warns if you add one, and offers hashes instead, which work for inline code that never changes.

WordPress

Apply the policy to your public pages only: wp-admin and the block editor need inline and eval-style code that a useful policy blocks, so every output here leaves them out. Check the result with the HTTP headers tool once it is live, and see the .htaccess and Nginx generators for the rest of your server configuration.

Frequently asked questions

What is a Content Security Policy?

A Content-Security-Policy header lists where a page may load scripts, styles, images, fonts, frames and other files from, and whether inline code may run. Browsers block anything not on the list, which stops most cross-site scripting attacks from doing harm even when an attacker gets code into a page.

Is the security headers generator free?

Yes. There is no sign-up. The builder has no limits because it runs in your browser. “Start from my site” runs on this site’s server, so it shares the connection checks’ limit on how many checks one visitor can run.

Will a Content Security Policy break my WordPress site?

An enforced policy that misses something will block it, which is why the builder starts in Report-Only mode: nothing is blocked while you collect reports and add what is missing. Applying the policy to public pages only keeps wp-admin and the block editor working.

Why does the WordPress template allow 'unsafe-inline'?

WordPress core, themes and blocks print inline scripts and styles, and core does not give them nonces. Without 'unsafe-inline' those would be blocked. It still leaves you with a policy that controls which other sites can load scripts, frames and fonts. Removing it later needs a theme and plugins that support nonces or hashes.

What is the difference between Report-Only and Enforce?

Content-Security-Policy-Report-Only blocks nothing; browsers only report what the policy would block, in the console or to a reporting address. Content-Security-Policy enforces the policy and blocks what it does not allow. Use Report-Only first and switch once the reports stop.

Should I use the WordPress plugin or my server configuration?

The server configuration (Nginx, Apache or Caddy) or a Cloudflare rule is the most reliable, because it covers every response. The plugin and the functions.php snippet run in PHP, so pages a caching plugin or host serves straight from disk are sent without the headers. Use them when you cannot change the server, and check a cached page with the HTTP headers tool.

Why is there no preset for YouTube or the Facebook pixel?

A preset is only included when the vendor publishes the sources its service needs, so every source is the vendor’s own. YouTube, Vimeo, Meta, Jetpack, Gravatar and Mailchimp do not publish one. Add the host from your embed code yourself; “Start from my site” finds the frames and scripts a page loads.

Is what I enter stored?

The builder sends nothing: what you type, the outputs and the plugin ZIP stay in your browser. “Start from my site” sends the address to this site’s server, which fetches that one page and keeps nothing it downloads. To count how the tool is used, this site keeps the domain you checked for 12 months, with the time, the outcome, your approximate location (country, region and city), the site you came from and your type of device and browser, but no IP address. The privacy policy has the details.

Related tools

  • Check a URL’s HTTP response headers and redirect chain.

  • .htaccess

    New (added recently)

    Generate a WordPress .htaccess with security, HTTPS, WooCommerce and caching rules, plus the matching Nginx rules.

  • Generate an Nginx config for WordPress with TLS, caching, HTTP/2 and HTTP/3.

  • SSL checker

    New (added recently)

    Check a website’s SSL certificate, chain, expiry and TLS versions, with fixes for each problem.