{"record":{"id":"e1d5fea7e086c699","repo":"valyala/fasthttp","slug":"invalid-ipv6-zone","errorCode":null,"errorMessage":"invalid ipv6 zone","messagePattern":"invalid ipv6 zone","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ipv6.go","lineNumber":10,"sourceCode":"package fasthttp\n\nimport (\n\t\"bytes\"\n\t\"errors\"\n)\n\nvar (\n\terrInvalidIPv6Host    = errors.New(\"invalid ipv6 host\")\n\terrInvalidIPv6Zone    = errors.New(\"invalid ipv6 zone\")\n\terrInvalidIPv6Address = errors.New(\"invalid ipv6 address\")\n)\n\nfunc validateIPv6Literal(host []byte) error {\n\tif len(host) == 0 || host[0] != '[' {\n\t\treturn nil\n\t}\n\tend := bytes.IndexByte(host, ']')\n\tif end < 0 || end == 1 {\n\t\treturn errInvalidIPv6Host\n\t}\n\taddr := host[1:end]\n\n\t// Optional zone.\n\tif zi := bytes.IndexByte(addr, '%'); zi >= 0 {\n\t\tif zi == len(addr)-1 {\n\t\t\treturn errInvalidIPv6Zone\n\t\t}","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/valyala/fasthttp/blob/c96f600972c6f4a7a30d664257b340ebe9d60124/ipv6.go#L1-L28","documentation":"When parsing a bracketed IPv6 literal host, fasthttp validates the zone part (the %zone suffix inside the brackets, e.g. [fe80::1%eth0]). errInvalidIPv6Zone is returned if the zone identifier is malformed — empty zone, invalid characters, or trailing garbage after the zone.","triggerScenarios":"Setting a host like '[fe80::1%]' (empty zone), '[fe80::1%zone]extra', or with invalid zone characters through URI host parsing / SetHost / validateIPv6Literal.","commonSituations":"Building link-local URIs with zone identifiers by hand; copying scoped addresses from OS output (e.g. 'fe80::1%en0') and pasting them into URIs incorrectly; proxies forwarding zone-qualified hosts.","solutions":["Provide a valid, non-empty zone inside the brackets: '[fe80::1%eth0]'.","Drop the zone if it is not needed (most HTTP usages: use '[fe80::1]').","Parse the full URL with fasthttp's URI.Parse instead of manual host assembly so errors point at the exact problem."],"exampleFix":"// before\nu := &fasthttp.URI{}\nu.Parse(nil, []byte(\"http://[fe80::1%]/\")) // invalid ipv6 zone\n// after\nu := &fasthttp.URI{}\nu.Parse(nil, []byte(\"http://[fe80::1%eth0]/\"))","handlingStrategy":"validation","validationCode":"func validZone(host string) bool {\n    if !strings.HasSuffix(host, \"]\") || !strings.Contains(host, \"%\") {\n        return strings.HasSuffix(host, \"]\")\n    }\n    inner := strings.TrimSuffix(strings.TrimPrefix(host, \"[\"), \"]\")\n    i := strings.IndexByte(inner, '%')\n    return i > 0 && i < len(inner)-1 && !strings.Contains(inner[i+1:], \"]\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Strip zone identifiers unless link-local addressing is required.","Never paste OS-scoped addresses (host%if) directly into URIs without bracketing and checking."],"tags":["ipv6","uri","zone-id"],"backgroundTag":"invalid-ipv6-literal","analyzedSha":"c96f600972c6f4a7a30d664257b340ebe9d60124","analyzedAt":"2026-08-31T22:48:28.265Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}