{"record":{"id":"fee02411073db637","repo":"cloudflare/cloudflared","slug":"hostname-actually-a-url-s-has-invalid-ascii-encd","errorCode":null,"errorMessage":"Hostname(actually a URL) %s has invalid ASCII encdoing %s","messagePattern":"Hostname\\(actually a URL\\) (.+?) has invalid ASCII encdoing (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"validation/validation.go","lineNumber":45,"sourceCode":")\n\nfunc ValidateHostname(hostname string) (string, error) {\n\tif hostname == \"\" {\n\t\treturn \"\", nil\n\t}\n\t// users gives url(contains schema) not just hostname\n\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:","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/validation/validation.go#L27-L63","documentation":"For URL-shaped input, ValidateHostname extracts the host portion and converts it to ASCII via idna.ToASCII (Internationalized Domain Names). This error fires when the hostname contains characters that cannot be converted to a valid IDNA ASCII form — typically invalid Unicode, labels starting with '--' (xn-- abuse), or over-long labels.","triggerScenarios":"Calling ValidateHostname with a URL whose hostname fails idna.ToASCII, e.g. \"http://exämple--de\" style invalid labels, control characters, or an empty hostname after parsing (\"http://:8080\").","commonSituations":"Internationalized domain names with disallowed characters; typos producing empty hostnames; unicode homoglyph or mis-encoded (non-UTF8) hostnames in config files.","solutions":["Use a valid, punycode-encodable hostname (convert IDN with golang.org/x/net/idna yourself or fix the characters)","Ensure the URL actually contains a hostname (not empty before the port)","Replace non-ASCII characters that IDNA disallows (underscores in hostnames are also rejected by strict IDNA)","Pre-validate with idna.ToASCII before calling"],"exampleFix":"// before\nhostname, err := validation.ValidateHostname(\"http://exämple_.com\")\n// after: punycode the IDN first\nascii, _ := idna.ToASCII(\"exämple.com\")\nhostname, err := validation.ValidateHostname(\"http://\" + ascii)","handlingStrategy":"validation","validationCode":"func idnaSafeHost(u string) bool {\n    parsed, err := url.Parse(u)\n    if err != nil { return false }\n    _, err = idna.ToASCII(parsed.Hostname())\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 in %q cannot be IDNA-encoded; use punycode\", input)\n    }\n    return err\n}","preventionTips":["Pre-convert internationalized domains with golang.org/x/net/idna","Avoid underscores and IDNA-disallowed characters in hostnames","Ensure hostnames are valid UTF-8 and non-empty after parsing"],"tags":["hostname","idna","validation","unicode"],"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-14T00:17:10.932Z"}