Skip to main content

Cloudflare Security Rules

Cloudflare's Web Application Firewall (WAF) helps protect your website from malicious traffic, brute-force attacks, bots, and other security threats. This guide explains how to create common security rules for WordPress websites.

Prerequisites​

Before creating any rules:

  1. Log in to your Cloudflare dashboard.
  2. Select your website.
  3. Navigate to Security > Security rules.
  4. Click Create rule.

Navigate to Security > Security rules in the Cloudflare dashboard


Configure a Rate Limiting Rule (Free Plan)​

Rate limiting helps protect your website from brute-force attacks and excessive requests.

Step 1. Navigate to Rate Limiting Rules

  1. Open your Cloudflare dashboard.
  2. Select your domain.
  3. Go to Security > Security rules.
  4. Click Create rule.
  5. Click Rate limiting rules.

Create a rate limiting rule in the Cloudflare dashboard

Step 2. Configure Rate Limit Settings

Set the rule name and the matching expression (for example, URI Path equals /wp-login.php), then configure the following settings:

SettingValue
Requests5
Period10 seconds (free plan)
ActionBlock (free plan)
Duration10 seconds (free plan)
StatusActive

Rate limiting rule options

Rate limiting rule action

Rate limiting request threshold

Rate limiting duration

Step 3. Deploy the Rule

  1. Review the configuration.
  2. Click Deploy.
  3. Verify that the rule appears in the rate limiting rules list.

Combine Core WordPress Path Protections​

Challenge access to /xmlrpc.php, /wp-login.php, and /wp-comments-post.php to reduce brute-force attacks, DDoS abuse, and automated comment spam. Make sure your website does not require these endpoints for automated clients (for example, Jetpack or the WordPress mobile app use /xmlrpc.php) before enabling the rule.

Step 1. Create a Custom Rule

  1. Open Security > Security rules.
  2. Click Create rule.
  3. Click Custom rules.

Step 2. Configure the Rule

FieldOperatorValue
Rule nameProtect WP Endpoints
URI Pathcontains/xmlrpc.php or /wp-login.php or /wp-comments-post.php
ActionManaged Challenge
StatusActive

Protect WP endpoints rule: rule name Protect WP endpoints rule: rule options Protect WP endpoints rule: action

Step 3. Deploy the Rule

  1. Click Deploy.

  2. Test access to the following URLs:

    https://yourdomain.com/xmlrpc.php
    https://yourdomain.com/wp-login.php
    https://yourdomain.com/wp-comments-post.php

    Cloudflare should present a challenge for each request.


Block Generic Script User-Agents​

This rule blocks incoming HTTP requests when the User-Agent header contains python, curl, wget, or go-http-client (in any letter case), or when the User-Agent header is empty. This rule does not identify all bots or automated traffic, and clients can bypass User-Agent matching by changing or spoofing their header.

Note: Some legitimate services (such as uptime monitors, payment webhooks, and API integrations) may use these User-Agents. Review your integrations before enabling this rule.

Step 1. Create a Custom Rule

  1. Navigate to Security > Security rules.
  2. Click Create rule.
  3. Click Custom rules.

Step 2. Configure the Rule

FieldOperatorValue
Rule nameBlock Automated HTTP Clients
User Agentcontainspython or curl or wget or go-http-client
User Agentequals(empty) or use the condition below
ActionBlock
StatusActive

The contains operator is case-sensitive. To match regardless of letter case, use Edit expression and enter:

(http.user_agent contains "python") or
(http.user_agent contains "curl") or
(http.user_agent contains "wget") or
(http.user_agent contains "go-http-client") or
(http.user_agent eq "")

Block User-Agent rule: rule name Block User-Agent rule: options Block User-Agent rule: action

Step 3. Deploy the Rule

  1. Review the rule expression and action.
  2. Click Deploy to activate the rule.
  3. Monitor the Security Events dashboard to verify that requests are being blocked as expected.

Challenge Non-Target Country Traffic​

This rule challenges requests from countries outside your target markets using Cloudflare Managed Challenge. It reduces unwanted traffic while allowing legitimate visitors to access your website. Make sure required users and business regions are not challenged by mistake.

