Skip to content

Ban at Cloudflare's edge; behind = cloudflare; warn when the log has Cloudflare's addresses - #14

Merged
FMXExpress merged 1 commit into
mainfrom
cloudflare
Nov 15, 2026
Merged

FMXExpress merged 1 commit into
mainfrom
cloudflare

Conversation

@FMXExpress

Copy link
Copy Markdown
Owner

For sites behind Cloudflare. On one real WordPress server, 82% of a day's 100,760 requests came from 1,430 Cloudflare addresses, because Apache logged the proxy rather than the visitor. Rules alone would have banned 343 Cloudflare addresses: each carries many visitors, none of them the attacker, and 19 carried the site's own wp-cron calls.

[cloudflare]: ban at the edge, for every site in the account

[cloudflare]
account_id = 0123456789abcdef0123456789abcdef
api_token =              ; or CLOUDFLARE_API_TOKEN
  • One list, one rule per site. jevban keeps one account-level IP list (list = jevban) and adds one rule to each site: ip.src in $jevban, action block. An address caught on one site is blocked on all of them. A new site gets its rule the next time jevban starts, and a restart doesn't duplicate rules.
  • Updates. After each batch of bans and unbans, the list is replaced whole with the active bans: one asynchronous PUT …/items, polled until it completes. A failed update is put right by the next one, entries left over from before a restart are removed, and expired bans leave the list. Cloudflare allows one pending bulk operation per account, which the action thread's single worker guarantees.
  • Limits. max_items (10,000, the free plan's total across lists) drops the oldest bans first. The free plan allows one custom list; if it's already in use, list = can name that existing IP list. The errors say so.
  • Failures never stop jevban. A wrong token, the list limit or a network failure is logged and retried with the next ban, and local bans continue.
  • Token permissions: Account Filter Lists Edit, Zone WAF Edit, Zone Read.
  • [action] keeps working alongside it for requests straight to the server's address (18% of that day, half of them probes). A visitor's address in the server's firewall can't hurt traffic that arrives through Cloudflare.

behind = cloudflare, and a warning

  • behind = cloudflare adds Cloudflare's published ranges (ips-v4 and ips-v6, November 2026) to ignoreip; [cloudflare] implies it. On the real log: 512 bans → 169, all of them direct connections. Every ban sampled was a real scanner (wordlist walkers, plugin fingerprinters, .env and .git hunters).
  • Without it, jevban warns when 30% or more of the first 2,000 requests come from Cloudflare. It fired on the real log (1,367 of 2,000).
  • The README's new "Behind Cloudflare" section gives the mod_remoteip config (CF-Connecting-IP, Cloudflare's ranges) that makes the log carry the visitor's address.

Tests

  • API mock: tests/mock_cloudflare.py implements the documented calls (the lists, the asynchronous bulk replace and its status, zones, zone entry-point rulesets, rule creation) with the documented envelope and free-plan limits: one list, one pending operation, five rules per zone.
  • End to end (tests/cloudflare_e2e.sh, in CI), with three sites, one of which already has a custom rule:
    • every site ends up with exactly one blocking rule;
    • three bans (IPv4 and IPv6) reach the list;
    • expiry empties it;
    • a restart adds no second rule.
  • Failure cases: a wrong token and a full plan are logged with the cause, local bans continue, and jevban keeps running.
  • Unit tests: 219 checks, 0 failed (list-name rules, [cloudflare] implying behind, a missing token refused).
  • No regression: benchmark quality is unchanged when [cloudflare] isn't configured.

Not yet tested against Cloudflare itself. That needs an API token on the account.


Generated by Claude Code

…Cloudflare's addresses

[cloudflare] keeps one account-level IP list (default jevban) and adds one
rule per zone, ip.src in $jevban (block): an address caught on one site is
blocked on every site of the account. The list is replaced whole after each
batch from the active bans (PUT items, polled until completed), so a failed
update is put right by the next; expired bans leave it. Errors are logged and
retried; jevban keeps running. Local [action] bans still run, for requests
straight to the server. HttpJson in Ban.Https makes any HTTP method.

behind = cloudflare (implied by [cloudflare]) never judges or bans
Cloudflare's addresses. Without it, jevban warns when 30% of the first 2,000
requests come from them: on a real server's day, rules alone would have
banned 343 Cloudflare addresses (19 carrying the site's own wp-cron).

tests/mock_cloudflare.py implements the documented calls (one pending bulk
operation, one list and five rules per zone as on the free plan);
tests/cloudflare_e2e.sh runs jevban against it in CI. 219 checks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NPVFJFY41846T15QqxmGW2
@FMXExpress
FMXExpress merged commit 5d34eb1 into main Nov 15, 2026
2 checks passed
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.

2 participants