Skip to content

Commit 4457dd5

Browse files
committed
Enforce bracket notation for IPv6 bootstrap resolvers
The isIPAndPort validation function was accepting ambiguous IPv6 addresses without brackets (e.g., "2606:4700:4700::1113:53"). The ExtractHostAndPort function would treat the last colon as a port separator, incorrectly splitting the IPv6 address. This fix enforces that IPv6 addresses must use bracket notation (e.g., "[2606:4700:4700::1113]:53") to prevent ambiguity and ensure correct parsing.
1 parent e9f8f55 commit 4457dd5

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

dnscrypt-proxy/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,11 @@ func isIPAndPort(addrStr string) error {
774774
return fmt.Errorf("Port missing '%s'", addrStr)
775775
} else if _, err := strconv.ParseUint(strconv.Itoa(port), 10, 16); err != nil {
776776
return fmt.Errorf("Port does not parse '%s' [%v]", addrStr, err)
777+
} else if ip.To4() == nil {
778+
// IPv6 address must use bracket notation to avoid ambiguity
779+
if !strings.HasPrefix(host, "[") || !strings.HasSuffix(host, "]") {
780+
return fmt.Errorf("IPv6 addresses must use bracket notation, e.g., [%s]:%d", ip.String(), port)
781+
}
777782
}
778783
return nil
779784
}

0 commit comments

Comments
 (0)