Add-ons
Add-ons

Cloudflare add-on for WP Cerber


The Cloudflare add-on for WP Cerber synchronizes selected WP Cerber IP decisions with Cloudflare IP Access Rules. When enabled, it can create and remove Cloudflare rules for WP Cerber lockouts and for entries in the Allowed and Blocked IP Access Lists. Because Cloudflare applies these rules before a request reaches your WordPress server, the add-on can reduce the traffic your server receives from addresses WP Cerber has already decided to block.

The add-on works with Cloudflare IP Access Rules, not Cloudflare Custom Rules.

Important: We recommend limiting the add-on to the Cloudflare zone of your website by entering its Zone ID in the add-on settings. Without a Zone ID, the add-on creates user-level Cloudflare IP Access Rules, and each rule applies to all Cloudflare zones owned by the Cloudflare user the configured credentials belong to, not just to the WordPress website where the add-on is installed. See Choose where the rules apply.

Requirements

Before installing the add-on, make sure your website meets the following requirements:

  • WP Cerber 9.8.3 or newer
  • PHP 7.4 or newer
  • A free or paid Cloudflare account
  • The website hostname is proxied through Cloudflare, not set to DNS only
  • WP Cerber’s Load security engine setting is set to Standard mode
  • WP Cerber’s My site is behind a reverse proxy setting is enabled when the website is served through the Cloudflare proxy

Cloudflare IP Access Rules can act on requests before they reach the origin server only if Cloudflare actually proxies the website’s HTTP and HTTPS traffic. A DNS-only record does not send web traffic through Cloudflare.

On the WordPress side, the reverse proxy setting is just as important. WP Cerber can make reliable IP-based security decisions only if it correctly detects the original visitor IP address. Enable My site is behind a reverse proxy only when the website really is behind Cloudflare or another trusted reverse proxy.

Cloudflare and HTTPS

When your website is proxied through Cloudflare, Cloudflare sits between visitors and your origin server and terminates visitor TLS connections at its edge, which means your website traffic is processed by Cloudflare infrastructure.

The connection between Cloudflare and your origin server can still be encrypted. Cloudflare supports encrypted origin connections and recommends Full (strict) mode when possible.

If your website has privacy, data-processing, or TLS requirements, review the corresponding Cloudflare configuration before enabling the add-on.

Proxy server for outgoing connections

The add-on sends its Cloudflare API requests through a proxy server when two conditions are met: WP Cerber’s Use WordPress proxy settings option is enabled, and both the WP_PROXY_HOST and the WP_PROXY_PORT constants are defined in wp-config.php. This is the proxy WP Cerber uses for its own outgoing connections. If the option is disabled or either constant is missing, the add-on connects to Cloudflare directly.

Versions of the add-on older than 3.0 ignored the option and always connected directly. The announcement of version 3.0 describes this change along with the others in that release. If both conditions are met on your website, make sure the proxy server allows connections to api.cloudflare.com before you update. Otherwise, the Cloudflare requests fail after the update and synchronization stops, while WP Cerber keeps enforcing its lockouts and IP Access Lists on the WordPress server.

Install the add-on

The Cloudflare add-on is a standard WordPress plugin. It is distributed through the WP Cerber website, not the wordpress.org plugin repository.

  1. Download the add-on: https://downloads.wpcerber.com/plugin/wp-cerber-cloudflare-addon.zip
  2. Log in to your WordPress admin dashboard.
  3. Go to Plugins → Add New Plugin.
  4. Click Upload Plugin.
  5. Select the downloaded ZIP archive.
  6. Click Install Now.
  7. Click Activate Plugin.

After activation, open WP Cerber → Add-ons → Cloudflare. All synchronization options are disabled by default.

Choose where the rules apply

Cloudflare keeps an IP Access Rule either for one zone, which is one domain in your Cloudflare account, or for a Cloudflare user as a whole. The Zone ID field of the add-on settings decides which of the two the add-on uses.

Zone ID entered, recommended Zone ID empty
A rule applies to The zone of this website only Every zone owned by the Cloudflare user
A lockout on this website Blocks the address on this website Blocks the address on all websites of that user
An Allowed IP Access List entry Is allowed on this website Is allowed on all websites of that user, where it can bypass several Cloudflare security controls
API Token permission Zone, Firewall Services, Edit for the zone Account, Account Firewall Access Rules, Edit

