Merge c93194e6be33533ae7ef9367a94581be9fbcd0de into 0f09c3a9b4626d9fe9979cf4d0521d6ae32ab646

This commit is contained in:
water 2026-10-13 02:03:43 -07:00 committed by GitHub
commit adc19dd39e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

8
gin.go
View File

@ -509,7 +509,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
}