Knowledgebase

How to protect your website with Cloudflare WAF rules and Under Attack mode

If your site is being flooded with bad traffic, login attempts or bots, Cloudflare can block most of it before it reaches your hosting. This guide shows how to protect your website with Cloudflare WAF rules and Under Attack mode on the free plan, with ready-to-use examples.

The site must already be active on Cloudflare with the proxy (orange cloud) on. If not, start with how to add your website to Cloudflare.

Quick protection: Under Attack mode

Under Attack mode shows every visitor a short browser check before they reach your site. It stops most automated attacks but slows down real visitors, so use it only during an attack.

  1. Open your domain in the Cloudflare dashboard.
  2. Find Under Attack mode. It appears in the domain overview (quick actions) and in the security settings.
  3. Turn it on. Watch your site and server load.
  4. Turn it off when the attack stops.
Note: Under Attack mode can block legitimate automated traffic such as payment gateway callbacks, mobile apps using your API, or uptime monitors. If something breaks, add a rule to skip the check for those paths or IPs, or turn the mode off.

Turn on Bot Fight Mode

In the security settings, look for Bot Fight Mode and turn it on. It challenges known bad bots. Test your site afterwards; if a service you rely on stops working, turn it off again.

Create WAF custom rules

  1. Go to Security > WAF (in newer dashboards, the security rules section) and open Custom rules.
  2. Click Create rule and give it a name.
  3. Build the condition with the fields, or click Edit expression and paste one of the examples below.
  4. Choose the action: Block, Managed Challenge (recommended for most cases) or Skip.
  5. Click Deploy.

The free plan includes a limited number of custom rules, so combine conditions in one rule where you can.

Example rules

1. Protect the WordPress login from outside Egypt. Visitors from other countries get a challenge on the login page:

(http.request.uri.path contains "/wp-login.php" and ip.src.country ne "EG")

Action: Managed Challenge. If your team travels or uses a VPN, they will just see a quick check.

2. Block access to xmlrpc.php (often abused for brute force, rarely needed):

(http.request.uri.path eq "/xmlrpc.php")

Action: Block. Skip this rule if you use the Jetpack plugin or the WordPress mobile app, which may need it.

3. Block a specific abusive IP or range:

(ip.src in {203.0.113.10 198.51.100.0/24})

Replace the example addresses with the ones you see in your logs.

Check what was blocked

Open Security > Events (also called the security analytics or events log). You will see each blocked or challenged request and the rule that caught it. If real customers are blocked, relax the rule.

Common problems

  • Payment callbacks fail: a rule or Under Attack mode is challenging the gateway. Add a rule with action Skip for the callback path.
  • Attack still hits the server: attackers may use your server IP directly. Make sure no DNS record exposes the IP without the proxy, and contact us so we restrict access at the server firewall.
  • Locked out of wp-admin: pause the rule from the custom rules list.

Frequently asked questions

Is the free plan enough to stop DDoS?

Cloudflare includes DDoS protection for proxied sites on all plans. Application-level floods may also need rules like the ones above.

Does this replace security on my hosting?

No. Keep WordPress and plugins updated and use strong passwords. See how to secure your WordPress website.

Will Managed Challenge annoy my visitors?

Most real visitors pass it without clicking anything. Apply it to sensitive paths, not the whole site.

Need help? Open a support ticket or message us on WhatsApp +20 127 113 3655.

  • cloudflare, waf, custom rules, under attack mode, ddos, bot fight mode, security

Was this answer helpful?

0 Users Found This Useful