We recommend entering the Zone ID. The rules then affect the website you are configuring and nothing else, so you never have to work out which of your other websites a rule reaches.

Leave the Zone ID empty in two cases:

  • You run several websites under one Cloudflare user and want a lockout on one of them to protect the others.
  • The website is a WordPress multisite network whose sites use domains of their own. Such a network spans several zones, and one Zone ID cannot cover them.

On a new installation, enter the Zone ID together with the credentials, before you enable any synchronization option. The add-on has no rules yet, so there is nothing to move.

On an existing installation, updating the add-on changes nothing. The add-on keeps creating user-level rules until you enter a Zone ID. Entering it later is a separate step: the add-on then deletes its user-level rules and creates them again in the zone, and until that has completed the website has no Cloudflare rules from the add-on. Update first, confirm that synchronization works, and move the rules to the zone afterwards, at a time of your choosing. Configuring Cloudflare zones describes how to find the Zone ID and what the move involves.

Configure Cloudflare credentials

The add-on authenticates to Cloudflare in one of two ways. The recommended method is a Cloudflare API Token limited to the IP Access Rules the add-on manages. The legacy method, the account email address combined with the Global API Key, remains supported so that existing installations keep working.

If both are configured, the add-on uses the API Token only. The Global API Key is used only while the API Token field is empty. If Cloudflare rejects a configured token, the add-on reports the failure and does not fall back to the Global API Key.

When you save the add-on settings, WP Cerber verifies the credentials the add-on is going to use by creating and deleting a temporary Cloudflare IP Access Rule. If Cloudflare rejects the request, the add-on reports the failure in the WordPress admin area and names the credential it has checked.

If the add-on settings page has no Cloudflare API Token section, your version of the add-on supports the Global API Key only. Update the add-on before following the steps below.

Create a least-privilege API Token

Unlike the Global API Key, which grants full access to your Cloudflare account, an API Token carries only the permissions you give it. The steps below create a token for the recommended setup, with the rules limited to the zone of your website. Such a token reaches the firewall settings of that one zone and nothing in your other zones.

  1. Log in to the Cloudflare dashboard as the user who owns the websites the add-on protects.
  2. Go to My Profile → API Tokens and click Create Token.
  3. Next to Create Custom Token, click Get started.
  4. Give the token a descriptive name, for example WP Cerber IP Access Rules.
  5. Under Permissions, add a single permission: Zone, Firewall Services, Edit.
  6. Under Zone Resources, include the specific zone of your website.
  7. Optionally, under Client IP Address Filtering, allow only the public IP address your WordPress server uses for outgoing connections. If that address changes, Cloudflare starts rejecting the token.
  8. Leave TTL empty unless you plan to replace the token before it expires. Once the token expires, synchronization stops until you enter a new one.
  9. Click Continue to summary, then Create Token, and copy the token. Cloudflare shows it only once.

Then open WP Cerber → Add-ons → Cloudflare. Enter the Zone ID of your website in the Zone ID field of the Cloudflare Zone section, paste the token into the API Token field of the Cloudflare API Token section, and save the settings. Enter both before you save: a token for a zone is rejected while the Zone ID is empty, because the add-on then checks it at user level. Token authentication does not need the account email address.

If you leave the Zone ID empty to create user-level rules, the token needs a different permission. In step 5, add Account, Account Firewall Access Rules, Edit, and in step 6, include the account that owns the websites under Account Resources.

A token created on the Account API Tokens page of your Cloudflare account works as well, provided it has the same permission. Such a token belongs to the account rather than to a user. With the rules limited to a zone, the owner of the token makes no difference. For user-level rules, which always belong to a Cloudflare user, prefer a token from your profile.

Treat the token as a sensitive credential. Like the Global API Key, it is stored in the WordPress database without encryption, and anyone who obtains it can use every permission it carries. Its narrow scope limits the damage a leaked token can do, which is the reason to prefer it.

Depending on your WP Cerber version, the add-on settings page may display the saved token, and a WP Cerber settings export may include it, as it includes the Global API Key. Keep exported settings files as confidential as the token itself.

Switch an existing installation to an API Token

Updating the add-on changes nothing on its own. An installation configured with the Global API Key keeps using it until you enter an API Token.

Switching the credential does not touch the existing rules. The add-on keeps every rule it has created and continues to manage them with the token. Nothing is deleted or created again, and the switch takes effect with the next request. The same holds for a return from the token to the Global API Key. Only a change of the Zone ID rebuilds the rule set.

