Skip to content
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

govalidator.IsExistingEmail() Function Can Cause GitHub Primary Email Address Validation Issue #25

Open
czqu opened this issue Apr 21, 2023 · 1 comment

Comments

@czqu
Copy link

czqu commented Apr 21, 2023

The ValidateEmail function provided below utilizes the govalidator.IsExistingEmail() function to validate email addresses. However, using this function can cause issues with the validation of GitHub Primary email addresses, such as "[email protected]". This is because the govalidator.IsExistingEmail() function attempts to verify if the domain can be reached, by performing a check using the net.LookupMX(host) and net.LookupIP(host) functions.

This domain verification check can fail for certain email addresses that are valid, such as the aforementioned GitHub Primary email address. This is because the "users.noreply.github.com" domain cannot be resolved using the net.LookupIP(host) function. As a result, using the govalidator.IsExistingEmail() function in this context may lead to false negatives and result in valid email addresses being rejected.

func ValidateEmail(email string, modified bool) error {
   if modified && email == "" {
      return nil
   }

   if !govalidator.IsExistingEmail(email) {
      return ErrInvalidEmail
   }
   return nil
}
func IsExistingEmail(email string) bool {

	if len(email) < 6 || len(email) > 254 {
		return false
	}
	at := strings.LastIndex(email, "@")
	if at <= 0 || at > len(email)-3 {
		return false
	}
	user := email[:at]
	host := email[at+1:]
	if len(user) > 64 {
		return false
	}
	switch host {
	case "localhost", "example.com":
		return true
	}
	if userDotRegexp.MatchString(user) || !userRegexp.MatchString(user) || !hostRegexp.MatchString(host) {
		return false
	}
	if _, err := net.LookupMX(host); err != nil {
		if _, err := net.LookupIP(host); err != nil {
			return false
		}
	}

	return true
}
@matsuyoshi30
Copy link
Owner

@czqu Thank you for reporting! I think it is enough to use mail.ParseAddress.

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

2 participants