You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
http: a trusted-proxy-aware client address; GetClientIP is spoofable and used as a rate-limit key #369
GetClientIP returns the first entry of X-Forwarded-For, then Forwarded, then X-Real-IP, and only then the connection's address. Its own doc comment says the result is attacker-controlled and must not be used as a trust boundary for rate limiting, access control or audit logging. Two services use it as exactly that, as the fallback key of a rate limiter, so a caller can rotate the header to dodge the limit. This comes from dioad/eventbroker#108 (candidate X3, row E13).
Where it bites
connect-control: internal/server/ratelimit.go falls back to dch.GetClientIP. The entitlements /webhook route (a public, unauthenticated payment-provider endpoint) is protected only by that limiter, with no principal extraction ahead of it, so every request is keyed by the spoofable address. Filed separately in dioad/connect-control.
eventbroker: principalFromRequest has the same fallback, reached when no authenticated principal is present (unauthenticated mode).
connect keys its pre-authentication limiter by RemoteAddr, which is the connection's address and is not spoofable (it relies on the proxy protocol where a proxy is in front).
Proposal
Add a client-address function in dioad/net that is safe by default:
Default to the connection's RemoteAddr (host only).
Honour forwarding headers only from configured trusted proxies: take the right-most untrusted entry of X-Forwarded-For (walking back past trusted hops), and ignore the headers entirely when the peer is not trusted.
Take the trusted set as config ([]netip.Prefix, with a Check), so Fly, Cloudflare and a plain deployment can each state theirs.
Keep GetClientIP for display and logging, and update its doc to point at the safe function. Do not change its behaviour silently.
Understand a PROXY protocol peer, where RemoteAddr is already the real client.
Acceptance criteria
Tests that a request from an untrusted peer cannot choose its address with any of the three headers, and that a trusted proxy's X-Forwarded-For chain resolves to the right client, including IPv6 and multiple hops.
Activity