diff options
author | techknowlogick <techknowlogick@gitea.io> | 2023-08-30 11:46:49 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-30 10:46:49 -0500 |
commit | 45976a1bdeb511d33016fdf6f906c06d995064ce (patch) | |
tree | 4c6976ea2d2e205c4a56e94783fa3d4f7c1ecfc8 /models | |
parent | 1bb9b1c4d906010c47936bf0ceba82efd1c0c014 (diff) | |
download | gitea-45976a1bdeb511d33016fdf6f906c06d995064ce.tar.gz gitea-45976a1bdeb511d33016fdf6f906c06d995064ce.zip |
Check blocklist for emails when adding them to account (#26812)
Diffstat (limited to 'models')
-rw-r--r-- | models/user/email_address.go | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/models/user/email_address.go b/models/user/email_address.go index e310858f92..e916249e30 100644 --- a/models/user/email_address.go +++ b/models/user/email_address.go @@ -16,6 +16,7 @@ import ( "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" + "code.gitea.io/gitea/modules/validation" "xorm.io/builder" ) @@ -161,7 +162,17 @@ func ValidateEmail(email string) error { return ErrEmailInvalid{email} } - // TODO: add an email allow/block list + // if there is no allow list, then check email against block list + if len(setting.Service.EmailDomainAllowList) == 0 && + validation.IsEmailDomainListed(setting.Service.EmailDomainBlockList, email) { + return ErrEmailInvalid{email} + } + + // if there is an allow list, then check email against allow list + if len(setting.Service.EmailDomainAllowList) > 0 && + !validation.IsEmailDomainListed(setting.Service.EmailDomainAllowList, email) { + return ErrEmailInvalid{email} + } return nil } |