{"record":{"id":"cd4c32f14413ea2c","repo":"netbirdio/netbird","slug":"invalid-dns-address-s","errorCode":null,"errorMessage":"invalid DNS address: %s","messagePattern":"invalid DNS address: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/android/dns_list.go","lineNumber":19,"sourceCode":"package android\n\nimport (\n\t\"fmt\"\n\t\"net/netip\"\n\n\t\"github.com/netbirdio/netbird/client/internal/dns\"\n)\n\n// DNSList is a wrapper of []netip.AddrPort with default DNS port\ntype DNSList struct {\n\titems []netip.AddrPort\n}\n\n// Add new DNS address to the collection, returns error if invalid\nfunc (array *DNSList) Add(s string) error {\n\taddr, err := netip.ParseAddr(s)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"invalid DNS address: %s\", s)\n\t}\n\taddrPort := netip.AddrPortFrom(addr.Unmap(), dns.DefaultPort)\n\tarray.items = append(array.items, addrPort)\n\treturn nil\n}\n\n// Get return an element of the collection as string\nfunc (array *DNSList) Get(i int) (string, error) {\n\tif i >= len(array.items) || i < 0 {\n\t\treturn \"\", fmt.Errorf(\"out of range\")\n\t}\n\treturn array.items[i].Addr().String(), nil\n}\n\n// Size return with the size of the collection\nfunc (array *DNSList) Size() int {\n\treturn len(array.items)\n}","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/netbirdio/netbird/blob/93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c/client/android/dns_list.go#L1-L37","documentation":"DNSList.Add parses its argument with netip.ParseAddr, which accepts only bare IP literals. Anything else (hostname, URL, address:port, CIDR) fails and returns this error; on success the address is Unmap()ed and stored with dns.DefaultPort (53). Note the underlying ParseAddr error is discarded, so the message carries only the offending string.","triggerScenarios":"Passing \"dns.google\" or \"one.one.one.one\" (hostnames); \"1.1.1.1:53\" (port included); \"10.0.0.0/8\" (CIDR); or a malformed IPv6 literal to DNSList.Add.","commonSituations":"Users typing DNS provider names into a mobile UI; feeding a config value that contains host:port; copying a CIDR from a route config into a DNS field.","solutions":["Pass a plain IP literal: \"1.1.1.1\" or \"2001:4860:4860::8888\".","Resolve hostnames to IPs in app code before calling Add.","Validate input in the UI with netip.ParseAddr and reject or resolve it before it reaches DNSList."],"exampleFix":"// before\nerr := dnsList.Add(\"dns.google\")\n\n// after\nerr := dnsList.Add(\"8.8.8.8\")","handlingStrategy":"validation","validationCode":"// Validate before adding to the DNS list\nfunc validDNSAddr(s string) bool {\n    addr, err := netip.ParseAddr(s)\n    return err == nil && addr.IsValid()\n}","typeGuard":"func isInvalidDNSAddress(err error) bool {\n    return err != nil && strings.HasPrefix(err.Error(), \"invalid DNS address:\")\n}","tryCatchPattern":"if err := dnsList.Add(input); err != nil {\n    if isInvalidDNSAddress(err) {\n        // show the user which value was rejected and prompt for a bare IP literal\n        return fmt.Errorf(\"enter an IP address like 1.1.1.1, not a hostname\")\n    }\n    return err\n}","preventionTips":["Accept only IP literals in DNS input fields; resolve hostnames in app code before adding.","Strip accidental host:port or CIDR notation before validation.","Run netip.ParseAddr in the UI layer for instant feedback instead of waiting for Add."],"tags":["android","dns","validation","ip-address"],"backgroundTag":null,"analyzedSha":"93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c","analyzedAt":"2026-08-16T03:09:19.136Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}