Intro

A few years ago, I wrote how to use Fail2Ban to ban clients that hit the private parts of my Caddy server (see 05-fail2ban-for-caddy). It worked, but it always felt like a black box: jail files to write, a regex syntax to learn, and no easy way to see who was banned, why, and from where.

So I wrote my own tool: Banalize.

Banalize follows the same idea as Fail2Ban:

It also adds what I was missing:

  • A dashboard to create rules, test a regex against your real logs, and browse matches and bans by IP and by country.
  • A REST API (with a Swagger UI) to automate everything.
  • Recidive: repeat offenders get exponentially longer bans.
  • Notifications (Signal, email) when an IP gets banned.
  • Persistence: bans survive restarts, and every match, ban and unban is kept in SQLite for auditing.
  • It’s small and fast: the core is a single Rust binary.

In this guide, I will set up Banalize behind Caddy with two rules that I use every day on my home server.

Beta

Banalize is still young (0.0.1-beta). It runs my own server every day, but expect some rough edges.


Prerequisite

Before we start, ensure you have the following prerequisites:

  • A server or machine with Docker installed.
  • Basic understanding of Docker concepts such as containers, images, and volumes.
  • Docker Compose.
  • A Caddy instance (check out 01-caddy-in-docker) writing formatted access logs. This needs the transform-encoder plugin, see 04-install-caddy-plugins and the Format Caddy Logs section of 05-fail2ban-for-caddy.

My Caddy log format, used in all the examples below:

{
    log access-log {
        include http.log.access.access-log
        output file /data/access.log
        format transform `{ts} {request>remote_ip} {request>host} {request>method} {request>uri} {status}` {
            time_format "02/Jan/2006:15:04:05"
        }
    }
}

Each request becomes one line:

02/Dec/2026:10:42:13 203.0.113.7 domain.name GET /.env 404

Fail2Ban

Don’t run Fail2Ban and Banalize on the same log at the same time. They would both try to ban the same IPs.


Installation

Clone the repository:

git clone https://github.com/aussedatlo/banalize.git && cd banalize

The provided docker-compose.yml runs two services:

  • core: the API and the iptables integration, on port 6040.
  • ui: the dashboard, on port 6041.

Both use network_mode: host, so the bans apply to the host network stack.

Banalize needs to read the Caddy log file. Create a docker-compose.override.yml next to it to mount the Caddy data folder read-only:

services:
  core:
    volumes:
      # replace with the path of your Caddy data folder
      - /opt/caddy/data:/var/log/caddy:ro

Build and start it:

docker compose up -d --build

The dashboard is now available at http://<server-ip>:6041, and the API documentation at http://<server-ip>:6040/swagger.

Don't expose the dashboard

The API can create rules and lift bans. Keep ports 6040 and 6041 on your local network, or behind a Caddy subdomain restricted to your LAN (see 02-caddy-hardening).

Why the FORWARD chain?

The compose file sets BANALIZE_CORE_FIREWALL_CHAIN: FORWARD. When Caddy runs in Docker, the traffic to the container doesn’t go through the host INPUT chain: Docker forwards it. A ban in INPUT would do nothing. If Caddy runs directly on the host, use INPUT instead.


Rule 1: Ban Unauthorized Requests

The first rule is the one from my Fail2Ban post: some subdomains are restricted to my local network and answer 401 to everyone else. Nobody from the outside has a good reason to try them twice.

From the dashboard, create a new config, or use the API:

curl -X POST http://localhost:6040/api/configs \
  -H 'Content-Type: application/json' \
  -d '{
    "id": "caddy",
    "name": "Caddy",
    "param": "/var/log/caddy/access.log",
    "regex": "<IP>.*(401|403)$",
    "max_matches": 2,
    "find_time": 864000000,
    "ban_time": 172800000,
    "recidive_multiplicator": 2,
    "ignore_ips": ["192.168.1.0/24"]
  }'
  • param: the log file to watch, as seen from the container.
  • regex: <IP> is where Banalize captures the address.
  • max_matches and find_time: 2 matches in 10 days, so two unauthorized requests and you’re out.
  • ban_time: the first ban lasts 2 days. All times are in milliseconds.
  • recidive_multiplicator: the next ban lasts 4 days, then 8, 16…
  • ignore_ips: IPs or ranges to never ban, like your local network.

The same config, from the dashboard:

This rule also protects login pages for free. A failed login on most self-hosted apps answers 401. With this config, a brute-force attempt gets two tries per IP before being dropped at the firewall.


Rule 2: Ban Secret File Scanners

If your server is reachable from the Internet, your logs are full of requests like these:

