| 开发者 | dandawson |
|---|---|
| 更新时间 | 2026年9月16日 02:00 |
| PHP版本: | 7.2 及以上 |
| WordPress版本: | 7.1 |
| 版权: | GPLv2 or later |
| 版权网址: | 版权信息 |
wp-config.php insteadCF-Connecting-IP is trusted only when the request reaches the site from a Cloudflare edge address; the range list is refreshed daily from Cloudflare's public endpoint. If the site sits behind an additional proxy or load balancer, list its addresses in this optional constant so forwarded headers are honoured:
define( 'EDGE404_TRUSTED_PROXIES', '10.0.0.0/8, 203.0.113.7' );
Otherwise a request is attributed to the address it actually connected from, which cannot be forged. Private and reserved addresses are never sent to Cloudflare as block targets.
/wp-content/plugins/, or install it from the WordPress admin, then activate it.wp-config.php instead, in which case the constants take precedence and the fields are shown read-only:
define( 'EDGE404_API_TOKEN', 'your-cloudflare-api-token' );
define( 'EDGE404_ZONE_ID', 'your-zone-id' );
Sites set up before 2.0.0 used CF_404_API_TOKEN and CF_404_ZONE_ID. Those names are still honoured, so an existing wp-config.php does not have to be edited: the values are copied into the settings on upgrade and the constants can be removed whenever convenient.
Cloudflare Global API Keys are not supported: they authenticate against the whole Cloudflare account, which is far more access than editing one zone's access rules needs.No. It uses IP Access Rules, which are available on all plans. Cloudflare enforces an account-level quota on the number of rules.
Each line is matched against the request path, the path plus query string, and both of those prefixed with the requested host. That means an entry can be a path (/tracking/*), a host and path (tracking.example.com/tracking/*), a "contains anywhere" pattern (*tracking.example.com*, which also matches that text in a path or query string) or a pasted URL. Use * for wildcards; a pattern with no wildcard must match exactly. Entries saved by earlier versions gain a trailing * on upgrade so previous prefix behaviour is preserved.
They are 404s, so they are logged. Hosts that rewrite links in outgoing mail serve them from a tracking subdomain, so add an entry such as /tracking/* or tracking.example.com/* to the whitelist; matching includes the requested host, so host patterns work too. Nothing host-specific is whitelisted by default.
Blocking falls back to running inline if the scheduled event cannot be created, but expiry, log pruning and diagnostics rely on the scheduled task. Server-level cron and external schedulers work; the plugin warns only when its own maintenance task has not run for two hours, and the warning can be dismissed permanently.
404 records are kept for the configured retention period (1-168 hours, 12 by default). Expired block records are removed a day after expiry. Diagnostic warnings and errors are kept for 7 days and capped at 500 rows. Credentials are redacted from diagnostic output.
Either works. An account token (Manage Account -> Account API Tokens) belongs to the Cloudflare account, so it keeps working when the user who created it loses access, which makes it the better default. A user token (My Profile -> API Tokens) is the only option for a zone reached through an account you are not a member of. One token can serve several sites if its Zone Resources include each zone.
It gets progressively harder to shake off. While an IP is blocked, Cloudflare handles its requests at the edge, so they never reach WordPress to be counted — which is why a returning IP is re-blocked on its first 404 instead of having to earn the full threshold again, and why each successive block within the "Remember offenders" window is twice as long as the last, up to the "Maximum block duration" ceiling. If a 404 does get through while a block is live, the existing block is extended rather than duplicated. Set "Remember offenders" to 0 to treat every block as a first offence.
Deactivating cancels every scheduled task and, unless "Keep Cloudflare blocks when the plugin is deactivated" is enabled in Settings, deletes the Cloudflare access rules the plugin created — nothing would remain to expire them otherwise. Deleting the plugin removes its rules, database tables and options.
wp-config.php. The token is stored in a non-autoloaded option, masked once saved, and never rendered back to the browser; leaving the field empty keeps the stored token.wp-config.php on upgrade are copied into the settings so the constants can be removed at leisure.edge404_ / EDGE404_ rather than being tied to the display name. Tables, options and pending scheduled tasks are moved to the new names on upgrade, and Cloudflare rules created by 1.x are still recognised, so blocks keep expiring on time.EDGE404_API_TOKEN and EDGE404_ZONE_ID. The old CF_404_API_TOKEN, CF_404_ZONE_ID and CF404_TRUSTED_PROXIES names still work and take no action to keep.edge404_ prefix: edge404_notification_subject, edge404_block_duration_minutes, edge404_block_ip_event, edge404_unblock_ip./tracking/* is no longer whitelisted by default and is no longer added to whitelists on upgrade: it only fits sites whose mail service uses a tracking subdomain, and the plugin should not edit a setting the site owner has saved. Add it manually if your host rewrites links in outgoing mail.CF_404_API_TOKEN is recognised and named, since Cloudflare's own answer ("Invalid request headers") does not hint that the wrong kind of credential was used.Bearer prefix included in CF_404_API_TOKEN, are now cleaned up instead of producing a Cloudflare "Invalid request headers" error.cf404_block_duration_minutes filter for sites that want their own escalation curve.duplicate_of_existing, and says so at info level, whether the existing rule is one of ours or came from elsewhere in the zone.CF-Connecting-IP and forwarded-for headers are only trusted from Cloudflare edge addresses or proxies listed in CF404_TRUSTED_PROXIES; private and reserved addresses are never blocked.*tracking.example.com* work; /tracking/* is whitelisted by default so email click-tracking links are not counted.[CF 404 Defender: example.com] Blocked 1.2.3.4 (managed_challenge, 10 min) and are filterable via cf404_notification_subject.admin-post.php with capability and nonce checks.CF_404_API_KEY / CF_404_API_EMAIL) was removed in favour of scoped API tokens. Sites still using it get an admin error explaining the change.uninstall.php to remove rules, tables and options on deletion.cf404_block_ip() returns true or a WP_Error, and a failed API call is no longer logged as a successful block.