gofiber/fiber · error

Domain pattern '%s' has label '%s' exceeding RFC 1035 limit

Error message

Domain pattern '%s' has label '%s' exceeding RFC 1035 limit of 63 characters (%d chars)

What it means

Panics from domain.go:112 when a constant (non-parameter) label exceeds the RFC 1035 per-label limit of 63 characters. Long labels are not matchable by any real DNS name and signal a malformed or adversarial pattern.

Source

Thrown at domain.go:112

				panic(fmt.Sprintf("Domain pattern '%s' contains empty parameter name at position %d", pattern, i))
			}
			paramName := part[1:]
			// Validate parameter name contains only ASCII-safe characters (a-z, A-Z, 0-9, underscore, hyphen).
			// Using explicit ASCII ranges rather than unicode.IsLetter/IsDigit to reject non-ASCII
			// characters that are invalid in DNS names.
			for _, ch := range paramName {
				if !isASCIIAlphanumeric(ch) && ch != '_' && ch != '-' {
					panic(fmt.Sprintf("Domain pattern '%s' contains invalid parameter name '%s' with character '%c'", pattern, paramName, ch))
				}
			}
			m.paramIdx = append(m.paramIdx, i)
			m.paramNames = append(m.paramNames, paramName) // preserve original case
			m.parts[i] = part                              // keep ":param" marker for matching
		} else {
			// Only lowercase constant labels (RFC 4343)
			// Enforce RFC 1035 per-label length limit (63 characters)
			if len(part) > 63 {
				panic(fmt.Sprintf("Domain pattern '%s' has label '%s' exceeding RFC 1035 limit of 63 characters (%d chars)",
					pattern, part, len(part)))
			}
			// Validate label contains only valid ASCII domain characters (a-z, 0-9, hyphen).
			normalized := utilsstrings.ToLower(part)
			for _, ch := range normalized {
				if !isASCIIAlphanumeric(ch) && ch != '-' {
					panic(fmt.Sprintf("Domain pattern '%s' contains invalid character '%c' in label '%s'", pattern, ch, part))
				}
			}
			m.parts[i] = normalized
		}
	}

	// Check if the domain pattern has too many parameters
	if len(m.paramNames) > maxParams {
		panic(fmt.Sprintf("Domain pattern '%s' has %d parameters, which exceeds the maximum of %d",
			pattern, len(m.paramNames), maxParams))
	}

View on GitHub (pinned to 9a4c7e57fe)

Solutions

  1. Keep constant labels at or under 63 characters.
  2. Validate each label's length before registering the domain route.
  3. Move overlong identifiers into path segments or headers instead of the hostname.

Example fix

// before
label := base64.RawURLEncoding.EncodeToString(blob) // > 63
app.Domain(label + ".example.com").Get("/", h)

// after
label := shorten(blob) // ensure <= 63 chars
if len(label) > 63 {
    return fmt.Errorf("label too long")
}
app.Domain(label + ".example.com").Get("/", h)
Defensive patterns

Strategy: validation

Validate before calling

for _, label := range strings.Split(pattern, ".") {
    if !strings.HasPrefix(label, ":") && len(label) > 63 {
        return fmt.Errorf("domain label exceeds 63 chars: %s", label)
    }
}
app.Domain(pattern).Get("/", h)

Prevention

When it happens

Trigger: app.Domain("<64+chars>.example.com"); a single label built by padding or concatenation that crosses 63 chars.

Common situations: Hashes, base64 blobs, or IDs used as a domain label; generated patterns with unbounded label length; test fixtures.

Related errors


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