{"record":{"id":"e6ddd6c51503792d","repo":"dgraph-io/dgraph","slug":"invalid-hostname-v","errorCode":null,"errorMessage":"Invalid hostname: %v","messagePattern":"Invalid hostname: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"x/x.go","lineNumber":863,"sourceCode":"\n// ValidateAddress checks whether given address can be used with grpc dial function\nfunc ValidateAddress(addr string) error {\n\thost, port, err := net.SplitHostPort(addr)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif p, err := strconv.Atoi(port); err != nil || p <= 0 || p >= 65536 {\n\t\treturn errors.Errorf(\"Invalid port: %v\", p)\n\t}\n\tif ip := net.ParseIP(host); ip != nil {\n\t\treturn nil\n\t}\n\t// try to parse as hostname as per hostname RFC\n\tif len(strings.Replace(host, \".\", \"\", -1)) > 255 {\n\t\treturn errors.Errorf(\"Hostname should be less than or equal to 255 characters\")\n\t}\n\tif !regExpHostName.MatchString(host) {\n\t\treturn errors.Errorf(\"Invalid hostname: %v\", host)\n\t}\n\treturn nil\n}\n\n// RemoveDuplicates sorts the slice of strings and removes duplicates. changes the input slice.\n// This function should be called like: someSlice = RemoveDuplicates(someSlice)\nfunc RemoveDuplicates(s []string) (out []string) {\n\tsort.Strings(s)\n\tout = s[:0]\n\tfor i := range s {\n\t\tif i > 0 && s[i] == s[i-1] {\n\t\t\tcontinue\n\t\t}\n\t\tout = append(out, s[i])\n\t}\n\treturn\n}\n","sourceCodeStart":845,"sourceCodeEnd":881,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/x/x.go#L845-L881","documentation":"The hostname fails the RFC hostname regular expression (regExpHostName). After passing the 255-length check, the string must match the legal hostname character/label rules; otherwise it is rejected as invalid.","triggerScenarios":"Passing a host with illegal characters (underscores, spaces, symbols), empty labels ('..'), leading/trailing hyphens, or an empty string to the hostname validation function.","commonSituations":"Using hostnames with '_' (common in internal configs), IPv6 without brackets pasted raw, hostnames containing ports ('host:9000') or schemes ('https://host'), or copy-paste artifacts like whitespace.","solutions":["Fix the hostname to match RFC rules: letters, digits, hyphens, dot-separated labels","Strip scheme/port from the value before validating (use url.Parse and pass u.Hostname())","Replace invalid characters like underscores with hyphens or use the IP address"],"exampleFix":"// before\nerr := ValidateHost(\"https://my_server:9000\") // invalid\n// after\nu, _ := url.Parse(\"https://my-server:9000\")\nerr := ValidateHost(u.Hostname()) // \"my-server\"","handlingStrategy":"validation","validationCode":"var hostRe = regexp.MustCompile(`^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)*$`)\nfunc validHostname(host string) bool {\n    if net.ParseIP(host) != nil { return true }\n    return hostRe.MatchString(host)\n}","typeGuard":"func looksLikeHostname(s string) bool { return s != \"\" && !strings.ContainsAny(s, \" _:/@\") }","tryCatchPattern":null,"preventionTips":["Strip scheme and port with url.Parse before storing/validating a host","Avoid underscores in hostnames even if some resolvers accept them","Trim whitespace from config values before use"],"tags":["hostname","validation","dns"],"backgroundTag":"invalid-hostname","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}