Skip to content

Store emails in lowercase#888

Open
ignatiusm wants to merge 7 commits into
devfrom
825-store-emails-lowercase
Open

Store emails in lowercase#888
ignatiusm wants to merge 7 commits into
devfrom
825-store-emails-lowercase

Conversation

@ignatiusm

@ignatiusm ignatiusm commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Resolves #825 and resolves #542

Context

This PR has a bit of a strange origin story:

Last year, I was doing some testing and was able to create separate accounts for: joe@test.com; Joe@test.com; and joe@Test.com: #542 At some part of the app there was a search for duplicate emails, and given I was was able to create separate accounts I figured the duplicate email search should be case sensitive (backed up by some stackoverflow answers on a related question - it turns out the spec for emails is not very specific).

However, when we were getting CTRL Pen tested I encountered an issue of incompatibility with Auth0's behaviour of saving emails as lowercase: #825

On the basis of this we decided to also store emails as lowercase in CTRL. Emails are encypted at rest (using the prisma-field-encryption library. There is also an emailHash field to stores a hash of the email to allow for index creation and unique checks: e.g. CREATE UNIQUE INDEX "User_emailHash_key" ON "User"("emailHash");

Tests and code fixes

AuthController

  • application/backend/src/controllers/AuthController.test.ts to check that registering an admin fails with emailHash already in use when an existing admin exists with an uppercase version of the email. Evidence of failing Auth test:
image
  • Key code fix is in application/backend/prisma/schema.prisma to normalise the User emailHash, but an explanatory note is also included in application/backend/src/controllers/AuthController.ts

ParticipantsController

  • application/backend/src/controllers/ParticipantsController.test.ts to check that when creating a batch of invites, emails with different cases do not result in two separate invites.

  • Key fixes are in:

    • application/backend/src/controllers/ParticipantsController.ts to normalise email to lowercase when creating Invites for participants
    • application/backend/prisma/schema.prisma to normalise the Invites emailHash

Admin-portal invite Modal

  • application/admin-client/cypress/e2e/invites.cy.js test to ensure that only lowercase emails are added to recipients list by typing and pasting.

  • application/admin-client/src/components/InviteModal.tsx I did a bit of a refactor to simplify and clarify the logic for adding by typing vs adding by pasting and carve out some helper functions.

Note: if you do not make clean then yarn dev and make seed then you may encounter errors due to prisma schema changes. You might need to run yarn prisma:generate to recreate the prisma client.

I also created another issue (#890) to add invites for dev and test users. Without invites there is a chance for weird states to exist (e.g. a users should have an 'Accepted' invite) and we probably need tests for them!

@ignatiusm ignatiusm changed the title Adds AuthController test for email case sensitivity Store email in lowercase Jul 22, 2026
@ignatiusm ignatiusm changed the title Store email in lowercase Store emails in lowercase Jul 22, 2026
@ignatiusm
ignatiusm requested a review from plouka13 July 23, 2026 02:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant