SECURITY: realIP trusts X-Forwarded-For/X-Real-IP headers unconditionally #44

Closed
opened 2026-02-16 06:56:37 +01:00 by clawbot · 1 comment
Collaborator

Severity: MEDIUM

File: internal/middleware/middleware.go lines ~105-125 (realIP function)

Description

The realIP function trusts X-Real-IP and X-Forwarded-For headers from any client, not just trusted reverse proxies. This is used for:

  1. Request logging (informational)
  2. Rate limiting (security-critical)

An attacker can bypass the login rate limiter by sending a spoofed X-Forwarded-For header with a different IP on each request, getting unlimited login attempts.

Suggested Fix

  1. Add a configuration option for trusted proxy CIDRs
  2. Only trust forwarded headers when the direct connection comes from a trusted proxy
  3. Fall back to RemoteAddr for untrusted connections

Alternatively, use chi's built-in middleware.RealIP which can be configured with trusted proxies, or always rate-limit on RemoteAddr in addition to the extracted IP.

## Severity: MEDIUM ## File: `internal/middleware/middleware.go` lines ~105-125 (realIP function) ## Description The `realIP` function trusts `X-Real-IP` and `X-Forwarded-For` headers from any client, not just trusted reverse proxies. This is used for: 1. Request logging (informational) 2. **Rate limiting** (security-critical) An attacker can bypass the login rate limiter by sending a spoofed `X-Forwarded-For` header with a different IP on each request, getting unlimited login attempts. ## Suggested Fix 1. Add a configuration option for trusted proxy CIDRs 2. Only trust forwarded headers when the direct connection comes from a trusted proxy 3. Fall back to `RemoteAddr` for untrusted connections Alternatively, use chi's built-in `middleware.RealIP` which can be configured with trusted proxies, or always rate-limit on `RemoteAddr` in addition to the extracted IP.
Owner

assume any request from an RFC1918 IP is a trusted proxy. if the request has an x-real-ip or x-forwarded-for and isn't coming from an rfc1918 ip, fail closed.

assume any request from an RFC1918 IP is a trusted proxy. if the request has an x-real-ip or x-forwarded-for and isn't coming from an rfc1918 ip, fail closed.
sneak closed this issue 2026-02-16 07:03:23 +01:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sneak/upaas#44
No description provided.