Add validation for wildcard server names

This commit is contained in:
Manuel Alejandro de Brito Fontes 2020-10-19 19:40:06 -03:00
parent cdd6437380
commit d74ea25df8
3 changed files with 35 additions and 1 deletions

View file

@ -182,6 +182,7 @@ var (
"buildMirrorLocations": buildMirrorLocations,
"shouldLoadAuthDigestModule": shouldLoadAuthDigestModule,
"shouldLoadInfluxDBModule": shouldLoadInfluxDBModule,
"buildServerName": buildServerName,
}
)
@ -1459,3 +1460,15 @@ func shouldLoadInfluxDBModule(s interface{}) bool {
return false
}
// buildServerName ensures wildcard hostnames are valid
func buildServerName(hostname string) string {
if !strings.HasPrefix(hostname, "*") {
return hostname
}
hostname = strings.Replace(hostname, "*.", "", 1)
parts := strings.Split(hostname, ".")
return `~^(?<subdomain>[\w-]+)\.` + strings.Join(parts, "\\.") + `$`
}