Don't trust proxy headers for client IP#1492
Merged
Merged
Conversation
The device is reached directly rather than behind a reverse proxy, but gin trusts all proxies by default, so c.ClientIP() returns the client-controlled X-Forwarded-For/X-Real-IP value. A caller could rotate that header to get a fresh rate-limit key on every request and bypass the login/setup throttle. Call SetTrustedProxies(nil) so ClientIP() uses the real socket peer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The web server runs
gin.Default()without callingSetTrustedProxies, so gin trusts every proxy by default andc.ClientIP()returns the client-controlledX-Forwarded-For/X-Real-IPvalue.The device is reached directly, not behind a reverse proxy, so those headers should never be trusted. As-is, a caller can rotate
X-Forwarded-Forto get a fresh rate-limit key on every request and bypass the throttle on/auth/login-localand/device/setup, enabling unlimited online password guessing.Fix: call
r.SetTrustedProxies(nil)soClientIP()uses the real socket peer. Also tightens the IP shown in logs/metrics.Note
Low Risk
Small, security-hardening router bootstrap change with no intended behavior change when the device is not behind a proxy; fails fast if proxy config cannot be applied.
Overview
Disables trusting proxy headers in Gin during router setup by calling
r.SetTrustedProxies(nil), with fatal logging if that configuration fails.Because the KVM web UI is reached directly (not behind a reverse proxy),
c.ClientIP()will now use the real TCP peer instead of client-controlledX-Forwarded-For/X-Real-IP. That closes a bypass where attackers could rotate forwarded IPs to evade the password rate limiter on/auth/login-localand/device/setup, and makes logs/metrics IP labels reflect the actual connection source.Reviewed by Cursor Bugbot for commit 97cab04. Bugbot is set up for automated code reviews on this repo. Configure here.