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

API should guard against invalid email addresses #109

Open
AaronSofaer opened this issue Jan 7, 2016 · 4 comments
Open

API should guard against invalid email addresses #109

AaronSofaer opened this issue Jan 7, 2016 · 4 comments
Labels

Comments

@AaronSofaer
Copy link

Any email address with unicode characters that aren't the standard ASCII English set are not really valid email addresses. The API should return 400 with an Invalid Email Address code when a client attempts to create a user by POSTing to /users.

@AaronSofaer AaronSofaer added the bug label Jan 7, 2016
@christopherstyles
Copy link

The email address should already be getting validated, using the email_validator gem. This happens somewhat obscurely by the included Clearance::User model. See clearance/user.rb#L144-L148.

Also, when testing locally, I do get a 422 response with an Email is invalid error code:

Request:

curl -X "POST" "http://api.lvh.me:5000/users" \
    -H "Content-Type: application/json" \
    -d "{\"data\":{\"attributes\":{\"email\":\"test\\[email protected]\",\"password\":\"testing123\",\"first_name\":\"test\",\"last_name\":\"test\",\"state_code\":\"NY\"}}}"

Response:

HTTP/1.1 422 Unprocessable Entity
Date: Thu, 11 Feb 2016 19:15:54 GMT
Status: 422 Unprocessable Entity
# snip…
{
  "errors": [
    {
      "detail": "Email is invalid",
      "id": "VALIDATION_ERROR",
      "status": 422,
      "title": "Email error"
    }
  ]
}

Any chance you can provide me with a way to reproduce the issue you’re seeing?

@AaronSofaer
Copy link
Author

@christopherstyles I used an accented character in the email address, if I remember right. That or a ligature'd AE.

@christopherstyles
Copy link

@AaronSofaer I’m no expert on this, but after some diving it seems that RFC 2822 (which outlined valid addresses as being solely US-ASCII) was obsoleted by RFC 6531. Utf-8 characters are acceptable to smtp servers that support the SMTPUTF8 extension.

Some of the characters that would invalidate the local part of an email address can be found in this chart…things like # or <space> or !. Those will return an error from the API.

@AaronSofaer
Copy link
Author

@christopherstyles RFCs are nice and all, but services like Mailgun will choke on those addresses, often quite loudly/with side effects. But I'm not exactly married to this bug; it was just something I noticed in my initial pokings. :)

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

No branches or pull requests

2 participants