[H-1] Rate limiter collapses to one shared bucket behind Caddy — remote lockout DoS of /login and /oauth/token #5

Closed
opened 2026-11-14 18:28:40 +01:00 by amiryahaya · 0 comments
Owner

Finding

Rate limiting keys on conn.remote_ip (the TCP peer). There is no RemoteIp/X-Forwarded-For handling anywhere, so in the shipped Docker topology every external request arrives from the Caddy container IP: one shared bucket per client_id.

Evidence

  • lib/mdid_ws/auth/rate_limiter.ex:122-131 — get_remote_ip returns conn.remote_ip
  • lib/mdid_ws_web/endpoint.ex — no trusted-proxy/forwarded-header plug (grep-verified)

Impact

5 bad secrets from one attacker → 30-minute lockout for every legitimate user of that client on both /oauth/token and /login; repeatable forever = sustained remote DoS of the CA's token issuance. (Silver lining: XFF spoofing is impossible since the header is never read.)

Fix

  • Add trusted-proxy handling (RemoteIp plug or equivalent) restricted to the Caddy subnet, keyed on the real client IP
  • Key lockout primarily on client_id with a separate coarse per-IP cap so one IP cannot lock a shared client for everyone
  • Return Retry-After on 429

Line numbers refer to the initial import commit 282cb11. Source: comprehensive audit, 2026-11-12 (first review of this codebase).

## Finding Rate limiting keys on `conn.remote_ip` (the TCP peer). There is no RemoteIp/X-Forwarded-For handling anywhere, so in the shipped Docker topology every external request arrives from the Caddy container IP: one shared bucket per client_id. ## Evidence - `lib/mdid_ws/auth/rate_limiter.ex:122-131` — `get_remote_ip` returns `conn.remote_ip` - `lib/mdid_ws_web/endpoint.ex` — no trusted-proxy/forwarded-header plug (grep-verified) ## Impact 5 bad secrets from one attacker → 30-minute lockout for **every** legitimate user of that client on both /oauth/token and /login; repeatable forever = sustained remote DoS of the CA's token issuance. (Silver lining: XFF spoofing is impossible since the header is never read.) ## Fix - [ ] Add trusted-proxy handling (RemoteIp plug or equivalent) restricted to the Caddy subnet, keyed on the real client IP - [ ] Key lockout primarily on client_id with a separate coarse per-IP cap so one IP cannot lock a shared client for everyone - [ ] Return `Retry-After` on 429 _Line numbers refer to the initial import commit `282cb11`. Source: comprehensive audit, 2026-11-12 (first review of this codebase)._
Sign in to join this conversation.
No description provided.