mirror of
https://github.com/gin-gonic/gin.git
synced 2025-04-25 11:06:48 +08:00
Merge 41a41597662ddd5f2a4963108aa72d9da2a6cc6b into 8763f33c65f7df8be5b9fe7504ab7fcf20abb41d
This commit is contained in:
commit
0f4ea91679
11
gin.go
11
gin.go
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user