server icon indicating copy to clipboard operation
server copied to clipboard

[PM-7842] Fix validation of IDN emails

Open NicolaiSoeborg opened this issue 1 year ago • 3 comments

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]):

  1. (frontend) emails are checked using this regex: https://github.com/angular/angular/blob/17.3.6/packages/forms/src/validators.ts#L127
  2. (backend) check for ParseException and MimeKit.MailboxAddress.Parse(X).Address == X
  3. (backend) check "edge cases" regex
  4. (backend) check EmailAddressAttribute().IsValid (https://github.com/Microsoft/referencesource/blob/master/System.ComponentModel.DataAnnotations/DataAnnotations/EmailAddressAttribute.cs#L54)

The problem:

  1. doesn't allow emails in IDN form
  2. requires emails in IDN form
  3. allows emails in IDN form
  4. 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.

NicolaiSoeborg avatar Apr 30 '24 22:04 NicolaiSoeborg

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Apr 30 '24 22:04 CLAassistant

Thank you for your contribution! We've added this to our internal Community PR board for review. ID: PM-7842

bitwarden-bot avatar Apr 30 '24 22:04 bitwarden-bot

Any updates on this? Another way of fixing this bug is by changing the Angular validator to not require emails to be punycoded :shrug:

NicolaiSoeborg avatar May 22 '24 18:05 NicolaiSoeborg