Skip to content

feat: add IP blacklist support to Cloudflare Worker edge layer (Fixes #1045)#1154

Closed
zeroknowledge0x wants to merge 1 commit into
sublime247:mainfrom
zeroknowledge0x:feat/edge-ip-blacklist-1045
Closed

feat: add IP blacklist support to Cloudflare Worker edge layer (Fixes #1045)#1154
zeroknowledge0x wants to merge 1 commit into
sublime247:mainfrom
zeroknowledge0x:feat/edge-ip-blacklist-1045

Conversation

@zeroknowledge0x
Copy link
Copy Markdown

Fixes #1045

Summary

Adds edge-level IP blacklist support to the well-known-cache Cloudflare Worker, blocking malicious requests before they reach the origin server.

Changes

  • Add IP_BLACKLIST env var (comma-separated IPs/CIDRs)
  • Support exact IP matching: 203.0.113.1
  • Support CIDR range matching: 198.51.100.0/24
  • Mixed lists: 203.0.113.1,198.51.100.0/24,192.0.2.5
  • Block requests using cf-connecting-ip header (Cloudflare's real client IP)
  • Structured JSON logging for blocked requests (monitoring-ready)
  • Comprehensive unit tests for all IP matching logic

Configuration

Add to wrangler.toml vars:

IP_BLACKLIST = "203.0.113.1,198.51.100.0/24"

Or set via wrangler secret put IP_BLACKLIST for production.

Testing

  • Unit tests cover: exact IP, CIDR range, /0, /32, mixed lists, whitespace, invalid entries
  • All IP matching functions have edge case coverage

Security

  • Uses cf-connecting-ip (Cloudflare-provided) for reliable client IP
  • Falls back to x-forwarded-for first entry
  • Logs blocked IPs with request path for forensics

…ublime247#1045)

- Add IP_BLACKLIST env var for comma-separated IPs/CIDRs
- Support exact IP and CIDR range matching (e.g. 192.168.1.0/24)
- Block requests at the edge before they reach the origin
- Log blocked requests with structured JSON for monitoring
- Use cf-connecting-ip header for accurate client IP detection
- Add comprehensive unit tests for IP matching logic
- Document configuration in wrangler.toml with examples
@sublime247 sublime247 closed this May 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MEDIUM] Implement Cloudflare Worker Edge Security IP Blacklist Rules

3 participants