mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 19:06:18 +01:00 
			
		
		
		
	Check blocklist for emails when adding them to account (#26812)
This commit is contained in:
		| @@ -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")) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user