Files
CatoandClaude Opus 5 fbb0be51ee fix(enquiry): the spam throttle keyed on a value the sender picks (#40)
The enquiry route's clientIp read the FIRST hop of X-Forwarded-For. Its own
comment said "Caddy sits in front, so the socket address is always the proxy" —
true, and the reason the conclusion was backwards: Caddy APPENDS the real peer
address to whatever header arrived, so the rightmost entry is the only one we
wrote and every entry to its left is a string the sender typed.

Reading [0] therefore let a spammer send a different leading value on each
request and land in a fresh bucket every time. The five-an-hour limit could
never be reached, so the mailbox had no throttle at all — only the honeypot
fields stood between it and a script.

Take the last hop instead. The x-real-ip and 'unknown' fallbacks are unchanged
and in the same order, and RATE is untouched at 5/hour — a real sender behind
Caddy now has exactly one key, which was always the intent.

clientIp moves to lib/client-ip.ts: a route.ts may not export arbitrary
symbols, so where it was it could not be tested, which is how the inverted
reading survived. It now has tests, including one that rotates the leading hop
and asserts every variation keys the same bucket. Proven by mutation: putting
[0] back fails 3 of them.


Claude-Session: https://claude.ai/code/session_01NLZ6vs1jsWw2kKbpWTZHf2

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-17 04:54:56 -07:00
..
2026-08-29 10:23:53 +00:00