Merge c93194e6be33533ae7ef9367a94581be9fbcd0de into dcaa4296d111981ffb31ac3eba90bb63e1eb5ab9

This commit is contained in:
water 2026-08-19 23:09:58 -07:00 committed by GitHub
commit 4520c2b9bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

8
gin.go
View File

@ -486,7 +486,13 @@ func (engine *Engine) validateHeader(header string) (clientIP string, valid bool
items := strings.Split(header, ",")
for i := len(items) - 1; i >= 0; i-- {
ipStr := strings.TrimSpace(items[i])
ip := net.ParseIP(ipStr)
// Handle formats like "[::1]:port", "1.2.3.4:port", and "[::1]"
host, _, err := net.SplitHostPort(ipStr)
if err != nil {
// No port present; strip brackets if present (e.g. "[::1]")
host = strings.Trim(ipStr, "[]")
}
ip := net.ParseIP(host)
if ip == nil {
break
}