Change validation rules for profile email addresses
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
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry -
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
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)