Overview
A login form, a search box, an export endpoint: blocking them blocks your users. What is wrong is the rate, and the response should be proportional to that.
In Synapse a rate limit is a WAF action, not a separate system, so the same rule that identifies the traffic decides what happens to it.
When you see this
- One client calls an endpoint far more often than a person could.
- Login failures arrive at a steady, machine pace.
- An expensive endpoint slows down under a single client.
Steps
- 01
Pick the endpoint
Write a WAF rule that selects the traffic, and give it the rate_limit action.
WAF rule, action rate_limit http.request.path == "/login" and http.request.method == "POST" - 02
Set requests, period and duration
requests is how many are allowed in the window, period is the window in seconds, and duration is how long the client stays at 429 once over. duration is the penalty, not the window: period 60 with duration 600 counts a burst over a minute and holds the client for ten.
Settings on the rule requests: 100 period: 60 duration: 600 - 03
Behind a load balancer, set trusted proxies
The bucket keys on the L4 socket peer. A balancer that rotates its source addresses spreads one client across many buckets, so the rule never fires; one that collapses clients onto a few addresses makes real users limit each other. List the ranges your proxies connect from, and Synapse takes the client from the first X-Forwarded-For token for those connections only.
/etc/synapse/config.yaml proxy: trusted_proxies: - "10.10.0.0/20" # your load balancer's rangeDecisionDoes traffic reach Synapse through a load balancer?Yes List its ranges in proxy.trusted_proxies, and only those.
No The socket peer is the client. Nothing to do.
- 04
Combine it with what you know
A rate limit can take any condition the WAF can: tighten it for sources the threat feed already doubts.
WAF rule, action rate_limit http.request.path == "/login" and threat.score > 30 - 05
Count enforcement, not evaluation
Requests under the threshold are not marked as remediated. Only those that received a 429 are, so the event stream counts enforcement.
Every rate-limited request jq -c 'select(.action == "ratelimit") | {ts, src_ip, rule_id}' \ /var/log/synapse/events.log
Common mistakes
- Reading duration as the window. It is the penalty.
- Rate limiting behind a load balancer without proxy.trusted_proxies.
- Widening trusted_proxies beyond your real proxies, which lets clients forge their own address.
Escalate when
- A client that keeps coming back at the limit from new addresses: it is rotating, so match it by fingerprint instead.
Where this stops working
- Counters are per client address: a client that rotates addresses gets a fresh bucket. Pair the limit with a fingerprint rule.
- Rate limiting is a WAF action, so it needs proxy mode.