Step 1. Create a Custom Rule

  1. Navigate to Security > Security rules.
  2. Click Create rule.
  3. Click Custom rules.

Step 2. Configure the Rule

FieldOperatorValue
Rule nameGeo-Challenge Unintended Traffic
Countryis not inYour target countries (for example, India, US )
ActionManaged Challenge
StatusActive

Use does not equal if you have a single target country, or is not in if you have several.

Non-target country rule: rule name Non-target country rule: options Non-target country rule: action

Step 3. Deploy the Rule

  1. Review the rule expression and action.
  2. Click Deploy to activate the rule.

Enable Bot Fight Mode​

Bot Fight Mode helps detect and mitigate automated bot traffic, reducing unwanted requests and protecting your website from malicious bots.

Step 1. Navigate to Security > Settings.

Step 2. Scroll to Bot traffic.

Bot traffic settings

Step 3. Enable Bot fight mode.

Enable Bot fight mode


Enable Browser Integrity Check​

Enable Cloudflare Browser Integrity Check to detect and challenge requests from suspicious browsers, bots, and automated clients using HTTP headers and browser signals, helping reduce malicious traffic to your website.

Step 1. Navigate to Security > Settings.

Step 2. Scroll to DDoS Attacks.

Browser Integrity Check Setting

Step 3. Enable Browser Integrity Check.

Enable Browser Integrity Check


Best Practices​

  • Use Managed Challenge instead of Block whenever possible.
  • Monitor Cloudflare Security Events after deploying new rules.
  • Test each rule before applying it to a production environment.
  • Review security logs regularly for false positives.
  • Combine security rules with rate limiting for stronger protection.

Troubleshooting​

Allow Let's Encrypt Validation (Skip Rule)​

If your origin server issues SSL certificates through Let's Encrypt (for example, with Certbot or a hosting control panel), the validation servers must reach /.well-known/acme-challenge/ over plain HTTP. Rules such as Managed Challenge, Geo-Challenge, and rate limiting can block these requests and cause certificate issuance or renewal to fail. This rule skips those protections for the ACME challenge path only.

Important: Custom rules run in order, from top to bottom. Place this rule above all other custom rules. Otherwise, those rules may act on the validation request first.

Step 1. Create a Custom Rule

  1. Navigate to Security > Security rules.
  2. Click Create rule.
  3. Click Custom rules.

Step 2. Configure the Rule

FieldOperatorValue
Rule nameLetsencrypt Skip
URIstarts with/.well-known/acme-challenge/
ActionSkip

The Expression Preview should show:

(starts_with(http.request.uri, "/.well-known/acme-challenge/"))

Let's Encrypt skip rule: rule name and expression

Step 3. Configure the Skip Action

Under Then take action..., set Choose action to Skip, then configure the following:

SettingValue
Log matching requestsEnabled
All remaining custom rulesChecked
All remaining custom rules in this phaseUnchecked
All rate limiting rulesChecked
All managed rulesChecked
All Super Bot Fight Mode RulesChecked

Click More components to skip if you also want to skip additional components, such as Browser Integrity Check, for this path.

Note: Skip rules cannot skip IP Access Rules. Some components, such as Bot Fight Mode on the Free plan, may not be skippable. If validation still fails, review Security > Events to see which feature is blocking the request.

Step 4. Deploy the Rule

  1. Review the rule expression and action.
  2. Click Deploy.
  3. In the rules list, drag the rule to the top so it is evaluated first.

SSL Certificate Issuance or Renewal Fails​

  1. Confirm the Letsencrypt Skip rule is active and placed above all other custom rules.
  2. Open Security > Events and look for blocked or challenged requests to /.well-known/acme-challenge/.
  3. Check whether the geo-challenge, rate limiting, or Bot Fight Mode is acting on those requests.
  4. Retry certificate issuance after correcting the rule order or skip components.

Legitimate Users Are Being Blocked​

  1. Open Security > Events.
  2. Locate the blocked requests.
  3. Review the triggering rule.
  4. Modify the rule or add an exception if necessary.

Login Page Is Inaccessible​

  1. Verify the rule expression.
  2. Check the rule action.
  3. Temporarily disable the rule for testing.
  4. Confirm there are no conflicting Cloudflare rules.