Edge defense: blocking scanner attacks at the front door
in Web security
A daily attack report full of scanner hits tempts you to ban addresses, but on a small site the cheaper fix is to stop those requests before they reach the app.
- What did a day of the report hold?
- Was anything compromised?
- Why not ban the addresses?
- Closing scanner paths in Caddy
- Do the alerts still see the probes?
- What else changed since day one?
- What is still open?
- Strong and weak points
- Summary
On its first day online, aiwow.dev was scanned within hours, and the dashboards were empty because the log shipper had stalled. That story is in aiwow.dev went online and got 561 attack probes in its first day. Since then a timer mails me a report every morning: the last 24 hours of probes, rate-limit blocks and server errors, with every such request attached as a CSV. Three days in, I opened one, handed the CSV to a coding agent and asked two questions: were we compromised, and how do I ban the addresses that attack me?
| Tool | Used for |
|---|---|
| Caddy 2.11.7 with the caddy-ratelimit module | HTTPS, rate limits, one masked JSON log line per request, and now the scanner drop |
| Loki and Grafana (hosted) | log store, the Attacks dashboard, five log alerts |
| Python 3.13 | the daily report, and a one-off script that counted the CSV |
| Claude Code | read the CSV, answered the questions, wrote the Caddy rule and its tests |
What did a day of the report hold?
The CSV held 1,428 rows, and 1,264 of them were mine. That afternoon I had proven the new log alerts by firing each one on purpose: a flood of requests to trip the rate limit, a burst of probe paths, then the app stopped for four minutes so it answered 502. My uptime check hit the stopped app too. All of that lands in the report, because the report can't tell a drill from an attack.
The other 164 rows came from 22 address ranges (each log line keeps only the first three parts of an IPv4 address, a /24):
kind status rows
probe 404 114
probe 429 13
rate-limited 429 37
methods: GET x 164
The probes asked for the usual things:
58 .env files (/.env, /.env.backup, /app/.env, /api/.env ...)
30 WordPress (/wp-admin/install.php x 22)
13 PHP pages (/info.php, /phpinfo.php ...)
10 /.aws/credentials and /.aws/config
8 /.git/config
One range sent 95 of the 164 rows, with a Chrome-on-Windows user agent. 133 rows geolocated to Germany. Neither tells you much: scanners run on rented cloud machines and fake their browser.
Was anything compromised?
No probe worked: every outside row is a 404 or a 429, none is a 2xx or a 3xx, and every one is a GET. The site has no WordPress and no PHP, and the image leaves out .env and .git, so there is nothing at those paths to find.
The agent named the limit of that answer itself, and it is worth keeping. The CSV holds only bad requests by design. It can show that no probe here succeeded; it can't prove that nothing else happened. A careful attacker uses real pages under the rate limit, which is why the report also lists odd 4xx answers on real routes, the top senders of POST requests, and the addresses that read the most distinct pages. This CSV held no odd 4xx rows at all.
Why not ban the addresses?
Banning by address would cost more than it saves here, for three reasons the agent gave:
- The log has no full address. Caddy cuts IPv4 to a /24 before writing the line. A ban built from it blocks 256 addresses, neighbours included.
- Scanners move. The agent traced today's ranges to large cloud providers, and tomorrow's will be different ones.
- IPv6 visitors all share one address. Docker hands every IPv6 request to Caddy from one internal address of its own. Banning that would block every IPv6 reader. My own drill traffic arrived the same way.
The better question is what those requests cost. Each probe went through Caddy to the app, which runs a single worker, and the app built a 404 page for it. That is work spent on nobody. The fix is to stop them one step earlier.
Closing scanner paths in Caddy
Caddy now closes the connection, with no reply, on any path that looks like a scanner: /.env, /.git, wp-*, *.php, /actuator, /cgi-bin and the rest. Figure 1 shows where the drop sits.
The dashed arrow is the new exit: the scanner gets a closed connection and the app never sees the request. The rule is two lines in the Caddyfile:
@scanner path_regexp ^(?:(?i)(/.*)?/([.](env|git|svn|hg|aws|ssh|...)([./].*)?|wp-[a-z]+([./].*)?|...)$
abort @scanner
abort is Caddy's directive for dropping a connection without writing a response. A closed connection also gives the scanner less to learn than a 404 page: no headers, no status, no server name.
- Caddy checks the path against the probe pattern.
- A scanner path gets
abort: the connection closes. - Any other path goes to the app as before, which answers 200 or 404.
- Both exits write one masked log line.
Before writing the rule, the agent checked that no real page matches the pattern: all 65 routes, the static files and every post URL. A post slug starting wp- would match, and a test already fails if one is ever served.
Do the alerts still see the probes?
Yes, because the drop uses the same pattern and still writes the log line. The pattern is PROBE_ in the daily report's code. The Probe burst alert (more than 100 probe hits in 5 minutes), the Attacks dashboard and the report all match on it. The Caddyfile copies it word for word.
Copies drift, so four new tests pin them:
- The Caddyfile's matcher equals
PROBE_, wrapped inRE ^(?:...)$. /.env,/.git/config,/wp-admin/install.php,/index.php,/cgi-bin/xand/ACTUATOR/envget no response from a real Caddy container./, a post and/.well-known/security.txtstill return 200.- A dropped
/.envstill appears in Caddy's access log.
The last one matters most. If abort skipped the log line, the alert, the dashboard and the report would all go quiet on scanners, and a quiet report reads as a quiet day. The tests failed before the rule existed and passed after. In that chat the full suite passed too: 1,519 tests, 97.85% coverage.
What else changed since day one?
The day-one post ended with three next steps. Two shipped in the three days since, with more besides:
| Day-one gap | What exists now |
|---|---|
| A dead log shipper looked like a quiet day | A Logs stopped alert fires after 15 minutes with no Caddy line. Proven: the shipper was stopped at 16:40 UTC on 11 November and the alert email went out at 16:54. |
| The report could not tell zero lines from a calm day | A day with zero lines gets NO LOG LINES, check the log shipper in the subject. |
| Log alerts existed only on paper | Flood, Probe burst, 5xx burst and SSH login are live, and each fired once on purpose between 17:26 and 17:33 UTC. |
| A careful attacker under the rate limit was invisible | The report lists odd 4xx on real routes, top POST senders and the widest readers. |
| The per-attacker table hit the log store's series cap at 7 days (485 of 500) | It reads only attack lines (429 or probe), and its widest query is 101 series. |
The drill that fired the alerts is also what filled 1,264 rows of the report above. Proving an alert leaves traffic behind, so note the drill's time before you read the next report.
What is still open?
The IPv6 gap is planned but not built: every IPv6 visitor shares one rate-limit bucket and is invisible by country in the report. The fix is to turn on IPv6 for the Docker network, so Caddy sees each visitor's own address. It is a separate change because it needs a minute of downtime and a proof on the server first.
The drop itself is live, and its first deploy taught one thing. A plain docker compose up -d left Caddy running the old config, so /.env still got the app's 404. Recreating the Caddy container loaded the rule. On 12 November, /.env and /wp-admin/install.php on the live site got no reply, and / returned 200. The runbook now says a Caddyfile change needs --force-recreate caddy.
Strong and weak points
Where it wins:
- One pattern drives the drop, the alert, the dashboard and the report, and a test fails if any copy drifts.
- Scanners cost the app nothing now, and learn less.
- The drop keeps the log line, so the counts stay honest.
- The ban decision was made on the data: masked logs, moving ranges and the shared IPv6 address all argue against it.
Where it loses:
- The pattern only knows paths it lists. A new scanner target, say
/.npmrc, still reaches the app until someone adds it. - A scanner over the rate limit still shows up as 429s; the drop changes nothing for it.
- The report mixes drills and attacks, and nothing marks which is which.
- No fix yet for IPv6 visitors sharing one address.
- The first deploy left Caddy on its old config until the container was recreated; nothing checked for it.
Summary
- Read the report's own rows first: 1,264 of 1,428 were my alert drill, not attackers.
- 164 outside requests from 22 ranges asked for
.env, WordPress, PHP, AWS keys and.git; none got a 2xx or 3xx. - Banning by address is weak when logs keep only a /24, scanners rotate clouds, and IPv6 arrives as one gateway address.
- Dropping scanner paths in Caddy saves the app's single worker and gives scanners less, as long as the log line stays.
- Keep one pattern for the drop and every counter, and pin the copies with tests.
- Ship the IPv6 network change, so the rate limit and the report see each IPv6 visitor.
- Mark drill traffic in the report, so a proof run never reads as an attack.