fix: build the password reset link without path.join and encode the email [T-2539]
Merged
EV
6d ago+55+55+01234567890123456789-4-4-0123456789
What was wrong
api/src/services/mail.service.ts:88built the reset link withjoin(config.virtualHost, 'reset-password').path.joincollapses the//, sohttps://t.example.combecamehttps:/t.example.com/reset-password(on Windows hosts it even became.\http:\localhost:8080\reset-password). Mail clients usually do not turn that into a link.api/src/templates/mail/password-reset-token.txt:7printed{{endpoint}}?email={{user.email}}&resetToken={{resetToken}}: the email was not URL-encoded, and{{ }}HTML-escapes it. Forjane+tr@example.comthe reset page (webapp/src/app/auth/components/reset-password/reset-password.component.ts:18and47-49, a disabled field filled fromqueryParams.email) receivedjane tr@example.com,ResetPasswordRequest.email(@IsEmail(),api/src/domain/http.ts:621-624) answered 400, and the user could not correct the field, so they could not reset their password. An email with'became'inside the link, which breaks the query string.
What changed
- New
passwordResetUrl(email, token)inapi/src/utils/password-reset-url.ts:${config.virtualHost}/reset-password?email=${encodeURIComponent(email)}&resetToken=${encodeURIComponent(token)}, built the same way asverifyEmailUrlandinviteSignupUrl. MailService.passwordResetTokenpasses that URL to the template asresetUrl. Thepathimport stays,mustCompileTemplatestill uses it.- The template prints
{{{resetUrl}}}(unescaped), like the verify-email and invite templates. docs/changelog.md: one line under## next.
Tests
New specs, run on the unchanged code first:
api/src/utils/password-reset-url.spec.ts(1 test):passwordResetUrl('jane+tr@example.com', 'abc')equals${config.virtualHost}/reset-password?email=jane%2Btr%40example.com&resetToken=abc.api/src/services/mail.service.spec.ts(2 tests): spies on the privatesendand checks the reset email text contains that URL and nohttp:/orhttps:/followed by a non-slash; a second case checks thato'neil@example.comis not HTML-escaped (').
Before the fix: 2 suites failed (the util spec does not compile, TS2307; both MailService tests fail, the received text was .\http:\localhost:8080\reset-password?email=jane+tr@example.com&resetToken=abc and ...email=o'neil@example.com...). After the fix: 3 of 3 tests pass.
Checks run
prettier --check "**/*.ts"at the root (asbin/check_lint.sh): clean.yarn --cwd api lint(tslint): clean.yarn --cwd api build(tsc + copyfiles): passes;dist/src/templates/mail/password-reset-token.txthas{{{resetUrl}}}.- api unit tests (jest,
--maxWorkers=2): 170 of 171 pass. The one failure,src/formatters/properties.spec.ts, fails only on Windows and is unrelated: thepropertieslibrary writes\r\nwhenprocess.platform === 'win32', while the fixture has\n. It passes on Linux CI. - e2e tests were not run locally; the e2e specs that touch password reset mock
passwordResetToken, so they do not read the template.
Fleet task T-2539; authored by the lead lane while the fleet is paused by its daily cost ceiling.
š¤ Generated with Claude Code
Summary by cubic
Fixes the password reset email so the link actually opens the reset page and works with plus-addressed emails.
path.joincollapsedhttps://tohttps:/, so mail clients did not turn the link into a clickable URL.- The email was not URL-encoded and was HTML-escaped, so
jane+tr@example.comreached the reset page asjane tr@example.comand the reset failed with a 400, with no way for the user to correct it.
The link is now built by a new passwordResetUrl helper that encodes the email and token, and the template prints it unescaped, matching how the verify-email and invite links are handled.