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 /modules/validation/helpers.go | |
parent | 1bb9b1c4d906010c47936bf0ceba82efd1c0c014 (diff) | |
download | gitea-45976a1bdeb511d33016fdf6f906c06d995064ce.tar.gz gitea-45976a1bdeb511d33016fdf6f906c06d995064ce.zip |
Check blocklist for emails when adding them to account (#26812)
Diffstat (limited to 'modules/validation/helpers.go')
-rw-r--r-- | modules/validation/helpers.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/modules/validation/helpers.go b/modules/validation/helpers.go index 3381846b86..f6e00f3887 100644 --- a/modules/validation/helpers.go +++ b/modules/validation/helpers.go @@ -10,6 +10,8 @@ import ( "strings" "code.gitea.io/gitea/modules/setting" + + "github.com/gobwas/glob" ) var externalTrackerRegex = regexp.MustCompile(`({?)(?:user|repo|index)+?(}?)`) @@ -48,6 +50,29 @@ func IsValidSiteURL(uri string) bool { return false } +// IsEmailDomainListed checks whether the domain of an email address +// matches a list of domains +func IsEmailDomainListed(globs []glob.Glob, email string) bool { + if len(globs) == 0 { + return false + } + + n := strings.LastIndex(email, "@") + if n <= 0 { + return false + } + + domain := strings.ToLower(email[n+1:]) + + for _, g := range globs { + if g.Match(domain) { + return true + } + } + + return false +} + // 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")) |