{"id":"f26e879139f4da0c","repo":"gofiber/fiber","slug":"domain-pattern-s-exceeds-rfc-1035-maximum-of-25","errorCode":null,"errorMessage":"Domain pattern '%s' exceeds RFC 1035 maximum of 253 characters (%d chars)","messagePattern":"Domain pattern '(.+?)' exceeds RFC 1035 maximum of 253 characters \\((.+?) chars\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"domain.go","lineNumber":68,"sourceCode":"// parseDomainPattern parses a domain pattern like \":subdomain.example.com\"\n// into a domainMatcher. Parameter parts start with \":\".\n// Constant labels are lowercased per RFC 4343 (domain names are case-insensitive),\n// but parameter names are preserved as-is so that DomainParam lookups work with\n// the exact names the caller used (e.g., \":User\" → param name \"User\").\nfunc parseDomainPattern(pattern string) domainMatcher {\n\tpattern = utils.TrimSpace(pattern)\n\t// Trim trailing dot of a fully-qualified domain name (RFC 3986),\n\t// consistent with Fiber's own host normalization in Subdomains().\n\tpattern = utils.TrimRight(pattern, '.')\n\n\t// Validate pattern is not empty after trimming\n\tif pattern == \"\" {\n\t\tpanic(\"Domain pattern cannot be empty\")\n\t}\n\n\t// Enforce RFC 1035 total length limit on patterns\n\tif len(pattern) > 253 {\n\t\tpanic(fmt.Sprintf(\"Domain pattern '%s' exceeds RFC 1035 maximum of 253 characters (%d chars)\",\n\t\t\tpattern, len(pattern)))\n\t}\n\n\tparts := strings.Split(pattern, \".\")\n\n\t// Prevent DoS from patterns with excessive label counts\n\tif len(parts) > maxDomainParts {\n\t\tpanic(fmt.Sprintf(\"Domain pattern '%s' has %d parts, which exceeds the maximum of %d\",\n\t\t\tpattern, len(parts), maxDomainParts))\n\t}\n\n\tm := domainMatcher{\n\t\tparts:    make([]string, len(parts)),\n\t\tnumParts: len(parts),\n\t}\n\n\tfor i, part := range parts {\n\t\t// Validate no empty labels (e.g., \"example..com\" is invalid)","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/gofiber/fiber/blob/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/domain.go#L50-L86","documentation":"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.","triggerScenarios":"app.Domain(veryLongString) where the string is built by concatenating many labels or comes from untrusted/config input longer than 253 chars.","commonSituations":"A pattern accidentally constructed by joining a large slice; copy-paste of a full certificate Subject Alternative Name list; misconfigured wildcard generator.","solutions":["Shorten the pattern to a real hostname under 253 chars.","Validate len(pattern) <= 253 before calling Domain().","If the long string encodes multiple hosts, split and register each separately."],"exampleFix":"// before\napp.Domain(strings.Join(allLabels, \".\")).Get(\"/\", h) // > 253\n\n// after\nhost := strings.Join(allLabels, \".\")\nif len(host) > 253 {\n    return fmt.Errorf(\"domain pattern too long: %d\", len(host))\n}\napp.Domain(host).Get(\"/\", h)","handlingStrategy":"validation","validationCode":"if len(pattern) > 253 {\n    return fmt.Errorf(\"domain pattern exceeds 253 chars\")\n}\napp.Domain(pattern).Get(\"/\", h)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Cap generated domain patterns at 253 chars.","Split overlong multi-host strings into separate Domain() calls.","Log pattern length when constructing from dynamic input."],"tags":["routing","domain","validation","rfc-1035","panic"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}