{"record":{"id":"506403464627fbe7","repo":"cloudflare/cloudflared","slug":"url-should-not-be-empty","errorCode":null,"errorMessage":"URL should not be empty","messagePattern":"URL should not be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"validation/validation.go","lineNumber":82,"sourceCode":"//\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//\n// This is arguably a bug, but changing it might break some cloudflared users.\nfunc ValidateUrl(originUrl string) (*url.URL, error) {\n\turlStr, err := validateUrlString(originUrl)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn url.Parse(urlStr)\n}\n\nfunc validateUrlString(originUrl string) (string, error) {\n\tif originUrl == \"\" {\n\t\treturn \"\", fmt.Errorf(\"URL should not be empty\")\n\t}\n\n\tif net.ParseIP(originUrl) != nil {\n\t\treturn validateIP(\"\", originUrl, \"\")\n\t} else if strings.HasPrefix(originUrl, \"[\") && strings.HasSuffix(originUrl, \"]\") {\n\t\t// ParseIP doesn't recoginze [::1]\n\t\treturn validateIP(\"\", originUrl[1:len(originUrl)-1], \"\")\n\t}\n\n\thost, port, err := net.SplitHostPort(originUrl)\n\t// user might pass in an ip address like 127.0.0.1\n\tif err == nil && net.ParseIP(host) != nil {\n\t\treturn validateIP(\"\", host, port)\n\t}\n\n\tunescapedUrl, err := url.PathUnescape(originUrl)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"URL %s has invalid escape characters %s\", originUrl, unescapedUrl)","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/validation/validation.go#L64-L100","documentation":"validateUrlString is the internal normalizer behind ValidateUrl and NewAccessValidator; it rejects an empty origin URL up front because no scheme/host can be derived from an empty string. The library requires a non-empty URL string to validate and prepend a default scheme to.","triggerScenarios":"Calling ValidateUrl(\"\") or NewAccessValidator with an empty domain or issuer string — typically an unset config value or environment variable for the origin/issuer URL.","commonSituations":"Config file missing the origin/ingress service value; empty environment variable substituted into the URL field; YAML/JSON config key present but with an empty value; programmatic callers passing an empty string default.","solutions":["Provide a non-empty origin URL, e.g. --url http://localhost:8080 or service: http://localhost:8080 in config","Check the config file/env var feeding the value is actually set and non-empty before calling","Add an early guard in your code that skips/errs on empty URLs with a clearer message","If the value may legitimately be absent, check for emptiness before invoking ValidateUrl"],"exampleFix":"// before\nu, err := validation.ValidateUrl(os.Getenv(\"ORIGIN_URL\")) // empty env var\n// after\norigin := os.Getenv(\"ORIGIN_URL\")\nif origin == \"\" {\n    return nil, errors.New(\"ORIGIN_URL is not set\")\n}\nu, err := validation.ValidateUrl(origin)","handlingStrategy":"validation","validationCode":"func nonEmptyURL(s string) bool { return strings.TrimSpace(s) != \"\" }","typeGuard":null,"tryCatchPattern":"u, err := validation.ValidateUrl(origin)\nif err != nil {\n    if err.Error() == \"URL should not be empty\" {\n        return nil, fmt.Errorf(\"origin URL is required; set the --url flag or service config\")\n    }\n    return nil, err\n}","preventionTips":["Check that config fields/env vars feeding URLs are set and non-empty before calling","Use required-field checks when loading tunnel configuration files","Provide explicit defaults (e.g. http://localhost:8080) instead of empty strings"],"tags":["url","validation","empty-input","config"],"backgroundTag":"empty-required-field","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"}