Skip to content

Don't trust proxy headers for client IP#1492

Merged
adamshiervani merged 1 commit into
devfrom
fix/disable-trusted-proxies
Jun 11, 2026
Merged

Don't trust proxy headers for client IP#1492
adamshiervani merged 1 commit into
devfrom
fix/disable-trusted-proxies

Conversation

@adamshiervani

@adamshiervani adamshiervani commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

The web server runs gin.Default() without calling SetTrustedProxies, so gin trusts every proxy by default and c.ClientIP() returns the client-controlled X-Forwarded-For / X-Real-IP value.

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-For to get a fresh rate-limit key on every request and bypass the throttle on /auth/login-local and /device/setup, enabling unlimited online password guessing.

Fix: call r.SetTrustedProxies(nil) so ClientIP() 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-controlled X-Forwarded-For / X-Real-IP. That closes a bypass where attackers could rotate forwarded IPs to evade the password rate limiter on /auth/login-local and /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.

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.
@adamshiervani adamshiervani marked this pull request as ready for review June 11, 2026 08:55
@adamshiervani adamshiervani merged commit 3ae3fae into dev Jun 11, 2026
5 checks passed
@adamshiervani adamshiervani deleted the fix/disable-trusted-proxies branch June 11, 2026 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant