CSP Pilot

By Florian Puschmann

0+ active installationsVersion 1.0.0

Introduce a Content Security Policy step by step: guided rollout, built-in report endpoint, self-test for cache and CDN problems. Privacy-friendly.

Description

A Content Security Policy (CSP) is a rule set that your website sends to the browser. It states which sources a page may load scripts, images and other content from, and where it may send data to. Used carefully, it can limit the damage when a third-party script on your site is compromised, mainly by restricting where data can be sent (connect-src), and it makes violations visible.

CSP Pilot helps you introduce a policy without breaking your site, also on shared hosting without server access:

  • Guided rollout in five steps. Scan your site, observe in Report-Only mode, evaluate the reports, check that the header really arrives, then enforce. Every step explains why it exists and what can go wrong. The status of each step is calculated from real data (settings, site scan, reports, self-test), not ticked off by hand.
  • Presets for common services (Google Analytics 4, Tag Manager, reCAPTCHA, Cloudflare Web Analytics, Google Fonts, YouTube, Vimeo). Every entry comes from the service’s own documentation and shows its source and check date. You see a preview and confirm; nothing is removed.
  • Safe by default. The plugin starts in Report-Only mode: nothing is blocked. It never switches to Enforce by itself, and switching needs an explicit confirmation. An emergency switch in wp-config.php stops the header at once.
  • Built-in report endpoint. Browsers send violation reports to your own site (Reporting API and the older report-uri). They are summarised in the admin area, so you do not need an external reporting service.
  • Adopt source. A report for a host can be turned into a rule: you see a before/after preview of the directive and confirm. Inline code, eval, data:, blob: and browser extensions get an explanation instead of a button.
  • Site scan. On a button, the plugin reads pages of your own site (the home page, a page you pick, the login page or the 20 latest pages) like a visitor and shows which sources they use that your policy does not cover. Strict limits apply: only your own site, no cookies, no automatic redirects to other sites, time and size limits, one scan at a time. It sees only the delivered page and your own style sheets, not what scripts load later.
  • Draft for a stricter policy. In Enforce mode, a change that could block something is saved as a draft and sent as Report-Only next to the enforced policy, so real browsers test it first.
  • Guard rails. Values that practically switch a policy off in script-src and similar directives (https:, data:, whole top-level domains, public CDNs) are refused unless you confirm.
  • Take over rules of another policy (from a header found by the scan, or pasted): every rule is checked, safe ones are ticked, unsafe ones refused.
  • Self-test. Checks that exactly one policy arrives (a cache, a CDN or a second plugin can remove or double the header), that the report address is sent, and that a test report is stored.
  • Explanations for every setting. The plugin is fully translatable; translations are delivered through translate.wordpress.org.
  • Privacy-friendly. Only reduced data is stored: directive, blocked host or keyword, page path without query string and fragment, mode, time and a counter. No IP addresses, no user agents, no cookies, no full URLs. Reports are deleted automatically (7 to 90 days, default 30). A suggestion for your privacy statement is included (it is not legal advice).
  • No external services. No telemetry, no calls to other sites. The self-test and the site scan only request pages of your own site. See “External services” below.

What it does not do

  • There is no guarantee. A CSP is one layer of protection, not a complete defence, and a wrongly configured policy can break parts of your site. Always start in Report-Only mode and test your important pages.
  • The included “Basis” template allows inline scripts and styles ('unsafe-inline'), which is the usual WordPress compromise. This reduces the protection against injected code. It does not weaken the limit on where data can be sent.
  • No nonce or hash mode ('strict-dynamic' with nonces). Nonces do not work together with page caching, because all visitors would get the same value.
  • No crawler and no scan in the background. The site scan runs only when you press the button, and you decide which sources to allow.
  • It does not manage other security headers (HSTS, X-Content-Type-Options and so on).
  • It cannot guarantee compatibility with every plugin, theme or page builder. Front-end editors such as Elementor are excluded for logged-in administrators by default, and the header is not sent inside the Customizer preview and common page builders (checked with test doubles, not with every builder).

Requirements

PHP 7.4 or newer, WordPress 6.0 or newer. For the Reporting API (report-to) the site must be served over https; browsers fall back to report-uri otherwise.

External services

CSP Pilot does not connect to any external or third-party service. It sends no telemetry and loads no scripts, styles, fonts or images from other sites.

