{"record":{"id":"f92e02cdb88b61f6","repo":"Billionmail/BillionMail","slug":"hostname-format-is-incorrect","errorCode":null,"errorMessage":"hostname format is incorrect","messagePattern":"hostname format is incorrect","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/internal/controller/settings/settings.go","lineNumber":208,"sourceCode":"\tswitch key {\n\tcase \"ADMIN_USERNAME\", \"admin_username\":\n\t\t// Admin username: allowed letters, numbers, underscores, length 4-32\n\t\tif len(value) < 4 || len(value) > 32 {\n\t\t\treturn fmt.Errorf(\"admin username length must be between 4-32\")\n\t\t}\n\t\tif !public.IsValidUsername(value) {\n\t\t\treturn fmt.Errorf(\"admin username can only contain letters, numbers and underscores\")\n\t\t}\n\n\tcase \"ADMIN_PASSWORD\", \"admin_password\":\n\t\tif len(value) < 4 {\n\t\t\treturn fmt.Errorf(\"password length must be at least 4 characters\")\n\t\t}\n\n\tcase \"BILLIONMAIL_HOSTNAME\", \"billionmail_hostname\":\n\t\t// Hostname: allowed letters, numbers, dots, hyphens\n\t\tif !public.IsValidHostname(value) {\n\t\t\treturn fmt.Errorf(\"hostname format is incorrect\")\n\t\t}\n\n\tcase \"SMTP_PORT\", \"SMTPS_PORT\", \"SUBMISSION_PORT\", \"IMAP_PORT\", \"IMAPS_PORT\", \"POP_PORT\", \"POPS_PORT\", \"HTTP_PORT\", \"HTTPS_PORT\", \"REDIS_PORT\",\n\t\t\"smtp\", \"smtps\", \"submission\", \"imap\", \"imaps\", \"pop\", \"pops\", \"http\", \"https\", \"redis_port\":\n\t\t// Port: 1-65535\n\t\tport := public.ParseInt(value)\n\t\tif port < 1 || port > 65535 {\n\t\t\treturn fmt.Errorf(\"port must be between 1-65535\")\n\t\t}\n\n\tcase \"IPV4_NETWORK\", \"ipv4_network\":\n\t\t// IPv4 network: CIDR format\n\t\tif !public.IsValidCIDR(value) {\n\t\t\treturn fmt.Errorf(\"IPv4 network format is incorrect, please use CIDR format (e.g. 192.168.1.0/24)\")\n\t\t}\n\n\tcase \"TZ\", \"timezone\":\n\t\t// Timezone: check if it is a valid timezone","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/controller/settings/settings.go#L190-L226","documentation":"validateConfigValue in the settings controller rejects a value for the BILLIONMAIL_HOSTNAME config key when public.IsValidHostname fails. Hostnames are written to mail infrastructure config (Postfix/Dovecot) and must contain only letters, numbers, dots and hyphens; anything else would break downstream service configuration. The error is returned from SetSystemConfig/SetSystemConfigKey before the value is persisted.","triggerScenarios":"Calling SetSystemConfig or SetSystemConfigKey with BILLIONMAIL_HOSTNAME (or billionmail_hostname) set to a value containing underscores, spaces, slashes, protocol prefixes (http://), trailing dots, or other characters outside [A-Za-z0-9.-].","commonSituations":"Admins paste a URL like 'https://mail.example.com' instead of the bare hostname, or use underscore names like 'mail_server' (valid in some DNS setups but rejected here), or include a port ('mail.example.com:25').","solutions":["Use a bare FQDN hostname containing only letters, numbers, dots and hyphens, e.g. mail.example.com","Strip scheme and port: 'https://mail.example.com:25' → 'mail.example.com'","Replace underscores with hyphens if the machine name contains them","Verify with the same regex the validator uses before calling the API"],"exampleFix":"// before\nkey: BILLIONMAIL_HOSTNAME, value: https://mail.example.com\n// after\nkey: BILLIONMAIL_HOSTNAME, value: mail.example.com","handlingStrategy":"validation","validationCode":"const hostRe = /^[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?(?:\\.[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?)*$/;\nif (!hostRe.test(hostname)) throw new Error('hostname format is incorrect');","typeGuard":"function isValidHostname(v: string): boolean {\n  return /^[A-Za-z0-9.-]+$/.test(v) && !v.includes('..') && v.length <= 253;\n}","tryCatchPattern":"try {\n  await api.setSystemConfigKey('BILLIONMAIL_HOSTNAME', hostname);\n} catch (e) {\n  if (String(e.message).includes('hostname format')) {\n    notify('Hostname may only contain letters, numbers, dots and hyphens');\n  } else throw e;\n}","preventionTips":["Strip scheme (http://) and port before sending a hostname","Never use underscores in hostnames","Trim whitespace and quotes from clipboard input","Validate with the same regex client-side before calling the API"],"tags":["validation","config","hostname"],"backgroundTag":"invalid-hostname-format","analyzedSha":"fc36c76c050c3775c5e899faf7403cf0262d2744","analyzedAt":"2026-09-05T21:28:54.019Z","contentChangedAt":"2026-09-05T21:28:54.019Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}