Skip to content

Trim whitespace from user-supplied passwords and emails - #927

Open
iamtanuj18 wants to merge 9 commits into
devfrom
915-trim-password-whitespace
Open

Trim whitespace from user-supplied passwords and emails#927
iamtanuj18 wants to merge 9 commits into
devfrom
915-trim-password-whitespace

Conversation

@iamtanuj18

Copy link
Copy Markdown

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, and generate-reset-link silently dropping the outbound reset email when the requestor's address is padded.

Chrome auto-trims type=email before 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.ts env 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) and createParticipant (next of kin), plus createAdmin.ts and seed.ts env vars.

Frontend

Password: Register.tsx, Login.tsx, ResetPassword.tsx on user-client; setup/index.tsx, password/update.tsx resolver, authProvider.ts login + updatePassword on admin-client.

Email: Register.tsx, Login.tsx, ForgotPassword.tsx, ProfileEdit.tsx (own NoK email) on user-client; setup/index.tsx, authProvider.ts login + forgotPassword, pages/users/create.tsx, users/edit.tsx (custom handleSubmit intercept because these use Refine's useForm), pages/participants/edit.tsx (user email + NoK email) on admin-client.

Tests

  • Auth.test.ts covers 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.ts covers reset-then-login with padded newPassword, and generate-reset-link with padded email actually sending the reset email.
  • registration.cy.js adds Cypress e2e for password and email round-trip through the register + login UI.

Scope

Per Slack with @ignatiusm:

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