GHSA-9g5q-2w5x-hmxf
ADVISORY - githubSummary
Summary
The vulnerability allows the Request.RemoteAddr to be spoofed when determining the request source IP via the X-Forwarded-For header. This could result in misidentification of the request source and potentially compromise access control and logging integrity.
Details
Currently, the RealIP() implementation splits the X-Forwarded-For header by , and uses the first IP.
https://github.com/go-chi/chi/blob/v5.1.0/middleware/realip.go#L50-L54
However, relying on the first IP in the X-Forwarded-For header is insecure because it can be manipulated by attackers to falsify the source IP.
Malicious Case:
- A malicious client sends a request with a forged IP in the X-Forwarded-For header:
X-Forwarded-For: <forged-ip> - The proxy appends the actual client’s IP and forwards the request:
X-Forwarded-For: <forged-ip>,<client-ip> - If the server always uses the first IP, it becomes vulnerable to IP spoofing.
Ideally, the implementation should verify IPs starting from the end of the X-Forwarded-For header value, skipping trusted IPs within the system, and using the first untrusted IP as the actual client IP.
For example, the labstack/echo web framework processes the X-Forwarded-For header by checking IPs from the end, skipping trusted IPs, and using the first untrusted IP as the client's ip.
https://github.com/labstack/echo/blob/v4.13.2/ip.go#L261-L273
PoC
1. Run the Go application with the following code:
package main
import (
"fmt"
"log"
"net/http"
"github.com/go-chi/chi/v5/middleware"
)
func main() {
// Set handler to print the remote address
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(
w,
fmt.Sprintf("remote addr: %s (want 192.0.2.1)", r.RemoteAddr),
)
})
// Use RealIP middleware
log.Fatal(http.ListenAndServe(":8080", middleware.RealIP(handler)))
}
2. Send a request to the server using curl with a manipulated X-Forwarded-For header:
$ curl localhost:8080 -H 'X-Forwarded-For: 192.0.2.2, 192.0.2.1'
remote addr: 192.0.2.2 (want 192.0.2.1)
Impact
This vulnerability can lead to a request source IP spoofing issue, which may allow attackers to bypass access controls or falsify request logs. It primarily affects systems that rely on X-Forwarded-For to determine the actual client IP, particularly in scenarios where intermediary proxies or load balancers are involved.
Common Weakness Enumeration (CWE)
Origin Validation Error
GitHub
-
CVSS SCORE
7.7highGoLang
-
minimos
MINI-37v3-x6xp-wmcj
-
minimos
MINI-3g57-f789-cf4f
-
minimos
MINI-3j64-jmrf-5qgj
-
minimos
MINI-3xqc-72p3-fvc8
-
minimos
MINI-4ffg-2f6m-8c3g
-
minimos
MINI-4pqx-q9mw-g6fj
-
minimos
MINI-5f3h-p6vv-x9q9
-
minimos
MINI-5ghx-878p-gjp5
-
minimos
MINI-5mwg-r4vx-v3xf
-
minimos
MINI-6j95-hpm9-rhqv
-
minimos
MINI-728j-pvp8-728j
-
minimos
MINI-7jc4-6xgv-396j
-
minimos
MINI-852x-x9f6-rrhq
-
minimos
MINI-8fgg-q3xp-cv52
-
minimos
MINI-8mjj-j446-65mc
-
minimos
MINI-9jph-3vw9-558x
-
minimos
MINI-9r8r-8g8p-7fq6
-
minimos
MINI-c62q-pjgf-h888
-
minimos
MINI-f68q-4px9-hfmg
-
minimos
MINI-ff37-66gc-h4c6
-
minimos
MINI-fw75-g22v-ff2j
-
minimos
MINI-g6r9-f55x-cxwg
-
minimos
MINI-jcvw-r4jq-mc6r
-
minimos
MINI-m6fx-g298-c8fg
-
minimos
MINI-mc43-rxh5-783j
-
minimos
MINI-mqph-4mwp-2wq6
-
minimos
MINI-p7qg-gwhp-jgm6
-
minimos
MINI-pf3g-cq89-w7fh
-
minimos
MINI-qmwx-8j7r-r395
-
minimos
MINI-qq9m-r6q6-mp3m
-
minimos
MINI-r72p-cxr7-px23
-
minimos
MINI-rg46-6crh-w7x4
-
minimos
MINI-rjqc-5rq2-wphq
-
minimos
MINI-rp4q-v5mx-x2cq
-
minimos
MINI-vcfv-392j-5rqm
-
minimos
MINI-wf7v-rmpv-8gvq
-
minimos
MINI-wrv3-wp2r-v765
-
minimos
MINI-x6w2-9fhp-4xpw
-
minimos
MINI-xcv2-x388-crhm
-
minimos
MINI-xqv4-gx96-6gj5
-
minimos
MINI-xqwg-vmgf-7frh
-