Trim whitespace from user-supplied passwords and emails - #927
Open
iamtanuj18 wants to merge 9 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #915.
Password and email fields on register, login, reset, and admin edit paths accept leading and trailing whitespace without trimming. Registering with
" Constellation2026!"succeeds but a subsequent login with the clean version fails because the stored hash includes the space. Same shape on the email side, with duplicate users created against padded and clean variants of the same email, andgenerate-reset-linksilently dropping the outbound reset email when the requestor's address is padded.Chrome auto-trims
type=emailbefore submit so the UI looked fine, but anything hitting the API directly (Swagger, curl, Postman, CSV/RedCap import) surfaces the bug. This PR trims at the input boundary in every handler and form.Backend
Password:
AuthController.registerUser/registerInitialUser/registerParticipant/login,UsersController.resetPassword,utils/createAdmin.ts(env var + trimmed truthy guard),prisma/seed/seed.tsenv vars.Email: same auth handlers plus
UsersController.createUser/updateUser/generatePasswordResetLink,ProfilesController.updateCurrentProfile/updateProfileById(user email + next of kin email),IntegrationsController.processParticipantData(CSV/RedCap loop),AuthController.loginOIDC(provider userinfo before lookup) andcreateParticipant(next of kin), pluscreateAdmin.tsandseed.tsenv vars.Frontend
Password:
Register.tsx,Login.tsx,ResetPassword.tsxon user-client;setup/index.tsx,password/update.tsxresolver,authProvider.tslogin + updatePassword on admin-client.Email:
Register.tsx,Login.tsx,ForgotPassword.tsx,ProfileEdit.tsx(own NoK email) on user-client;setup/index.tsx,authProvider.tslogin + forgotPassword,pages/users/create.tsx,users/edit.tsx(customhandleSubmitintercept because these use Refine'suseForm),pages/participants/edit.tsx(user email + NoK email) on admin-client.Tests
Auth.test.tscovers leading/trailing/all-whitespace password on participant register, admin register-then-login round-trip, duplicate detection for padded and clean variants of the same email, and next of kin email stored trimmed.ResetPassword.test.tscovers reset-then-login with padded newPassword, andgenerate-reset-linkwith padded email actually sending the reset email.registration.cy.jsadds Cypress e2e for password and email round-trip through the register + login UI.Scope
Per Slack with @ignatiusm:
ParticipantsController.createInvites,admin-client/components/InviteModal.tsx, andemailHashnormalisation inschema.prismaare covered by open PR Store emails in lowercase #888. Its.trim().toLowerCase()handles whitespace on the invite path.@patternannotations incommon/types/api/**will be handled in the validate user input work tracked in Validate user-supplied input in participant and admin portals #891.