fix(web): key the subscribe limit on the real client

Behind a reverse proxy every visitor shared the proxy's address, so the
whole site got 10 signups an hour and one person could block everyone.
Over IPv6 each address of a /64 was a fresh key, so the limit did not
bind and the map grew by one entry per address.

- web.trusted_proxies (addresses or CIDR ranges, default empty) is
  validated at load and passed to the web handler. X-Forwarded-For is
  read only when the TCP peer is a trusted proxy; the client is then the
  right-most entry that is not itself a trusted proxy. An empty or
  malformed header falls back to the peer. With no trusted proxy the
  behaviour is unchanged: the header is ignored.
- IPv6 clients are keyed by their /64, IPv4 clients by address.
- The limiter remembers at most 100000 clients. When full it sweeps
  expired entries first and otherwise answers 429 to new clients until
  the oldest window ends, instead of growing.
This commit is contained in:
tgiachi 2026-11-10 15:11:26 +01:00
commit 44b3f9d98a

View file

@ -15,6 +15,10 @@ relay:
# rate_per_second: 14 # at most this many sends started per second, for relays that throttle (Amazon SES); 0 = unlimited
web:
listen: 0.0.0.0:8081 # public archive and unsubscribe pages; "" disables them
# Reverse proxies (addresses or CIDR ranges) allowed to name the visitor in X-Forwarded-For, for
# the subscribe form's limit of 10 posts per hour per IPv4 address or IPv6 /64. Empty (the
# default): the TCP peer is the visitor and the header is ignored.
# trusted_proxies: [172.16.0.0/12]
api:
listen: 0.0.0.0:8080
# The API token is read from the PARSIMONY_API_TOKEN environment variable.