Skip to content

This repository provides a complete Cloudflare WAF setup guide, including custom rules for bot protection, country blocking, and CAPTCHA verification. Learn how to configure firewall settings step by step to secure your website against threats.

License

Notifications You must be signed in to change notification settings

kamrullab/cloudflare-security-rules

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”₯ Cloudflare Web Application Firewall (WAF) and Security Setup

🌍 Overview

This repository provides a complete step-by-step guide to setting up and configuring Cloudflare Web Application Firewall (WAF). It helps protect websites against malicious attacks, bot traffic, and unauthorized access. This guide includes the process of creating custom rules, understanding firewall settings, and applying CAPTCHA verification to enhance security and performance.


πŸ“Œ How to Create Cloudflare WAF Rules (Step-by-Step Guide)

πŸš€ Step 1: Accessing Cloudflare Security Settings

  1. πŸ”‘ Login to Cloudflare: Go to Cloudflare Dashboard and log in.
  2. 🌐 Select Your Website: Click on the website you want to protect.
  3. πŸ›‘οΈ Navigate to WAF: In the left sidebar, go to Security > WAF (Web Application Firewall).
  4. βš™οΈ Go to Custom Rules: Click on the Custom Rules tab.

πŸ—οΈ Step 2: Creating a New Custom Rule

  1. Click on βž• Create Rule.
  2. Enter a πŸ“ Rule Name (e.g., CAPTCHA SKIP for bots).
  3. Choose a πŸ“Œ Field (e.g., User Agent to detect bots).
  4. Select an βš™οΈ Operator (e.g., contains to match specific bots).
  5. Enter a πŸ“₯ Value (e.g., Googlebot for Google Search bot).
  6. Choose an πŸ”’ Action (e.g., Skip for trusted bots, Block for countries, or Managed Challenge for CAPTCHA).
  7. Set the πŸ”„ Placement Order (first, after another rule, etc.).
  8. Click πŸ’Ύ Save and ensure the rule is βœ… Enabled.

🎯 Custom Rules Configuration (Basic to Advanced)

Below are three essential WAF rules, explained in three formats: Table Format, Copyable Code Format, and Detailed Explanation.


1️⃣ CAPTCHA SKIP Rule (Allowing Search Engine Bots) πŸ€–

βœ… πŸ“‹ Table Format

πŸ“Œ Field βš™οΈ Operator πŸ“₯ Value
User Agent contains facebookexternalhit
OR contains TwitterBot
OR contains LinkedInBot
OR contains Googlebot
OR contains Bingbot
πŸ”’ Action Skip
πŸ”„ Placement First

βœ… πŸ“œ Copyable Code Format

Rule Name: CAPTCHA SKIP
Field: User Agent
Operator: contains
Value: facebookexternalhit

OR

Field: User Agent
Operator: contains
Value: TwitterBot

OR

Field: User Agent
Operator: contains
Value: LinkedInBot

OR

Field: User Agent
Operator: contains
Value: Googlebot

OR

Field: User Agent
Operator: contains
Value: Bingbot

Action: Skip
Placement: First

βœ… πŸ“– Detailed Explanation

  • 🎯 Purpose: This rule allows legitimate search engine bots to access your website without being blocked by CAPTCHA.
  • πŸ“Œ Field: User Agent checks if the visitor is a bot.
  • βš™οΈ Operator: contains applies if the bot’s name appears.
  • πŸ“₯ Values: Recognized search bots like Googlebot, Bingbot, etc.
  • πŸ”’ Action: Skip allows these bots to bypass security checks.
  • πŸ”„ Placement: This rule should be first in order.

2️⃣ COUNTRY BLOCK Rule (Blocking Specific Countries) 🌍

βœ… πŸ“‹ Table Format

πŸ“Œ Field βš™οΈ Operator πŸ“₯ Value
Country equals United Kingdom
OR equals United States
πŸ”’ Action Block
πŸ”„ Placement After CAPTCHA SKIP

βœ… πŸ“œ Copyable Code Format

Rule Name: COUNTRY BLOCK
Field: Country
Operator: equals
Value: United Kingdom

OR

Field: Country
Operator: equals
Value: United States

Action: Block
Placement: After CAPTCHA SKIP

βœ… πŸ“– Detailed Explanation

  • 🎯 Purpose: Blocks traffic from selected countries to prevent fraud or unwanted access.
  • πŸ“Œ Field: Country checks the visitor’s location.
  • βš™οΈ Operator: equals applies only to the listed countries.
  • πŸ“₯ Values: United Kingdom, United States (can add more if needed).
  • πŸ”’ Action: Block denies access to these users.
  • πŸ”„ Placement: Should be after the CAPTCHA SKIP rule.

3️⃣ CAPTCHA ON Rule (Adding Verification for Suspicious Traffic) πŸ”

βœ… πŸ“‹ Table Format

πŸ“Œ Field βš™οΈ Operator πŸ“₯ Value
Hostname wildcard mail.kamrul.us
OR wildcard kamrul.us/SOFT
OR wildcard kamrul.us
πŸ”’ Action Managed Challenge
πŸ”„ Placement After COUNTRY BLOCK

βœ… πŸ“œ Copyable Code Format

Rule Name: CAPTCHA ON
Field: Hostname
Operator: wildcard
Value: mail.kamrul.us

OR

Field: Hostname
Operator: wildcard
Value: kamrul.us/SOFT

OR

Field: Hostname
Operator: wildcard
Value: kamrul.us

Action: Managed Challenge
Placement: After COUNTRY BLOCK

βœ… πŸ“– Detailed Explanation

  • 🎯 Purpose: Protects sensitive pages by forcing visitors to pass a CAPTCHA challenge.
  • πŸ“Œ Field: Hostname applies the rule to specific site sections.
  • βš™οΈ Operator: wildcard matches similar URLs.
  • πŸ”’ Action: Managed Challenge presents CAPTCHA verification.
  • πŸ”„ Placement: Runs after COUNTRY BLOCK rule.

πŸ” Final Verification & Troubleshooting

βœ… How to Check if Rules Are Working?

  1. πŸ› οΈ Test the site from different locations (use VPN for testing country blocks).
  2. πŸ” Use browser developer tools (F12 > Network > Inspect HTTP headers).
  3. πŸ“Š Check Cloudflare Security Logs (Security > WAF > Logs).

image

image

image

image

image

πŸ† License & Contact

This guide is open-source under the MIT License. For further support, contact kamrul.us Admin or visit Cloudflare Support.

image

About

This repository provides a complete Cloudflare WAF setup guide, including custom rules for bot protection, country blocking, and CAPTCHA verification. Learn how to configure firewall settings step by step to secure your website against threats.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published