02/Dec/2026:10:42:13 203.0.113.7 domain.name GET /.env 404
02/Dec/2026:10:42:13 203.0.113.7 domain.name GET /.env.production 404
02/Dec/2026:10:42:13 203.0.113.7 domain.name GET /.git/config 404
02/Dec/2026:10:42:13 203.0.113.7 domain.name GET /.aws/credentials 404

Bots scan the whole Internet looking for leaked secrets. No real visitor ever asks for /.env, so one request is enough to ban:

curl -X POST http://localhost:6040/api/configs \
  -H 'Content-Type: application/json' \
  -d '{
    "id": "secrets",
    "name": "Secret files",
    "param": "/var/log/caddy/access.log",
    "regex": "<IP> \\S+ \\S+ \\S*/\\.(?:env|git|aws)\\S* [45]\\d\\d$",
    "max_matches": 1,
    "find_time": 864000000,
    "ban_time": 8640000000,
    "ignore_ips": ["192.168.1.0/24"]
  }'

Every part of the regex has a reason:

  • \S*/\.(?:env|git|aws) matches a path segment starting with .env, .git or .aws, anywhere in the URL.
  • [45]\d\d$ only counts errors. If one day you really serve a .env, Banalize won’t ban your visitors for it.

Extend the list with what you see in your own logs. And if you host a file-sync app (Nextcloud, Filebrowser…), exclude its URLs: if you sync a code repository, a .git folder is perfectly legit there. A negative lookahead does it, for example <IP> \S+ \S+ (?!/your/file-sync/path/)\S*/\.(?:env|git|aws)\S* [45]\d\d$.

Learn from my mistake

My first version was <IP>.*\.(env|git|log|bak|sql).*. It banned me the day I uploaded a folder whose name contained .logo to my file-sync app: \.log matched .logo. Anchor your regex and exclude your file-sync URLs.

The dashboard validates your regex against Banalize’s engine as you type. Banalize uses fancy-regex, so lookaheads like (?!...) work. To check what it would actually match, test it on your own log first, for example:

grep -P '\S+ \S+ \S*/\.(?:env|git|aws)\S* [45]\d\d$' /opt/caddy/data/access.log | tail

With both rules, the Configs page of the dashboard looks like this:


Notifications

To get a message on each ban, Banalize supports Signal (through signal-cli-rest-api, see 14-ssh-signal-notifications) and email:

curl -X POST http://localhost:6040/api/notifiers \
  -H 'Content-Type: application/json' \
  -d '{
    "events": ["ban"],
    "signal_config": {
      "server": "http://localhost:8080/v2/send",
      "number": "+33600000000",
      "recipients": ["+33600000000"]
    }
  }'

Then hit POST /api/notifiers/{id}/test to check it works.


The Dashboard

The home page sums up the activity of all the rules: bans, matches in the last 24 hours, where the attacks come from, and the top offenders.

Each config has its own page, with the same stats for that rule only:

Below, the live log shows the new lines of the file as they arrive, with the regex matches highlighted. It’s the easiest way to check a rule. Then every match, ban and unban is listed, and you can search by IP or lift a ban by hand:

The offenders page ranks the IPs by activity. The scanners of the next post are easy to spot: around 68 matches for a single ban.

Demo data

These screenshots come from a demo instance with fake data. The IPs are from reserved ranges that don’t exist on the Internet.


Pitfalls

A few things I learned running it:

  • Docker gateway: if you test Caddy with curl from the host itself, Caddy doesn’t see 127.0.0.1. It sees the Docker gateway, for example 172.18.0.1. A few 404 tests and Banalize bans your own gateway. Add it to ignore_ips, or lift the ban from the dashboard.
  • Never abort in Caddy where you want a ban: an aborted request has no status code in the log, so a regex ending with [45]\d\d$ won’t match it. Answer with a real 401 or 404 instead.
  • A ban is after the fact: Banalize reads the log, so the request has already been served. It protects you from the next requests, not the first one. That turned out to matter a lot, see 20-bulk-attacks-reflexion.
  • Check the firewall: iptables -S FORWARD | grep banalize should show the jump to the banalize chain, and iptables -S banalize lists the active bans.

Conclusion

In a few minutes, Banalize turns your Caddy access log into a firewall: unauthorized requests and secret-file scanners get dropped before they can try again, repeat offenders stay out longer, and you get a dashboard to see it all happening.

Since June, on my server, Banalize has banned 1,126 IPs from 46 countries:

Running these two rules taught me a lot about who knocks at my door: some IPs sent 70 requests in less than 100 ms before the ban landed. That’s the subject of the next post: 20-bulk-attacks-reflexion.


Resources



Recent Posts