Add password reset by emailed single-use link #215
Loading…
Reference in a new issue
No description provided.
Delete branch "password-reset"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Lets a local-password user who forgot their password get a reset link by email. Vikunja task 584. ADR-0174 supersedes ADR-0094 and lifts the v1 email exclusion for password recovery only.
Behaviour:
POST /api/auth/password-reset/requestanswers 202 for every address. Only an account with a local password gets a mail. OIDC-only accounts get the same 202 and nothing.POST /api/auth/password-reset/confirmredeems the token once, sets the password, voids the account's other reset tokens and revokes its refresh tokens, in one transaction. Bad, used and expired tokens all give the same 400./forgot-passwordand/reset-password. The sign-in page links to the first instead of the ADR-0094 sentence.Config and rollout:
Smtp:Host,Smtp:Port,Smtp:Username,Smtp:Password,Smtp:FromAddress,WebUi:BaseUrl(README). WithSmtp:Hostset, the from address and base URL are required. With none, nothing is sent: Development logs the mail, elsewhere only a warning with no token.0006-password-reset-tokens.sql.SchemaVersionHealthCheck.RequiredScriptnow names it, so run the schema upgrade before deploying or readiness reports unhealthy.System.Security.Cryptography.Pkcs10.0.0, so that is pinned to 10.0.13 with a comment.Tests are in Api.Tests (flow over HTTP with a capturing mail sender), Infrastructure.Tests (SQL, log sender, schema) and WebUI.Tests (pages).
Verdict: changes needed
Two tests cannot fail on the behaviour they guard (see inline). One low-risk hardening item is also worth deciding on. Design, SQL and transaction look sound.
PostRequest_TheRelayFails_StillAnswers202passes with thecatchinSendResetMailAsyncdeleted: the faulted task is discarded, so the response is still 202. Assert the warning is logged (or that the task's fault is observed), otherwise it guards nothing.AddPlaceMarkPasswordResetpassesenvironment.IsDevelopment()toLogEmailSender. Flip it totrueand every test stays green while production logs the reset link. Add a test that builds the provider with a non-Development environment and noSmtp:Host, sends, and asserts the token is absent from the log. The same file's startup throw (Smtp:Host set without FromAddress or WebUi:BaseUrl) is also untested.SmtpEmailSenderdoesoptions.Password!, so a Username with no Password throws a NullReferenceException on every send, swallowed as a warning. Validate at startup alongside the FromAddress check.PasswordResetTokenRepository.Lifetimeexists. They can drift.@ -0,0 +38,4 @@}var (token, tokenHash) = RefreshTokenGenerator.Generate();await resetTokens.CreateAsync(user.Id, tokenHash, timeProvider.GetUtcNow().UtcDateTime, cancellationToken);No per-account throttle: each request for a known address inserts a row and sends a mail. Skip both if an unused token under a minute old exists; same 202.
@ -0,0 +22,4 @@if (string.IsNullOrWhiteSpace(smtp?.Host)){return services.AddSingleton<IEmailSender>(provider =>new LogEmailSender(provider.GetRequiredService<ILogger<LogEmailSender>>(), environment.IsDevelopment()));Untested: set this to true and the whole suite stays green while Production logs the token. Needs a wiring test with a non-Development environment.
@ -0,0 +112,4 @@}[Fact]public async Task PostRequest_TheRelayFails_StillAnswers202()Passes with the catch in SendResetMailAsync removed (exception lands in the discarded task). Assert the LogResetMailFailed warning instead.
Verdict: mergeable
All six round-one findings are addressed. Nothing new to act on.
Verdict: mergeable
The merge of
mainadded only #216's changes, so the diff againstmainis what review 877 approved. Nothing to act on.Verdict: changes needed
One finding. The
authenticated: truecase cannot fail if authentication is broken.MP_SMTP_AUTH_ACCEPT_ANY=1makes auth optional, so Mailpit accepts the message whether or notAuthenticateAsyncruns, and with any credentials. Delete theif (!string.IsNullOrEmpty(options.Username))block inSmtpEmailSenderand both theory rows stay green. That case only covers the lines.Fix: start Mailpit with
MP_SMTP_AUTH=relay-user:relay-passwordinstead ofACCEPT_ANY. KeepMP_SMTP_AUTH_ALLOW_INSECURE=1. Mailpit then rejects unauthenticated and wrong-credential sends. Thefalserow would fail against the same fixture, so give it its own assertion (ShouldThrowon the send) or a second Mailpit without auth. Then mutate the auth block and confirm thetruerow goes red.Port mapping, readiness and recipient uniqueness look fine.
Verdict: mergeable
Optional:
SendAsync_WithTheWrongPassword_IsRefusedByTheRelayusesShould.ThrowAsync<Exception>, so it also passes on a connection failure or a bad address. AssertMailKit.Security.AuthenticationExceptionso it only passes for a refused login. The delivery fact already guards the happy path, so this isn't blocking.