Medium, CVSS 6.9GoAmendedPublished
chi Has an IP Spoofing Vulnerability in middleware.RealIP
CVE-2026-72815 · GHSA-3fxj-6jh8-hvhx
- Affected
- Go github.com/go-chi/chi/v5/middleware >= 5.2.1, < 5.3.0
- Fixed in
- 5.3.0· Vendor fix available
- Issue
- The `RealIP` middleware in `go-chi/chi` is vulnerable to IP spoofing because it blindly trusts the first (leftmost) element of the `X-Forwarded-For` HTTP header. This allows a remote attacker to bypass IP-based access control lists (ACLs) and rate-limiting mechanisms by providing a spoofed IP address in the header. Details In `middleware/realip.go`, the `realIP` function parses the `X-Forwarded-For` header and extracts the first comma-separated value: ```go func realIP(r *http.Request) string { // ... } else if xff := r.Header.Get(xForwardedFor); xff != "" { ip, _, _ = strings.Cut(xff, ",") } // ... } ``` Standard practice for `X-Forwarded-For` is that each proxy appends the client's IP to the end of the list. However, since the client can also provide this header, the leftmost values are untrusted. A client can send a header like `X-Forwarded-For: , `, and `go-chi/chi` will treat ` ` as the source of the request. Proof of Concept (PoC) The following code…
Recommended action: Upgrade to 5.3.0 or later, then redeploy and verify.A vendor fix does not resolve your finding until you verify it in your own systems.