Skip to content

Email address validation is too strict #1419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
xenomote opened this issue Mar 5, 2025 · 0 comments
Open

Email address validation is too strict #1419

xenomote opened this issue Mar 5, 2025 · 0 comments

Comments

@xenomote
Copy link

xenomote commented Mar 5, 2025

if the "local part" of an email address is quoted, it may contain any number of @s, white-space characters and non printable unicode characters. Those three checks should be removed from the checkEmail String validation function to prevent erroneously rejecting compliant (although admittedly very weird) email addresses:

ogen/validate/string.go

Lines 63 to 99 in 8aafb42

func (t String) checkEmail(v string) error {
// Pretty basic validation, but should work for most cases and is not
// too strict to break things.
//
// Still better than obscure regex or std `mail.ParseAddress`.
var (
gotAt bool
last rune
)
for i, r := range v {
if unicode.IsSpace(r) {
return errors.Errorf("space character (%U)", r)
}
if !unicode.IsPrint(r) {
return errors.Errorf("not printable character (%U)", r)
}
last = r
if r != '@' {
continue
}
if gotAt {
return errors.New(`got @ multiple times`)
}
if i == 0 {
return errors.New(`got @ at start`)
}
gotAt = true
}
if last == '@' {
return errors.New("@ at end")
}
if !gotAt {
return errors.New(`no @`)
}
return nil
}

additionally, you can theoretically introduce a min/max length validation according to https://www.rfc-editor.org/errata/eid1003, though that may be covered by explicitly setting minLength and maxLength

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant