Merge 41a41597662ddd5f2a4963108aa72d9da2a6cc6b into ef68fa032c0e6ce637db56e89ec734c0de0a9f5e

This commit is contained in:
Trygun 2025-05-15 09:13:41 +02:00 committed by GitHub
commit 2d31750788
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

11
gin.go
View File

@ -478,17 +478,20 @@ func (engine *Engine) validateHeader(header string) (clientIP string, valid bool
for i := len(items) - 1; i >= 0; i-- {
ipStr := strings.TrimSpace(items[i])
ip := net.ParseIP(ipStr)
valid = true
if ip == nil {
break
ipStr = ""
valid = false
}
// X-Forwarded-For is appended by proxy
// Check IPs in reverse order and stop when find untrusted proxy
if (i == 0) || (!engine.isTrustedProxy(ip)) {
return ipStr, true
if valid && (!engine.isTrustedProxy(ip)) {
return ipStr, valid
}
}
return "", false
return "", valid
}
// updateRouteTree do update to the route tree recursively