Skip to content

Commit ee846ad

Browse files
authored
fix: enhance IP address validation to include global unicast check for IPv4 and IPv6 (#3084)
Signed-off-by: redscholar <blacktiledhouse@gmail.com>
1 parent 139931f commit ee846ad

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

pkg/variable/variable_get.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ var GetAllVariable = func(hostname string) GetFunc {
9090

9191
for _, addr := range addrs {
9292
if ipNet, ok := addr.(*net.IPNet); ok && !ipNet.IP.IsLoopback() {
93-
if ipType == _const.VariableIPv4 && ipNet.IP.To4() != nil {
93+
if ipType == _const.VariableIPv4 && ipNet.IP.To4() != nil && ipNet.IP.IsGlobalUnicast() {
9494
return ipNet.IP.String()
9595
}
9696

97-
if ipType == _const.VariableIPv6 && ipNet.IP.To16() != nil && ipNet.IP.To4() == nil {
97+
if ipType == _const.VariableIPv6 && ipNet.IP.To4() == nil && ipNet.IP.IsGlobalUnicast() {
9898
return ipNet.IP.String()
9999
}
100100
}

0 commit comments

Comments
 (0)