gofiber/fiber · error

Domain pattern ' ' exceeds RFC 1035 maximum of 253…

Error message

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

What it means

parseDomainPattern enforces the RFC 1035 total length limit (253 octets, leaving room for the root label) on domain patterns. Patterns longer than 253 characters are rejected at registration to keep DNS semantics valid. The pattern length counts after trimming whitespace and the trailing dot.

Solutions

  1. Shorten the pattern to <= 253 characters; split routing across multiple Domain routes if needed.
  2. Validate length before registering: if len(pattern) > 253 { return error }.
  3. Reduce label count or use shorter parameter names.

Example fix

// before
app.Domain(strings.Repeat("sub.", 60) + "example.com")

// after
app.Domain("sub.example.com")  // collapse redundant labels
Defensive patterns

Strategy: validation

Validate before calling

const maxDomainPattern = 253

func validateDomainLength(p string) error {
    if len(p) > maxDomainPattern {
        return fmt.Errorf("domain pattern too long: %d > %d", len(p), maxDomainPattern)
    }
    return nil
}

Prevention

When it happens

Trigger: Passing a domain pattern (possibly with parameter labels like :tenant) whose total character count exceeds 253.

Common situations: Dynamically composing a long pattern from many subdomains; copy-pasting a wildcard chain; templating that concatenates without length checks; typo producing a huge pattern.

Related errors


AI-assisted analysis of gofiber/fiber@a105acad6c (2026-08-11). Data as JSON: /api/errors/f26e879139f4da0c. Report an issue: GitHub.

Appendix: 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 a105acad6c)