fix: rate-limit and audit by real client address
uvicorn does not trust forwarded headers from a peer outside forwarded_allow_ips, so request.client.host was the web gateway for every request. The auth-source bucket therefore counted all customers together: 60 failed logins from one attacker locked out everyone. Security events recorded the gateway address, which made the audit trail useless for attribution. The gateway now overwrites X-Forwarded-For with the peer address it observed instead of appending to whatever the client sent, so the header carries one value the client cannot choose, and client_ip() resolves it with a fallback to the connection peer. The guest-session limiter was keyed on the environment name, making it one global bucket of 120 per 15 minutes: roughly eight new visitors a minute for the whole site before legitimate traffic started receiving 429. It is now per source, and the ceiling is deliberately generous because offices and mobile carriers put many real customers behind a single address. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -63,4 +63,15 @@ def run():
|
||||
attacker.call('/operator/login',{'email':email,'password':'invalid'},expected=429)
|
||||
print('PASS: operator login throttling (only synthetic account bucket exhausted)')
|
||||
|
||||
# Guest sessions are limited per source, not once for the whole deployment.
|
||||
# Keyed on the environment name this was a single global bucket of 120 per
|
||||
# 15 minutes, which the suites above would already have eaten into.
|
||||
for _ in range(25):
|
||||
Client().call('/session')
|
||||
# A forged forwarded address must not let a client pick another bucket: the
|
||||
# gateway overwrites the header, so these count against the real source too.
|
||||
for _ in range(5):
|
||||
raw('/api/session',200,{'X-Forwarded-For':'203.0.113.7'})
|
||||
print('PASS: guest sessions limited per source, forwarded address not client-controlled')
|
||||
|
||||
if __name__=='__main__':run()
|
||||
|
||||
Reference in New Issue
Block a user