An existing installation creates user-level rules, so the token that replaces the Global API Key needs the permission for user level: Account, Account Firewall Access Rules, Edit. Switch to the token first and keep the Zone ID empty. Moving the rules to a zone is a separate step, described in Choose where the rules apply, and it is easier to follow once the token is known to work.

Create the token as the same Cloudflare user the Global API Key belongs to. The rules the add-on has already created belong to that user, and a token created by another user cannot manage them.

This is easy to get wrong if you have more than one Cloudflare login. A token of another user passes the credential check, because that user can manage rules of their own, and nothing on the settings page points to the mismatch. The add-on then no longer reaches the rules it created earlier. They stay in Cloudflare under the first user until you delete them in the Cloudflare dashboard. If the IP Access Rules you see in Cloudflare do not include the ones the add-on reports in its log, compare the user the token belongs to with the user of the Global API Key.

Once the credential check succeeds with the token, clear the Email Address and Global API Key fields and save the settings again. The token takes precedence either way, but only clearing the fields removes the Global API Key from the WordPress database. If older database backups contain the key, consider changing it in the Cloudflare dashboard as well. Keep in mind that changing the Global API Key breaks every other integration that still uses it.

Global API Key (legacy)

The Global API Key section of the add-on settings is labeled as legacy and not recommended. The Global API Key grants full access to your Cloudflare account, so anyone who obtains it from the WordPress database or a backup can do far more than manage IP Access Rules. Use it only if you cannot use an API Token.

To use it, leave the API Token field empty and enter the email address of your Cloudflare account together with its Global API Key. You can find the Global API Key in the Cloudflare dashboard under My Profile → API Tokens, in the API Keys section.

Syncing WP Cerber lockouts

Without the add-on, WP Cerber enforces its lockouts on the WordPress server. Enable Sync locked out IP addresses to have supported lockouts enforced at Cloudflare as well.

When WP Cerber locks out an address and the lockout qualifies for synchronization, the add-on creates a Cloudflare Block rule, so further requests from that address can be stopped at Cloudflare before they reach your WordPress server. When WP Cerber lifts the lockout, the add-on removes the corresponding rule.

Some lockouts are not synchronized

By design, the add-on does not mirror every WP Cerber lockout as it occurs. No Cloudflare rule is created when:

  • the request belongs to a logged-in user
  • the lockout is triggered by certain erroneous requests, such as repeated 404 requests
  • the login attempt limit is reached for the first time, in cases where WP Cerber treats the first lockout differently
  • the request is identified as Googlebot from the googlebot.com domain
  • Cloudflare cannot represent the locked-out address or network as an IP Access Rule target

These exclusions apply only to the Cloudflare copy of the lockout. The lockout itself remains active in WP Cerber.

Subnet lockouts

Version 2.5 supports subnet lockouts. If Block subnet – Always block entire subnet Class C of intruders IP is enabled in WP Cerber, the add-on creates the rule for the subnet WP Cerber has locked out rather than only for the individual address that triggered the lockout. With the current WP Cerber subnet mode, this normally results in a /24 Cloudflare rule.

The rule is created only if Cloudflare supports that network size. If it does not, the lockout remains active in WP Cerber without a Cloudflare counterpart.

Earlier versions of the add-on did not synchronize subnet lockouts and required the Block subnet option to be disabled. Version 2.5 removes that restriction.

Syncing IP Access Lists

Turn on Enable IP Access List syncing to synchronize supported changes in the WP Cerber Allowed and Blocked IP Access Lists with Cloudflare IP Access Rules.

Synchronization runs in one direction only: WP Cerber → Cloudflare. Changes you make directly to IP Access Rules in the Cloudflare dashboard are not sent back to WP Cerber.

Blocked IP Access List

A supported entry added to the WP Cerber Blocked IP Access List becomes a Cloudflare Block rule. For example, if you add 192.168.1.0/24 to the list, the add-on can create a matching Cloudflare rule that blocks requests from that network before they reach your WordPress server.

Allowed IP Access List

A supported entry added to the WP Cerber Allowed IP Access List becomes a Cloudflare Allow rule, so use this list with care. Cloudflare documents that an IP Access Rule with the Allow action can bypass other Cloudflare security checks for that address, including Custom Rules, Rate Limiting Rules, WAF Managed Rules, and some other security features.

