A Python-based tool to manage Cloudflare WAF custom rules using the official cloudflare-python SDK. The tool allows or blocks requests based on the request URI path and source IP address.
- โ Create or update WAF custom rules
- โ
Match wildcard URI paths (e.g.,
/admin/*) - โ Allow access only to specific IPs or ranges
- โ Block all other requests
- โ Supports multiple rules via YAML config
- โ Dry-run mode for safe testing
- โ
Uses API token securely via
.envfile
git clone https://github.com/your-user/cloudflare-waf.git
cd cloudflare-waf
python3 -m venv venv
source venv/bin/activate
pip3 install -r requirements.txt
Create a .env file in the root of the project:
You can generate an API Token from your Cloudflare dashboard. Make sure it includes permission for Zone > Firewall Services > Edit.
If dry_run: true, the script will show what it would do.
Set dry_run: false to apply changes to Cloudflare.