fix: properly validate email containing comments

Originally reported by jomo (https://jomo.tv). A malicious actor could
register with an email address containing a comment, for example
"attacker@evil (comment@broken)". This commit fixes this issue by only
operating on normalized email addresses.

Signed-off-by: famfo <famfo@famfo.xyz>
This commit is contained in:
famfo 2025-08-23 01:57:20 +02:00 committed by Earl Warren
commit cf1fda81f6
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00

View file

@ -80,8 +80,15 @@ func validateEmailDomain(email string) error {
}
func IsEmailDomainAllowed(email string) bool {
// Normalized the address. This strips for example comments which could be
// used to smuggle a different domain
parsedAddress, err := mail.ParseAddress(email)
if err != nil {
return false
}
return isEmailDomainAllowedInternal(
email,
parsedAddress.Address,
setting.Service.EmailDomainAllowList,
setting.Service.EmailDomainBlockList)
}