mirror of
https://github.com/tailscale/tailscale.git
synced 2025-12-06 04:42:42 +00:00
cmd/tailscale: extend hostname validation (#7678)
In addition to checking the total hostname length, validate characters used in each DNS label and label length. Updates https://github.com/tailscale/corp/issues/10012 Signed-off-by: Anton Tolchanov <anton@tailscale.com>
This commit is contained in:
@@ -214,6 +214,21 @@ func FirstLabel(hostname string) string {
|
||||
return first
|
||||
}
|
||||
|
||||
// ValidHostname checks if a string is a valid hostname.
|
||||
func ValidHostname(hostname string) error {
|
||||
fqdn, err := ToFQDN(hostname)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, label := range strings.Split(fqdn.WithoutTrailingDot(), ".") {
|
||||
if err := ValidLabel(label); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var separators = map[byte]bool{
|
||||
' ': true,
|
||||
'.': true,
|
||||
|
||||
Reference in New Issue
Block a user