You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Key: '' Error:Field validation for '' failed on the 'ipv6' tag
Key: '' Error:Field validation for '' failed on the 'ipv6' tag
Key: '' Error:Field validation for '' failed on the 'ip6_addr' tag
Key: '' Error:Field validation for '' failed on the 'ip6_addr' tag
I checked the source code, for ipv6 tag the root cause is when we check a valid ip is IPv4 or IPv6, we used the To4() function in net package:
// isIPv6 is the validation function for validating if the field's value is a valid v6 IP address.funcisIPv6(flFieldLevel) bool {
ip:=net.ParseIP(fl.Field().String())
returnip!=nil&&ip.To4() ==nil
}
but in net package, it automatically covert the IPv4 mapped IPv6 address to IPv4, so the To4() function return value will not be nil, which make the isIPv6 return false. But I think this is not expected.
func (ipIP) To4() IP {
iflen(ip) ==IPv4len {
returnip
}
// covert the IPv4 mapped IPv6 address to IPv4 such as ::ffff:192.168.1.1 to 192.168.1.1iflen(ip) ==IPv6len&&isZeros(ip[0:10]) &&ip[10] ==0xff&&ip[11] ==0xff {
returnip[12:16]
}
returnnil
}
we can simply fix this by check the raw ip string's format, for ipv4 it only can contains ".", for ipv6 it must contains ":" and it can optional contains "."(dot is for IPv4 mapped IPv6 address) but cannot only contains ".".
and corresponding issue also happens in ipv4 tag and ip4_addr tag, the the IPv4 mapped IPv6 address can successfully pass by the ipv4 validation.
Package version eg. v9, v10:
v10.14.0
Issue, Question or Enhancement:
Unable to verify the IPv4 mapped IPv6 address
Code sample, to showcase or reproduce:
I checked the source code, for
ipv6
tag the root cause is when we check a valid ip is IPv4 or IPv6, we used the To4() function in net package:but in net package, it automatically covert the IPv4 mapped IPv6 address to IPv4, so the To4() function return value will not be nil, which make the
isIPv6
return false. But I think this is not expected.we can simply fix this by check the raw ip string's format, for ipv4 it only can contains ".", for ipv6 it must contains ":" and it can optional contains "."(dot is for IPv4 mapped IPv6 address) but cannot only contains ".".
and corresponding issue also happens in
ipv4
tag andip4_addr
tag, the the IPv4 mapped IPv6 address can successfully pass by the ipv4 validation.submit a pull request to simply fix this: #1312 please review it,
Please take care of this, thanks.
The text was updated successfully, but these errors were encountered: