From 45976a1bdeb511d33016fdf6f906c06d995064ce Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Wed, 30 Aug 2023 11:46:49 -0400 Subject: Check blocklist for emails when adding them to account (#26812) --- modules/validation/helpers.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'modules/validation/helpers.go') 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")) -- cgit v1.2.3