For that reason, add an address to the Allowed IP Access List only if you trust it and understand the effect of a Cloudflare Allow rule.

Supported IP addresses and networks

WP Cerber accepts more IP address and network formats than Cloudflare IP Access Rules do.

If an entry is valid in WP Cerber but Cloudflare cannot represent it, the add-on does not create a Cloudflare rule for it. The entry stays in your IP Access List exactly as it is, and nothing is rewritten or removed to make it fit Cloudflare.

Entry in a WP Cerber IP Access List Synced to Cloudflare
A single IPv4 address, for example 192.168.1.1 Yes
A single IPv6 address, for example 2001:db8::1 Yes
An IPv4 network with prefix length /16 or /24, for example 192.168.1.0/24 Yes
An IPv6 network with prefix length /32, /48, or /64, for example 2001:db8::/48 Yes
An IPv4 network with another prefix length, for example 10.0.0.0/8 No
A range written as a first and last IP address No

WP Cerber wildcard notation is converted to CIDR notation automatically when Cloudflare supports the resulting network:

  • 192.168.1.* becomes 192.168.1.0/24
  • 192.168.*.* becomes 192.168.0.0/16

Enabling IP Access List synchronization on an existing website

Turning on IP Access List synchronization does not trigger a bulk sync of entries already in the Access Lists. Only additions and removals made after you enable it are synchronized, as they occur.

To mirror an existing entry right away, remove it from the WP Cerber IP Access List and add it again. Be careful with entries that affect your own access to the website.

Saving a Zone ID for the first time, or changing it, is an exception. With the next event the add-on creates Cloudflare rules in the new zone for every supported entry of the Access Lists and for every active lockout, as far as the corresponding synchronization option is enabled at that moment. Review the Allowed IP Access List before you do so, because each of its entries becomes a Cloudflare Allow rule.

The one-time rebuild that runs when you update from an add-on version earlier than 2.5 works differently. It reads the current Access Lists and can recreate Cloudflare rules for entries that already exist at the time of the update.

Other add-on settings

Verbose rule notes

Enable Verbose rule notes to include additional WP Cerber information in Cloudflare rule notes. For IP Access List rules, the add-on can add the entry comment. For lockout rules, it can add the lockout reason.

Verbose notes can make Cloudflare rules easier to identify and search, but the information they contain is then stored by Cloudflare. Leave this option disabled if your Access List comments or lockout reasons contain anything you do not want stored there.

Delete Cloudflare rules on deactivation

When Delete Cloudflare rules on deactivation is enabled, deactivating the Cloudflare add-on removes the Cloudflare rules recorded by the add-on. The same cleanup also runs when WP Cerber itself is deactivated.

If a Cloudflare deletion fails, it is not retried during that deactivation. The add-on then no longer tracks that rule, so remove it manually in Cloudflare. After using deactivation to clear the rule set, check the IP Access Rules in your Cloudflare account to confirm that the expected rules are gone.

Reactivating the plugins does not automatically recreate the rules removed during deactivation. From that point on, synchronization is event-driven.

An installation whose rules are limited to a Cloudflare zone is the exception. After reactivation, the next event creates the whole rule set again in that zone, based on the lockouts and IP Access List entries WP Cerber holds at that moment.

Enable diagnostic logging

Turn on Enable diagnostic logging before investigating a synchronization problem. While this option is enabled, the add-on records synchronization activity and Cloudflare failures in the WP Cerber Diagnostic Log, which you can open from WP Cerber → Tools → Diagnostic Log. When the option is disabled, the add-on writes nothing to that log. The add-on never writes the API Token or the Global API Key to the log.

Troubleshooting

Cloudflare credentials are rejected

The failure notice names the credential that has been checked: the API Token whenever one is entered, and the Global API Key otherwise.

If the API Token is rejected, check that:

  • you copied the token itself, not its ID or the Global API Key
  • the token has the permission for where the rules apply: Firewall Services with Edit access for the zone whose Zone ID you entered, or Account Firewall Access Rules with Edit access if the Zone ID is empty
  • the Zone ID field holds the Zone ID of the zone the token was created for
  • the token is active and has not expired
  • the client IP address filter of the token, if you set one, includes the public IP address of your server
  • the token was created by the Cloudflare user whose zones you intend the add-on to affect

