diff --git a/models/user/email_address.go b/models/user/email_address.go index 8c6f24e57b..f1089ccc99 100644 --- a/models/user/email_address.go +++ b/models/user/email_address.go @@ -498,5 +498,5 @@ func IsEmailDomainAllowed(email string) bool { return !validation.IsEmailDomainListed(setting.Service.EmailDomainBlockList, email) } - return validation.IsEmailDomainListed(setting.Service.EmailDomainAllowList, email) + return validation.IsEmailDomainListed(setting.Service.EmailDomainAllowList, email) || validation.IsLocalEmailDomain(email) } diff --git a/modules/validation/helpers.go b/modules/validation/helpers.go index 567ad867fe..978bd4024e 100644 --- a/modules/validation/helpers.go +++ b/modules/validation/helpers.go @@ -73,6 +73,17 @@ func IsEmailDomainListed(globs []glob.Glob, email string) bool { return false } +func IsLocalEmailDomain(email string) bool { + localFqdn, err := url.ParseRequestURI(setting.AppURL) + if err != nil { + return false + } + + mailDomain := strings.Split(email, "@")[1] + + return mailDomain == localFqdn.Hostname() +} + // IsAPIURL checks if URL is current Gitea instance API URL func IsAPIURL(uri string) bool { return strings.HasPrefix(strings.ToLower(uri), strings.ToLower(setting.AppURL+"api"))