| 开发者 | cododigital |
|---|---|
| 更新时间 | 2026年11月7日 23:57 |
| PHP版本: | 7.4 及以上 |
| WordPress版本: | 7.1 |
| 版权: | GPLv2 or later |
| 版权网址: | 版权信息 |
Content-Security-Policy-Report-Only: nothing is blocked, and browsers report what would be. When the reports are clean, enforce it with one button.object-src 'none'), no <base> hijacking, forms posting only to your site, and no framing by other sites.wp-config.php kill switch.frame-src for YouTube would normally stop it falling back to default-src, silently blocking your own iframes. The plugin copies the inherited sources across first.204 response.frame-ancestors is left out of /embed/ pages, which exist to be framed by other sites.'unsafe-inline' for scripts and styles and works as an allowlist. It still blocks scripts from hosts you haven't listed, eval, plugins, <base> hijacking, form hijacking, data exfiltration through connect-src, and clickjacking.
If your site can do without inline scripts, remove 'unsafe-inline' from script-src. The change goes through a draft first, and the Reports tab shows exactly what breaks.
For hosts and agencies: configuration in wp-config.php
define( 'CODO_CSP_DISABLE', true ); // Send no policy headers at all. define( 'CODO_CSP_MODE', 'enforce' ); // Or 'report-only'. define( 'CODO_CSP_REPORT_URI', 'https://example.report-uri.com/r/d/csp/enforce' ); define( 'CODO_CSP_LOGIN', false ); // No policy on wp-login.php.
Constants override the settings screen and show as read-only there.
For developers
codo_csp_headers filter: change the headers before they are sent. Receives array( name => array( values ) ) and the context (site or login).codo_csp_skip_request filter: return true to send no policy on a front-end request.codo_csp_presets filter: add or change presets.codo_csp_default_rules filter: change the policy a site starts with.codo_csp_capability filter: change who can manage the policy (default manage_options).codo_csp_report_rate_limit filter: report requests processed per minute (default 120).codo_csp_max_report_rows filter: different violations kept (default 500).codo_csp_policy_changed action: fires when a policy changes. Hook in to purge a cache or CDN the plugin doesn't know about.codo_csp_purge_caches action: fires after the plugin purges page caches.codo_csp_mode_changed action: fires when switching between Report-Only and enforced.codo-content-security-policy folder to /wp-content/plugins/.It only does Content Security Policy. Security suites tend to offer CSP as one setting among many, often a text box for the header with little help building it. This plugin is built around getting the policy right: it starts in Report-Only, collects violation reports on your own site, scans your pages for the sources they use, and puts changes to an enforced policy through a draft first. It adds no firewall, login protection or malware scanning, so it sits alongside whichever security plugin you already use. Just make sure that plugin isn't also sending a policy header; the scan warns you if one is.
Not while it's in Report-Only, which is how it starts: browsers only report. Enforce it once the Reports tab is quiet. After that, changes that could block something go through a draft first.
They're the users an attack on the front end usually targets, because their browser holds an admin session. So the front end gets the same policy for everyone. The only exceptions are page builders and the Customizer preview (see below). Note that the admin bar adds a few requests for logged-in users that visitors don't make, so expect a few reports that only logged-in users trigger.
Front-end editors inject inline code that an enforced policy blocks, so no policy is sent inside them by default. This applies to the Customizer preview and to Elementor, Divi, Beaver Builder, Bricks, Oxygen, WPBakery, Thrive, Brizy and Avada, for users who can edit. Make sure "Page builders" is ticked on the Settings tab. For other builders, use the codo_csp_skip_request filter.
Full-page caches store the headers with the page. The plugin purges the common cache plugins when the policy changes. For anything else, such as Cloudflare, Varnish, NGINX fastcgi_cache without Nginx Helper, or your host's cache, purge it yourself or hook codo_csp_purge_caches.
Browsers enforce every policy they receive, so a second one (from your server configuration, a CDN, a security plugin or your host) can block something this plugin allows. Remove the other one, or make sure it allows at least as much. A page cache still holding an older version of this plugin's header can also cause the warning; purge it and scan again.
NGINX's default FastCGI buffer is 4 KB or 8 KB, and a large policy can exceed it ("upstream sent too big header"). The policy screen shows the header size and warns over 4 KB. Remove sources you no longer need (wildcards like https://*.example.com can replace several hosts), or raise fastcgi_buffer_size and fastcgi_buffers.
It would allow scripts from any host, which defeats the policy. Add the specific hosts instead. The same applies to https://*, data: and blob:, and to default-src (which covers scripts when script-src is absent), object-src, worker-src and base-uri. Workers may use blob:, because WordPress's emoji loader needs it.
Nonces must change on every response, so they can't be a fixed source. They also don't survive full-page caching. Use a hash for a specific inline script, keeping in mind that browsers ignore 'unsafe-inline' once a hash is present.
Anyone can send reports to your site, and browser extensions inject content that violates every policy (the plugin drops reports it can identify as extensions). Only allow sources you recognise. Sources a scan also found are marked.
Very little. They are handled before the theme loads and init runs, and processing is rate-limited (120 requests a minute by default). Identical reports update a counter instead of adding rows. Collection also switches itself off at the end of the period you choose.
Reports not seen for 30 days are deleted by a daily WP-Cron task, and you can clear them at any time. Reports store the directive, the blocked origin (not the full URL) and the latest page it happened on (the path, not the query string). No IP addresses or user agents are stored.
No.
Yes. Each site has its own policy, mode and reports, managed by its administrators. Network administrators can add network defaults (Network Admin > Settings > Content Security Policy). These are merged into every site's policy and can't be removed by site administrators. A network default that creates a directive on a site keeps the sources that site inherited for it, so adding one never blocks a site's own resources. 'none', hashes and 'strict-dynamic' can't be network defaults. Removing a network default applies to every site straight away, without a draft.