{"record":{"id":"8d06c379522ebaf0","repo":"valyala/fasthttp","slug":"invalid-ipv6-address","errorCode":null,"errorMessage":"invalid ipv6 address","messagePattern":"invalid ipv6 address","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ipv6.go","lineNumber":11,"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}\n\t\taddr = addr[:zi]","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/valyala/fasthttp/blob/c96f600972c6f4a7a30d664257b340ebe9d60124/ipv6.go#L1-L29","documentation":"After host/zone checks pass, validateIPv6Literal validates the actual IPv6 address bytes inside the brackets. errInvalidIPv6Address is returned when the address itself cannot be parsed — wrong number of groups, invalid hex digits, bad embedded IPv4, or misplaced '::'.","triggerScenarios":"Setting a host such as '[zz::1]', '[1:2:3]' (too few groups, no ::), '[::1::2]' (multiple '::'), or '[1.2.3.4]' through URI parsing / SetHost paths.","commonSituations":"Typos when hardcoding IPv6 endpoints in config; interpolating variables into host strings; DNS returning unexpected literals that code blindly brackets before passing to fasthttp.","solutions":["Correct the address syntax (validate with net.ParseIP after stripping brackets before use).","Resolve hostnames to IPs and format with net.IP.String() wrapped in brackets instead of hand-writing addresses.","Use URI.Parse with a full URL and handle the error to catch malformed literals early."],"exampleFix":"// before\nreq.Header.SetHost(\"[1:2:3]\") // invalid ipv6 address\n// after\nip := net.ParseIP(\"fd00::1\")\nreq.Header.SetHost(\"[\" + ip.String() + \"]\") // \"[fd00::1]\"","handlingStrategy":"validation","validationCode":"func validIPv6Addr(host string) bool {\n    inner := strings.TrimSuffix(strings.TrimPrefix(host, \"[\"), \"]\")\n    if i := strings.IndexByte(inner, '%'); i >= 0 {\n        inner = inner[:i]\n    }\n    ip := net.ParseIP(inner)\n    return ip != nil && strings.Contains(inner, \":\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Generate host strings via net.IP.String() rather than by hand.","Run net.ParseIP on configured IPv6 endpoints at startup and fail fast."],"tags":["ipv6","uri","address-validation"],"backgroundTag":"invalid-ipv6-literal","analyzedSha":"c96f600972c6f4a7a30d664257b340ebe9d60124","analyzedAt":"2026-08-31T22:48:28.265Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}