fix(email): accept SMTPUTF8 addresses (#11115)

# Which Problems Are Solved

Zitadel only accepted ASCII email addresses, while some users need to
enter internationalized addresses. For example `mö[email protected]`

# How the Problems Are Solved

- Use `net/mail` to validate email addresses, instead of a custom regex.
`net/mail` correctly accepts UTF-8 characters.
- In the management/v1 API email address validation is removed (only
string limits are applied)

# Additional Changes

- none

# Additional Context

Closes https://github.com/zitadel/zitadel/issues/9821
This commit is contained in:
Tim Möhlmann
2025-12-11 22:59:13 +00:00
committed by GitHub
parent 41cdc7805f
commit d2d85bd30e
3 changed files with 28 additions and 11 deletions
+10 -7
View File
@@ -1,8 +1,9 @@
package domain
import (
"errors"
"io"
"regexp"
"net/mail"
"strings"
"time"
@@ -11,18 +12,20 @@ import (
"github.com/zitadel/zitadel/internal/zerrors"
)
var (
emailRegex = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")
)
type EmailAddress string
var errEmailNameProvided = errors.New("email with name provided")
func (e EmailAddress) Validate() error {
if e == "" {
return zerrors.ThrowInvalidArgument(nil, "EMAIL-spblu", "Errors.User.Email.Empty")
}
if !emailRegex.MatchString(string(e)) {
return zerrors.ThrowInvalidArgument(nil, "EMAIL-599BI", "Errors.User.Email.Invalid")
p, err := mail.ParseAddress(string(e))
if err != nil {
return zerrors.ThrowInvalidArgument(err, "EMAIL-599BI", "Errors.User.Email.Invalid")
}
if p.Name != "" {
return zerrors.ThrowInvalidArgument(errEmailNameProvided, "EMAIL-599GV", "Errors.User.Email.Invalid")
}
return nil
}
+14
View File
@@ -68,6 +68,20 @@ func TestEmailValid(t *testing.T) {
},
result: true,
},
{
name: "email UTF-8, valid", // https://github.com/zitadel/zitadel/issues/9821
args: args{
email: &Email{EmailAddress: "abc@sünde.com"},
},
result: true,
},
{
name: "email with name, invalid",
args: args{
email: &Email{EmailAddress: "John Doe <[email protected]>"},
},
result: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {