Member-only story
Implementing a IP blocklist Worker
If your application is remotely hosted and your provider does not allow you administrative or firewall privileges it is possible to block specific IPs using a CloudFlare worker.
Note
This article is a proof of concept. If you want to create a proper domain-wide firewall, I suggest reading the article below which builds on the tools used here.
Setting up the IP address API / Store
Storing the IP addresses.
We start by creating a key-value list that the worker can easily access. On our dashboard go to “Storage and Databases” then select “Workers KV”.
We then select new, and name it IP_BLOCKLIST . This is our key value store.
Once created copy the namespace code from the url:
https://dash.cloudflare.com/.../workers/kv/namespaces/<copy this alphanumeric string>



