mirror of https://github.com/gin-gonic/gin.git
fix bug in validateHeader
This commit is contained in:
parent
a889c58de7
commit
41a4159766
11
gin.go
11
gin.go
|
@ -463,17 +463,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
|
||||
}
|
||||
|
||||
// parseIP parse a string representation of an IP and returns a net.IP with the
|
||||
|
|
Loading…
Reference in New Issue