mirror of
https://github.com/gin-gonic/gin.git
synced 2026-06-07 04:38:19 +08:00
fix(context): return empty string for invalid remote IP in ClientIP method
fix(gin): unmap address before checking if it is IPv4 in prepareTrustedCIDRs
This commit is contained in:
parent
6f54838d7f
commit
9ef3ade402
@ -1022,6 +1022,9 @@ func (c *Context) ClientIP() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !remoteIP.IsValid() {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
return remoteIP.String()
|
return remoteIP.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
gin.go
2
gin.go
@ -418,7 +418,7 @@ func (engine *Engine) prepareTrustedCIDRs() ([]netip.Prefix, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return cidrs, &net.ParseError{Type: "IP address", Text: trustedProxy}
|
return cidrs, &net.ParseError{Type: "IP address", Text: trustedProxy}
|
||||||
}
|
}
|
||||||
if addr.Is4() {
|
if addr.Unmap().Is4() {
|
||||||
trustedProxy += "/32"
|
trustedProxy += "/32"
|
||||||
} else {
|
} else {
|
||||||
trustedProxy += "/128"
|
trustedProxy += "/128"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user