mirror of
https://github.com/gin-gonic/gin.git
synced 2025-05-22 12:19:16 +08:00
Merge 41a41597662ddd5f2a4963108aa72d9da2a6cc6b into ef68fa032c0e6ce637db56e89ec734c0de0a9f5e
This commit is contained in:
commit
2d31750788
11
gin.go
11
gin.go
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user