This commit is contained in:
griffer 2026-01-22 08:52:26 +00:00 committed by GitHub
commit dc198f06b8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 8 deletions

View file

@ -585,17 +585,25 @@ func (node *Node) ApplyHostnameFromHostInfo(hostInfo *tailcfg.Hostinfo) {
return
}
newHostname := strings.ToLower(hostInfo.Hostname)
if err := util.ValidateHostname(newHostname); err != nil {
newHostname, err := util.NormaliseHostname(hostInfo.Hostname)
if err != nil {
log.Warn().
Str("node.id", node.ID.String()).
Str("current_hostname", node.Hostname).
Str("rejected_hostname", hostInfo.Hostname).
Str("original_hostname", hostInfo.Hostname).
Err(err).
Msg("Rejecting invalid hostname update from hostinfo")
Msg("Hostname normalization failed, keeping current hostname")
return
}
if hostInfo.Hostname != newHostname {
log.Info().
Str("node.id", node.ID.String()).
Str("original", hostInfo.Hostname).
Str("sanitized", newHostname).
Msg("Hostname sanitized during update")
}
if node.Hostname != newHostname {
log.Trace().
Str("node.id", node.ID.String()).

View file

@ -287,12 +287,12 @@ func EnsureHostname(hostinfo *tailcfg.Hostinfo, machineKey, nodeKey string) stri
return fmt.Sprintf("node-%s", keyPrefix)
}
lowercased := strings.ToLower(hostinfo.Hostname)
if err := ValidateHostname(lowercased); err == nil {
return lowercased
normalized, err := NormaliseHostname(hostinfo.Hostname)
if err != nil {
return InvalidString()
}
return InvalidString()
return normalized
}
// GenerateRegistrationKey generates a vanity key for tracking web authentication