Files
member-console/internal/server/validate.go
Christian Galo 47a75e0873 Add products, entitlement sets, and workspace support
- Add SQL queries and generated methods for Create/List/Update products
- Add CountWorkspacesByOrgID and ListResourceKeys querier methods
- Register workspace partials and operator routes for products and sets
- Add workspace UI section and operator tabs; tweak grant/site forms
- Replace isValidDNSLabel with validateDNSLabel for site validation
2026-03-27 10:55:03 -05:00

47 lines
1.7 KiB
Go

package server
import (
"fmt"
"regexp"
)
// validDNSLabel enforces the DNS label rules from RFC 1035 §2.3.1
// (as amended by RFC 1123 §2.1): lowercase alphanumeric, may contain
// hyphens in the middle, must start and end with a letter or number.
// 1-63 chars.
//
// Callers must normalize input with strings.ToLower before calling
// isValidDNSLabel, as this pattern only matches lowercase.
var validDNSLabel = regexp.MustCompile(`^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$`)
// isValidDNSLabel reports whether name is a valid DNS label.
func isValidDNSLabel(name string) bool {
return validDNSLabel.MatchString(name)
}
// validateDNSLabel validates a DNS label and returns a user-facing error
// message, or "" if the label is valid. It checks length before pattern
// to provide specific error messages per RFC 1035 §2.3.1.
func validateDNSLabel(name string) string {
if len(name) > 63 {
return "Site name exceeds the 63-character limit"
}
if !validDNSLabel.MatchString(name) {
return "Site name may only contain lowercase letters, numbers, and hyphens, and must start and end with a letter or number"
}
return ""
}
// validateFQDN checks that the assembled FQDN (label + "." + farmDomain)
// does not exceed 253 characters per RFC 1035 §2.3.4. Returns a user-facing
// error message, or "" if valid. The 63-char label limit already prevents
// overflow for any reasonable farm domain; this is a defense-in-depth measure.
func validateFQDN(label, farmDomain string) string {
// FQDN = label + "." + farmDomain
fqdnLen := len(label) + 1 + len(farmDomain)
if fqdnLen > 253 {
return fmt.Sprintf("The full domain name (%s.%s) exceeds the 253-character limit", label, farmDomain)
}
return ""
}