{"record":{"id":"7ddcc9cedb595d25","repo":"cloudflare/cloudflared","slug":"hostname-s-has-invalid-ascii-encdoing-s","errorCode":null,"errorMessage":"Hostname %s has invalid ASCII encdoing %s","messagePattern":"Hostname (.+?) has invalid ASCII encdoing (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"validation/validation.go","lineNumber":52,"sourceCode":"\tif strings.Contains(hostname, \":\") || strings.Contains(hostname, \"%3A\") {\n\t\tunescapeHostname, err := url.PathUnescape(hostname)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"Hostname(actually a URL) %s has invalid escape characters %s\", hostname, unescapeHostname)\n\t\t}\n\t\thostnameToURL, err := url.Parse(unescapeHostname)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"Hostname(actually a URL) %s has invalid format %s\", hostname, hostnameToURL)\n\t\t}\n\t\tasciiHostname, err := idna.ToASCII(hostnameToURL.Hostname())\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"Hostname(actually a URL) %s has invalid ASCII encdoing %s\", hostname, asciiHostname)\n\t\t}\n\t\treturn asciiHostname, nil\n\t}\n\n\tasciiHostname, err := idna.ToASCII(hostname)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"Hostname %s has invalid ASCII encdoing %s\", hostname, asciiHostname)\n\t}\n\thostnameToURL, err := url.Parse(asciiHostname)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"Hostname %s is not valid\", hostnameToURL)\n\t}\n\treturn hostnameToURL.RequestURI(), nil\n\n}\n\n// ValidateUrl returns a validated version of `originUrl` with a scheme prepended (by default http://).\n// Note: when originUrl contains a scheme, the path is removed:\n//\n//\tValidateUrl(\"https://localhost:8080/api/\") => \"https://localhost:8080\"\n//\n// but when it does not, the path is preserved:\n//\n//\tValidateUrl(\"localhost:8080/api/\") => \"http://localhost:8080/api/\"\n//","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/validation/validation.go#L34-L70","documentation":"For plain (non-URL) hostname input, ValidateHostname converts the hostname to ASCII via idna.ToASCII. This error is returned when the bare hostname fails IDNA conversion — invalid characters, bad label structure, or non-encodable Unicode.","triggerScenarios":"Calling ValidateHostname with a hostname without ':' that idna.ToASCII rejects — e.g. \"my_host\" (underscore), \"-bad-.example.com\" (leading/trailing hyphen), a label over 63 characters, or non-UTF8 bytes.","commonSituations":"Config files with hostnames containing underscores (common internal-DNS habit that IDNA rejects); typos like double dots or stray dashes; hostnames pasted with hidden unicode characters.","solutions":["Use a valid RFC hostname: letters, digits, hyphens only, no leading/trailing hyphens, labels ≤ 63 chars","Replace underscores with hyphens or use the IP address directly","Pre-validate with idna.ToASCII(hostname) before calling","Strip hidden/zero-width unicode characters from the input"],"exampleFix":"// before\nhostname, err := validation.ValidateHostname(\"my_server.example.com\")\n// after\nhostname, err := validation.ValidateHostname(\"my-server.example.com\")","handlingStrategy":"validation","validationCode":"func validHostname(h string) bool {\n    if h == \"\" { return false }\n    _, err := idna.ToASCII(h)\n    return err == nil\n}","typeGuard":null,"tryCatchPattern":"host, err := validation.ValidateHostname(input)\nif err != nil {\n    if strings.Contains(err.Error(), \"invalid ASCII\") {\n        return fmt.Errorf(\"hostname %q is not IDNA-encodable; use letters, digits, hyphens\", input)\n    }\n    return err\n}","preventionTips":["Use only letters, digits, hyphens and dots in hostnames","Replace underscores (common in internal DNS) with hyphens","Check label lengths (≤63) and avoid leading/trailing hyphens"],"tags":["hostname","idna","validation"],"backgroundTag":"invalid-url-format","analyzedSha":"2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f","analyzedAt":"2026-09-06T04:14:33.757Z","contentChangedAt":"2026-09-06T04:14:33.757Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}