gofiber/fiber · error

Domain pattern '%s' exceeds RFC 1035 maximum of 253 characte

Error message

Domain pattern '%s' exceeds RFC 1035 maximum of 253 characters (%d chars)

What it means

Panics from domain.go:68 when the domain pattern exceeds 253 characters, the RFC 1035 maximum total length for a domain name. This guard rejects absurdly long patterns that would never match a real host and protects the matcher from wasteful allocation.

Source

Thrown at domain.go:68

// parseDomainPattern parses a domain pattern like ":subdomain.example.com"
// into a domainMatcher. Parameter parts start with ":".
// Constant labels are lowercased per RFC 4343 (domain names are case-insensitive),
// but parameter names are preserved as-is so that DomainParam lookups work with
// the exact names the caller used (e.g., ":User" → param name "User").
func parseDomainPattern(pattern string) domainMatcher {
	pattern = utils.TrimSpace(pattern)
	// Trim trailing dot of a fully-qualified domain name (RFC 3986),
	// 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)

View on GitHub (pinned to 9a4c7e57fe)

Solutions

  1. Shorten the pattern to a real hostname under 253 chars.
  2. Validate len(pattern) <= 253 before calling Domain().
  3. If the long string encodes multiple hosts, split and register each separately.

Example fix

// before
app.Domain(strings.Join(allLabels, ".")).Get("/", h) // > 253

// after
host := strings.Join(allLabels, ".")
if len(host) > 253 {
    return fmt.Errorf("domain pattern too long: %d", len(host))
}
app.Domain(host).Get("/", h)
Defensive patterns

Strategy: validation

Validate before calling

if len(pattern) > 253 {
    return fmt.Errorf("domain pattern exceeds 253 chars")
}
app.Domain(pattern).Get("/", h)

Prevention

When it happens

Trigger: app.Domain(veryLongString) where the string is built by concatenating many labels or comes from untrusted/config input longer than 253 chars.

Common situations: A pattern accidentally constructed by joining a large slice; copy-paste of a full certificate Subject Alternative Name list; misconfigured wildcard generator.

Related errors


AI-assisted analysis of gofiber/fiber@9a4c7e57fe (2026-08-04). Data as JSON: /data/errors/f26e879139f4da0c.json. Report an issue: GitHub.