The only HTTP requests the plugin makes go to your own site, and only when you start them in the admin area:

  • Self-test (Settings → CSP Pilot → Self-test, on a button): requests your own home page to check which policy header arrives, and sends one test report to the report endpoint of your own site.
  • Site scan (on a button): requests pages of your own site (and its own style sheets) like a visitor. Addresses on other hosts are never requested; redirects to other sites are not followed.

No personal data is sent anywhere by these requests.

Service presets. The configuration offers presets for Google Analytics 4, Google Tag Manager, Google reCAPTCHA, Cloudflare Web Analytics, Google Fonts, YouTube and Vimeo. A preset only adds the host names of that service (for example https://www.googletagmanager.com) as text to your Content Security Policy header, after you preview and confirm it. CSP Pilot never contacts these services and does not embed them: the header only tells the visitor’s browser that your site may load content from them, which matters only if your site already uses the service (for example through another plugin or your theme). Using such a service is subject to its own terms and privacy policy, for example:

The code also names a few public CDN hosts (for example cdn.jsdelivr.net), only to warn when you try to allow all of them for scripts, and the documentation pages each preset was taken from, which are shown as text in the admin area. None of these addresses is contacted by the plugin.

Installation

  1. Upload the plugin folder to /wp-content/plugins/ or install the ZIP file under Plugins → Add New → Upload.
  2. Activate the plugin. It starts in Report-Only mode with the template “Basis”; nothing is blocked.
  3. Open Settings → CSP Pilot and follow the steps on the “Introduction” tab.

FAQ

Will it break my site?

Not in Report-Only mode: the browser only reports what it would block. Enforce mode can break things that were not allowed in the policy. Switch to Enforce only after you have evaluated the reports and run the self-test, and test your forms, search, consent banner and embedded content right afterwards.

How do I switch it off if I am locked out or the site breaks?

Add this line to wp-config.php (above the line “That’s all, stop editing!”):

define( 'CSPP_DISABLE', true );

The plugin then sends no header at all. Empty page caches and CDN caches afterwards.

I changed the policy, but visitors still get the old one.

Page caches and CDNs can store the headers together with the page. Empty them after every change. The self-test helps to find out where the header is lost.

Why is the header not sent to me when I am logged in as administrator?

By default the header is not sent to administrators, because front-end editors such as Elementor load many scripts a policy would block. You can change this on the Configuration tab. Other visitors always get the header. The admin area and the login page never get it.

Why do I see no reports?

Visit your pages without being logged in as administrator. If still nothing appears, run the self-test: a cache or CDN may remove the header, or a security plugin or firewall may block the REST API for visitors (the report address is a public REST route, because browsers send reports without logging in).

What does the plugin store?

Directive, blocked host or keyword, page path (without query string), mode, time, counter. See the text for your privacy statement on the “Self-test & help” tab; WordPress also shows it under Settings → Privacy → Policy Guide. To fend off misuse, the visitor’s IP address is used for at most two minutes as a salted hash value inside a rate-limit counter; it is not stored together with the reports. The text for your privacy statement is a suggestion, not legal advice, and the plugin cannot make a website compliant with any law: please check it against your own situation.

Does the plugin contact other websites?

No. There is no telemetry and no external service. The self-test and the site scan request only pages of your own site (the scan refuses redirects to other sites and never downloads style sheets of other sites). To switch the scan off completely, add define( 'CSPP_NO_SCAN', true ); to wp-config.php.

Does a preset load anything from Google, Cloudflare or other services?

No. A preset only writes the host names of the service into the policy header that your site sends, so that your visitors’ browsers may load what your theme and plugins already use. CSP Pilot itself never loads or requests anything from those hosts.

What does the site scan store?

Only the source (domain or keyword), the page path without query string and a counter, and for single files the path of the file. No page content. You can delete the result at any time.

Does it work on multisite?

Yes. Each site has its own policy, mode and reports. A network administrator can add network defaults (hosts that every site gets); sites cannot remove them.

Can I set the mode in wp-config.php?

Yes: define( 'CSPP_MODE', 'enforce' ); (or 'report-only'). The setting is then read-only in the admin area.

Which languages are available?

The plugin is written in English and fully translatable. Translations are provided by the community through translate.wordpress.org and installed by WordPress automatically.

Screenshots

Changelog

1.0.0

  • Initial release: header engine with Report-Only and Enforce mode and an emergency switch, configuration with templates, service presets, guard rails and explanations, draft for stricter policies, report endpoint and storage, report overview with “Adopt source”, site scan on request, import of rules from another policy, self-test, five-step introduction, multisite network defaults, fully translatable.