Fix trusted proxy client IP resolution for rate limiting - #18
Conversation
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughA new trusted proxy configuration ( Changes
Sequence DiagramsequenceDiagram
participant Client as Client
participant Proxy as Trusted Proxy/LB
participant Server as UniAuth Server
participant ConfigDB as Config (TrustedProxyRanges)
Client->>Proxy: HTTP Request
Proxy->>Proxy: Add X-Forwarded-For: client-ip
Proxy->>Server: Request + XFF Header
Server->>Server: Extract Peer IP from RemoteAddr
Server->>ConfigDB: Is Peer in TrustedProxyRanges?
ConfigDB-->>Server: Yes (proxy is trusted)
Server->>Server: Parse X-Forwarded-For list (R→L)
Server->>Server: Select rightmost untrusted IP
Server-->>Server: Resolved Client IP = parsed-from-header
alt Untrusted Peer / No Forwarded Header
Server-->>Server: Resolved Client IP = peer IP (direct)
end
Server->>Server: Store in Context[ClientIP]
Server->>Server: Use for rate limiting, audit logs
Server-->>Client: Response
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
TRUSTED_PROXY_CIDRSconfiguration and document the fail-closed default in user-facing docsTesting
go test ./...Summary by CodeRabbit
New Features
TRUSTED_PROXY_CIDRSenvironment variable to configure trusted proxy IP addresses for accurate client IP detection in rate limiting and audit trails.Bug Fixes
Documentation