Categories

Cloudflare Firewall Rule: Ban Country Codes from Registration

You are here:
< All Topics

Quickly add a Cloudflare Firewall Rule to block registration from specified countries.

Go to Cloudflare > Firewall > Firewall Rules > Create a firewall rule
Look for small text link as you scroll down to Edit expression

Paste the following rule, making sure to edit the registration URLs to be correct for your installation.

The action is Block.

Code:

(ip.geoip.country in {"AF" "AL" "DZ" "AO" "AM" "AZ" "BD" "BJ" "BY" "BA" "BN" "KH" "CM" "BI" "CF" "TD" "CN" "CG" "CD" "DJ" "GQ" "ER" "ET" "GA" "GM" "GH" "HT" "IN" "IR" "IQ" "KZ" "KE" "KP" "KG" "KR" "XK" "LA" "LV" "LY" "MG" "MW" "MD" "MN" "MZ" "NE" "NG" "PK" "RU" "RW" "RS" "SO" "SN" "SS" "SD" "LK" "SZ" "SY" "TJ" "TZ" "TL" "TM" "UZ" "VN" "T1"} and http.request.full_uri contains "/register") or (http.request.uri.path contains "?register")

Deploy

You can then go back to the rule and edit the countries if you want. Below are the countries included in the above code (including Tor).

xenforo.jpg

The above rule is good for blocking a large number of countries but leaving most of the world open. Conversely, If your forum is only open to one (or a few) countries, simply change the rule to: Country is not in [choose country (or countries) to allow from dropdown].

Also, you may choose to make the URI Path more restrictive, ie. /forums/register/

Table of Contents