{"record":{"id":"b44e47b2d32cfbef","repo":"XTLS/Xray-core","slug":"invalid-host-host","errorCode":null,"errorMessage":"invalid host + host","messagePattern":"invalid host \\+ host","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"infra/conf/transport_finalmask.go","lineNumber":845,"sourceCode":"\tvar tlsConfig *tls.Config\n\n\tu, err := url.Parse(c.Url)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tswitch u.Scheme {\n\tcase \"realm\":\n\t\tscheme = \"https\"\n\tcase \"realm+http\":\n\t\tscheme = \"http\"\n\tdefault:\n\t\treturn nil, errors.New(\"invalid scheme\", u.Scheme)\n\t}\n\n\thost = u.Hostname()\n\tif host == \"\" {\n\t\treturn nil, errors.New(\"invalid host\", host)\n\t}\n\n\tport = u.Port()\n\tif port == \"\" {\n\t\tport = \"443\"\n\t\tif scheme == \"http\" {\n\t\t\tport = \"80\"\n\t\t}\n\t}\n\n\ttoken, err = url.PathUnescape(u.User.String())\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif token == \"\" {\n\t\treturn nil, errors.New(\"invalid token\", token)\n\t}\n","sourceCodeStart":827,"sourceCodeEnd":863,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/infra/conf/transport_finalmask.go#L827-L863","documentation":"Thrown by Realm.Build() when the parsed Realm URL has an empty host component. After scheme validation, u.Hostname() must yield a non-empty value; a URL like 'realm:///path' (no authority) fails here. The host is a required part of the Realm endpoint address.","triggerScenarios":"Passing 'realm:///id' (missing authority), a URL whose host is only userinfo ('realm://token@/id'), or a value that lost its host during string concatenation/template interpolation.","commonSituations":"Environment-variable substitution producing an empty host; hand-built URL strings with a double '//' after the scheme; copying a share link and deleting the hostname.","solutions":["Include an explicit host: 'realm://token@host:port/id'.","Log or echo the final URL string before running the core to catch empty substitutions.","Validate the URL with net/url in a pre-flight check (see defense)."],"exampleFix":"// before\n\"url\": \"realm://mytoken@/v1\"\n// after\n\"url\": \"realm://mytoken@signal.example.com:8443/v1\"","handlingStrategy":"validation","validationCode":"u, _ := url.Parse(raw)\nif u.Hostname() == \"\" {\n    return fmt.Errorf(\"realm url is missing a host\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Assert non-empty hostname after env-var/template substitution.","Build Realm URLs from parts (scheme, userinfo, host, port, path) instead of string concatenation.","Lint config files for 'realm:///' patterns missing the authority."],"tags":["go","xray","config","validation","url-parsing"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}