Merge 41a41597662ddd5f2a4963108aa72d9da2a6cc6b into 8763f33c65f7df8be5b9fe7504ab7fcf20abb41d

This commit is contained in:
Trygun 2025-03-23 09:37:07 +08:00 committed by GitHub
commit 0f4ea91679
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

11
gin.go
View File

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