valyala/fasthttp · error
invalid ipv6 host
Error message
invalid ipv6 host
What it means
validateIPv6Literal rejects an IPv6 host literal that is not properly bracketed or is otherwise structurally invalid. errInvalidIPv6Host is returned when the host starts with '[' (IPv6 literal form) but the bracketed host fails basic host-level validation.
Source
Thrown at ipv6.go:9
package fasthttp
import (
"bytes"
"errors"
)
var (
errInvalidIPv6Host = errors.New("invalid ipv6 host")
errInvalidIPv6Zone = errors.New("invalid ipv6 zone")
errInvalidIPv6Address = errors.New("invalid ipv6 address")
)
func validateIPv6Literal(host []byte) error {
if len(host) == 0 || host[0] != '[' {
return nil
}
end := bytes.IndexByte(host, ']')
if end < 0 || end == 1 {
return errInvalidIPv6Host
}
addr := host[1:end]
// Optional zone.
if zi := bytes.IndexByte(addr, '%'); zi >= 0 {
if zi == len(addr)-1 {
return errInvalidIPv6ZoneView on GitHub (pinned to c96f600972)
Solutions
- Wrap IPv6 hosts in brackets including the closing one: use host '[::1]' not '::1' or '[::1'.
- Use uri.SetHost / URI.SetHost or URI.Parse with a full URL (http://[::1]:8080/) so fasthttp validates for you.
- Sanitize/normalize the Host header before forwarding if you are a proxy.
Example fix
// before
req.SetRequestURI("http://[::1]:8080/") // ok, but hand-built host below is not
req.Header.SetHost("[::1") // invalid ipv6 host
// after
req.Header.SetHost("[::1]") Defensive patterns
Strategy: validation
Validate before calling
func validIPv6Literal(host string) bool {
if !strings.HasPrefix(host, "[") || !strings.HasSuffix(host, "]") || len(host) < 4 {
return false
}
inner := host[1 : len(host)-1]
if i := strings.IndexByte(inner, '%'); i >= 0 {
inner = inner[:i]
}
return net.ParseIP(inner) != nil
} Prevention
- Always bracket IPv6 hosts including the closing ']'.
- Use URI.Parse with absolute URLs instead of manual host assembly.
- Validate Host headers at proxy boundaries.
When it happens
Trigger: Calling URI host parsing/normalization (e.g. uri.parseHost, Host normalization paths) with a Host header or request URI host like '[::1' (missing closing bracket) or '[]'.
Common situations: Hand-crafted Host headers missing a closing bracket; proxies forwarding mangled Host values; constructing URIs by string concatenation and forgetting brackets around IPv6 addresses.
Related errors
- invalid ipv6 zone
- invalid ipv6 address
- invalid port %q after host
- too many host headers
- missing required host header in request
AI-assisted analysis of valyala/fasthttp@c96f600972 (2026-08-31).
Data as JSON: /api/errors/39142bad3086dbf3.
Report an issue: GitHub.