[PM-7842] Fix validation of IDN emails
Type of change
- [x] Bug fix
- [ ] New feature development
- [ ] Tech debt (refactoring, code cleanup, dependency upgrades, etc)
- [ ] Build/deploy pipeline (DevOps)
- [ ] Other
Objective
Tracking the flow of emails when signing up / changing emails (i.e. [StrictEmailAddressAttribute]):
- (frontend) emails are checked using this regex: https://github.com/angular/angular/blob/17.3.6/packages/forms/src/validators.ts#L127
- (backend) check for
ParseExceptionandMimeKit.MailboxAddress.Parse(X).Address == X - (backend) check "edge cases" regex
- (backend) check
EmailAddressAttribute().IsValid(https://github.com/Microsoft/referencesource/blob/master/System.ComponentModel.DataAnnotations/DataAnnotations/EmailAddressAttribute.cs#L54)
The problem:
- doesn't allow emails in IDN form
- requires emails in IDN form
- allows emails in IDN form
- allows emails in IDN form
This PR relaxes (2) to only check for ParseExceptions, allowing IDN-emails to be specified in punycode form.
Would have been nice if MimeKit had a ParserOptions to not turn punycode into IDN-form, but that is not the case: https://github.com/jstedfast/MimeKit/blob/5a4ca6e24c8b193395ef45ea44e3e5bd3ddfa668/MimeKit/InternetAddress.cs#L447-L448
Bitwarden already have a ton of (unit-)test-cases for handling IDN, so that should already be covered.
Thank you for your contribution! We've added this to our internal Community PR board for review. ID: PM-7842
Any updates on this? Another way of fixing this bug is by changing the Angular validator to not require emails to be punycoded :shrug: