1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2025-10-15 19:42:04 +00:00

fix: email comments are removed from email addresses (#9074)

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9074
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Reviewed-by: 0ko <0ko@noreply.codeberg.org>
This commit is contained in:
Earl Warren 2025-08-30 13:15:30 +02:00
commit 1b13fda06b
9 changed files with 99 additions and 21 deletions

View file

@ -72,16 +72,23 @@ func validateEmailBasic(email string) error {
}
func validateEmailDomain(email string) error {
if !IsEmailDomainAllowed(email) {
if _, ok := IsEmailDomainAllowed(email); !ok {
return ErrEmailInvalid{email}
}
return nil
}
func IsEmailDomainAllowed(email string) bool {
return isEmailDomainAllowedInternal(
email,
func IsEmailDomainAllowed(email string) (validEmail, ok 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, false
}
return true, isEmailDomainAllowedInternal(
parsedAddress.Address,
setting.Service.EmailDomainAllowList,
setting.Service.EmailDomainBlockList)
}

View file

@ -67,8 +67,3 @@ func TestEmailAddressValidate(t *testing.T) {
})
}
}
func TestEmailDomainAllowList(t *testing.T) {
res := IsEmailDomainAllowed("someuser@localhost.localdomain")
assert.True(t, res)
}