If the Global API Key is rejected, check that:

  • you entered the Cloudflare account email address
  • you entered the Global API Key, not an API Token
  • the credentials belong to the Cloudflare user whose zones you intend the add-on to affect

Then save the settings again to rerun the credential check.

A WP Cerber entry does not appear in Cloudflare

Work through the following steps:

  1. Make sure the relevant synchronization option is enabled.
  2. Confirm that Cloudflare supports the address or network format.
  3. If the entry was added before you enabled synchronization, remember that existing entries are not synchronized in bulk.
  4. Look for a Cloudflare error in the WordPress admin notices.
  5. Enable diagnostic logging and review WP Cerber → Tools → Diagnostic Log.

Cloudflare limits the request rate

Cloudflare limits the number of API requests it accepts within a few minutes. Once the limit is reached, it rejects further requests for a short time, and the add-on reports “Please wait and consider throttling your request speed (code 971)”.

This is most likely while the add-on creates or deletes many rules in a row, as it does during a rebuild of the rule set or a move to another zone. The add-on then suspends the work and continues with a later event, so no action is needed. A single rule that could not be created for this reason is reported like any other failed request.

The limit applies to the Cloudflare user or token as a whole. Other tools and websites that use the same credentials count toward it.

Nothing happens after updating from an older version

The one-time rebuild starts with the next relevant WP Cerber IP event, not necessarily at the moment you update the plugin. Also confirm that working Cloudflare credentials are saved: either an API Token, or the Cloudflare email address together with the Global API Key.

To trigger a relevant event yourself, add an IP Access List entry and then remove it. Choose an address that will not affect your own access to WordPress or to other Cloudflare zones.

The Cloudflare rule set looks incomplete after an update

A large rebuild can span multiple requests, and while it is in progress, Cloudflare rule IDs and the number of visible rules may change.

Enable diagnostic logging and check the Diagnostic Log for rejected Cloudflare operations or unsupported targets.

Recovering from an accidental block

A Cloudflare Block rule can prevent your current IP address from reaching WordPress at all. If you accidentally block yourself, you have two practical ways to recover.

Use another Internet connection

Switch to a device or connection with a different public IP address, such as a mobile device on cellular data instead of your Wi-Fi network. Then log in to WordPress and remove the lockout or IP Access List entry that caused the block.

This is the preferred option when you need to restore normal WordPress access immediately.

Remove the Cloudflare rule manually

Log in to Cloudflare, open Security → Security rules → IP Access rules, find the rule for your IP address, and remove it. To find out your current public IP address, use What is my IP address.

Removing the Cloudflare rule lets your requests reach the WordPress server again, but it does not remove the corresponding WP Cerber lockout or IP Access List entry. WP Cerber continues to enforce its own state until that state expires or you change it in WordPress.

The add-on does not detect a rule you remove manually and continues to treat it as existing until the corresponding lockout is lifted or the IP Access List entry is removed in WordPress. At that point, the add-on clears its record of the rule, and if the same address is added again later, a new Cloudflare rule is created as usual.

Delete all Cloudflare rules created by the add-on

To remove the rules currently recorded by the add-on:

  1. Open WP Cerber → Add-ons → Cloudflare.
  2. Enable Delete Cloudflare rules on deactivation.
  3. Save the settings.
  4. Go to the WordPress Plugins page.
  5. Deactivate the Cloudflare for WP Cerber Security plugin.
  6. Check your Cloudflare IP Access Rules to confirm that the expected rules were removed.
  7. Reactivate the add-on only if you still want to use it.

Keep in mind that individual Cloudflare deletions can fail, so deactivation does not guarantee that every remote rule is removed.

Support

If you run into a synchronization problem, turn on Enable diagnostic logging, reproduce the issue, and then check WP Cerber → Tools → Diagnostic Log.

WP Cerber Professional customers can use the support helpdesk at https://my.wpcerber.com. Support for the free version is available through the WP Cerber community at https://talk.wpcerber.com.

Cloudflare references

The Cloudflare documentation covers the following topics in more detail:

Have any questions?

If you have a question regarding WordPress security or WP Cerber, ask it in the comments below or find answers on the community forum.

Spotted a bug or glitch?

We’d love to fix it! Share your bug discoveries with us here: Bug Report.


I'm a software engineer and team lead at Cerber Tech. I started coding in 1993 on IBM System/370 and today software engineering at Cerber Tech is how I make my living.

View Comments
There are currently no comments.