gofiber/fiber · error
Domain pattern '%s' has %d parts, which exceeds the maximum
Error message
Domain pattern '%s' has %d parts, which exceeds the maximum of %d
What it means
Panics from domain.go:76 when the pattern splits into more than maxDomainParts (16) dot-separated labels. The 16-label cap is a deliberate DoS guard below RFC 1035's 127-label theoretical max, preventing memory exhaustion from pathological patterns.
Source
Thrown at domain.go:76
// consistent with Fiber's own host normalization in Subdomains().
pattern = utils.TrimRight(pattern, '.')
// Validate pattern is not empty after trimming
if pattern == "" {
panic("Domain pattern cannot be empty")
}
// Enforce RFC 1035 total length limit on patterns
if len(pattern) > 253 {
panic(fmt.Sprintf("Domain pattern '%s' exceeds RFC 1035 maximum of 253 characters (%d chars)",
pattern, len(pattern)))
}
parts := strings.Split(pattern, ".")
// Prevent DoS from patterns with excessive label counts
if len(parts) > maxDomainParts {
panic(fmt.Sprintf("Domain pattern '%s' has %d parts, which exceeds the maximum of %d",
pattern, len(parts), maxDomainParts))
}
m := domainMatcher{
parts: make([]string, len(parts)),
numParts: len(parts),
}
for i, part := range parts {
// Validate no empty labels (e.g., "example..com" is invalid)
if part == "" {
panic(fmt.Sprintf("Domain pattern '%s' contains empty label at position %d", pattern, i))
}
if part[0] == ':' {
// Validate parameter name is not empty
if len(part) == 1 {
panic(fmt.Sprintf("Domain pattern '%s' contains empty parameter name at position %d", pattern, i))View on GitHub (pinned to 9a4c7e57fe)
Solutions
- Reduce the pattern to 16 or fewer labels.
- Validate len(strings.Split(pattern, ".")) <= 16 before calling Domain().
- Rearchitect over-deep tenant schemes to use fewer subdomain levels or path-based routing.
Example fix
// before
app.Domain(genDeepDomain(n)).Get("/", h) // n > 16
// after
pat := genDeepDomain(n)
if len(strings.Split(pat, ".")) > 16 {
return fmt.Errorf("domain pattern has too many labels")
}
app.Domain(pat).Get("/", h) Defensive patterns
Strategy: validation
Validate before calling
if len(strings.Split(pattern, ".")) > 16 {
return fmt.Errorf("domain pattern exceeds 16 labels")
}
app.Domain(pattern).Get("/", h) Prevention
- Bound the depth of generated subdomain patterns.
- Reject over-deep tenant schemes at config load.
- Prefer path-based routing for unbounded variability.
When it happens
Trigger: app.Domain("a.b.c.d....") with more than 16 labels; a pattern built by repeating ".x" in a loop; deeply nested generated subdomains.
Common situations: Generated wildcard/tenant patterns with unbounded depth; malformed input fed from a database column; test fixtures with artificially deep domains.
Related errors
- Domain pattern cannot be empty
- Domain pattern '%s' exceeds RFC 1035 maximum of 253 characte
- Domain pattern '%s' contains empty label at position %d
- Domain pattern '%s' contains empty parameter name at positio
- Domain pattern '%s' contains invalid parameter name '%s' wit
AI-assisted analysis of gofiber/fiber@9a4c7e57fe (2026-08-04).
Data as JSON: /data/errors/fc980bccbcebcf02.json.
Report an issue: GitHub.