#5 (H-1): rate-limit on the real client IP behind trusted proxies + Retry-After #45

Closed
amiryahaya wants to merge 0 commits from fix/h-1-real-client-ip into main
Owner

Behind Caddy every caller shared the proxy's IP in the login/token rate limiter — five bad secrets from anyone locked out everyone for 30 minutes (remote DoS).

Changes

  • new MdidWsWeb.Plugs.ForwardedRemoteIP: rewrites remote_ip from x-forwarded-for only when the peer and every hop is a trusted proxy (TRUSTED_PROXIES CIDRs; default empty = header never trusted, spoofing impossible as before). Handles chained hops, host:port and bracketed IPv6 entries
  • endpoint wired before the router; compose default TRUSTED_PROXIES=172.16.0.0/12 (Docker networks)
  • Retry-After on 429 from both /oauth/token and /login (remaining lockout seconds)
  • 11 new plug tests + lockout test extended for the header

Full suite: 170 passed locally.

Fixes #5

Behind Caddy every caller shared the proxy's IP in the login/token rate limiter — five bad secrets from anyone locked out **everyone** for 30 minutes (remote DoS). **Changes** - new `MdidWsWeb.Plugs.ForwardedRemoteIP`: rewrites `remote_ip` from `x-forwarded-for` only when the peer and every hop is a trusted proxy (`TRUSTED_PROXIES` CIDRs; default empty = header never trusted, spoofing impossible as before). Handles chained hops, `host:port` and bracketed IPv6 entries - endpoint wired before the router; compose default `TRUSTED_PROXIES=172.16.0.0/12` (Docker networks) - `Retry-After` on 429 from both `/oauth/token` and `/login` (remaining lockout seconds) - 11 new plug tests + lockout test extended for the header Full suite: 170 passed locally. Fixes #5
fix(auth): rate-limit on the real client IP behind trusted proxies, add Retry-After
All checks were successful
Lint / lint (pull_request) Successful in 2m26s
Security / Dependency advisories (mix hex.audit) (pull_request) Successful in 27s
Security / Secret scan (gitleaks) (pull_request) Successful in 10s
Unit tests / test (pull_request) Successful in 2m53s
a5ad6b3be3
Behind the Caddy reverse proxy every request arrived with the proxy
container's IP, so the login/token rate limiter bucketed all callers into
one {proxy_ip}:{client_id} identifier — five bad secrets from anyone
locked out everyone for 30 minutes (remote DoS).

- new ForwardedRemoteIP plug: rewrites conn.remote_ip from
  x-forwarded-for only when the peer AND every intermediary hop is a
  trusted proxy (TRUSTED_PROXIES CIDRs, default empty = header never
  trusted, unspoofable as before); handles chained hops, ports and
  bracketed IPv6
- endpoint pipeline wired before the router; compose default
  TRUSTED_PROXIES=172.16.0.0/12 (docker networks)
- 429 responses now carry Retry-After (remaining lockout seconds) on
  both /api/v1/cert_mgmt/oauth/token and /login

Fixes #5 (audit H-1)
amiryahaya closed this pull request 2026-11-14 18:57:50 +01:00
All checks were successful
Lint / lint (pull_request) Successful in 2m26s
Security / Dependency advisories (mix hex.audit) (pull_request) Successful in 27s
Security / Secret scan (gitleaks) (pull_request) Successful in 10s
Unit tests / test (pull_request) Successful in 2m53s

Pull request closed

Sign in to join this conversation.
No description provided.