Docs

Block at the edge with Cloudflare

4 min readUpdated November 19, 2026

If your site runs through Cloudflare, Shield can ask Cloudflare to block an attacker as soon as Shield catches them. The attacker’s later requests are stopped at Cloudflare and never reach your server.

This is the Cloudflare version of the previous topic, “Block at the edge with Bunny.net”. You can set up one, both, or neither.

A side-by-side comparison of settings for Bunny.net WAF and Cloudflare. Both panels feature identical input fields for API keys, block duration, and checkboxes for Honeypot username and Brute-force lockout triggers, with dedicated “Save” buttons at the bottom of each section.

What it does#

When a trigger fires, Shield adds an IP block rule to your Cloudflare zone. It uses Cloudflare’s IP Access Rules (found in Cloudflare under Security → WAF → Tools → IP Access Rules). These rules are separate from your custom WAF rules, so they don’t use up any of your custom rule slots.

Cloudflare doesn’t expire these rules itself, so Shield does it: it schedules a WordPress background task that deletes the rule when your chosen block time is up.

Choose which events trigger a block:

  • Honeypot username: someone tried to log in with a username on your trap list. (On by default.)
  • Brute-force lockout: an IP went over the failed-attempt limit. (On by default in a fresh install.)

Shield still locks the IP out locally as usual. The Cloudflare block is added on top. The push is sent in the background, usually within a minute of the lockout.

Before you start#

You need:

  • A site whose domain is on Cloudflare (a zone).
  • A Cloudflare API token you create for Shield. Don’t use your Global API Key.

Create the API token

  1. In Cloudflare, go to your profile and open API Tokens (the tab has a link).
  2. Create a token with the permission Zone / Firewall Services / Edit.
  3. Limit the token to your site’s zone if you can.
  4. Copy the token. Cloudflare only shows it once.

Set it up#

  1. Go to Settings → Nahnu Login Shield and open the Edge Blocking tab. Stay on the IP Blocking sub-tab.
  2. In the Cloudflare card, turn on Enable Cloudflare blocking.
  3. Paste your API token and click Save Cloudflare settings. Saving loads your zones.
  4. Under Zone, search for your domain and click it. The page shows the zone ID underneath.
  5. Set the Block duration, from 1 to 8760 hours. The default is 24 hours.
  6. Under Trigger on, tick Honeypot username, Brute-force lockout, or both.
  7. Click Save Cloudflare settings.
  8. Click Test connection. A success message means Shield can reach your zone. An error tells you if the token lacks permission or the zone ID wasn’t found.

The card’s badge shows where you stand: Not configured, Key saved, choose a zone, Configured, not enabled, or Active.

Keep the token out of the database#

By default, the token is saved in your site’s settings. The tab recommends putting it in wp-config.php instead:

define( 'NAHNLS_CF_API_TOKEN', 'your-token-here' );
define( 'NAHNLS_CF_ZONE_ID', 'your-zone-id' );

When these are set, the tab shows “Set in wp-config.php” in place of the fields. Choose this option if you can: a token stored only in a config file isn’t exposed by a database leak or a settings export.

Make sure Cloudflare sees the same IP as Shield#

Behind Cloudflare, every request reaches your server from a Cloudflare IP. Shield needs the visitor’s real IP, or it would ask Cloudflare to block the wrong address. Turn on Trust proxy headers on the Lockout tab. See “Lockouts are keyed to the wrong IP (proxies and CDNs)” in the Troubleshooting section.

See and remove blocks#

Under the provider cards, a Currently blocked IPs table lists every IP Shield has blocked at the edge. It shows the IP, the provider, the reason, when it was blocked and when it expires. Each row has an unblock button. For Cloudflare, clicking it deletes the rule in Cloudflare straight away. See “The edge block log”.

If a visitor, or you, get blocked by mistake:

  1. Unlock the IP on the Lockout tab (see “Unlock an IP”). This clears the lockout and lifts the Cloudflare block in the background.
  2. If you only click Unblock in the Currently blocked IPs table, the Cloudflare rule is deleted but the local lockout stays, so unlock the IP too.
  3. If the rule still shows in Cloudflare, delete it under Security → WAF → Tools → IP Access Rules.

To avoid blocking yourself, keep your own IP in the Whitelisted IPs list (Lockout tab). Whitelisted IPs are never locked out, so they are never sent to Cloudflare.

What gets logged#

Each push appears in the Currently blocked IPs table. If Cloudflare rejects a request, the error goes to your server’s PHP error log with the prefix [NAHNLS].

Good to know#

  • One IP per rule. Each lockout is one IP Access Rule, sent as its own request. To block a whole network (AS number), see “Cloudflare WAF”.
  • Expiry depends on WP-Cron. Shield deletes the rule when the time is up using a background WordPress task. If WP-Cron is switched off on your site without a real cron job in its place, rules may stay in Cloudflare longer than intended. Delete leftovers by hand in Cloudflare.
  • Reaching Cloudflare. Your server must be able to make outgoing requests to api.cloudflare.com.
  • Free plans. IP Access Rules are part of Cloudflare’s free tools, but limits and features can change. Check your plan with Cloudflare.
  • Requests that never reach WordPress can’t be logged by Shield. Cloudflare’s own security events will show them.

Was this helpful?

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only