Skip to content

Change validation rules for profile email addresses

Max Woolf requested to merge 215919-email-validation into master

What does this MR do?

Short version: This MR changes the validation logic for email addresses being added to a user's profile to be less permissive than Devise's default.


Currently email addresses inside the profile feature are validated using DeviseEmailValidator which as a subclass of ActiveModel::EachValidator allows us to use the nice syntactic sugar:

validates :email, devise_email: true

However, the Devise regular expression, which this class uses, permits some email addresses that it should not permit and which are rejected by some SMTP servers (including the one in use by GitLab.com, causing 500s.)

It was proposed that we use a more robust validator to pick up a particular case (and perhaps others).

Specifically, it was possible to enter an email address in which a period existed either at the start or directly before the @ despite not being a valid URL. (Example: test.@example.com or .test@example.com)

Additionally, the error mentioned in the associated issue was also triggered in a couple of the other examples of email addresses where the test cases affirmed their validity.

Gotchas

Due to there already being an EmailValidator class which was defined by a dependency of an OpenID gem, this MR is unable to use validates :email, email: true. By using an instance method, we can be certain the correct class is being called despite a slight trade-off in readability. (I'd be keen on feedback about this, or ways it could be improved)

Screenshots

Screenshot_2020-04-28_at_16.11.27

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team

Closes #215919 (closed)

Edited by Max Woolf

Merge request reports

Loading