ADR-0168 — A reset code expires, and a reset ends every session
Status: Accepted · Date: 2026-10-11 · Track: launch wave 1, api
workstream · Supersedes: the legacy reset behaviour (clear 2FA, sign in)
Context
Launch audit P1-5 found four weaknesses in password reset:
lost_password_codenever expired.- A reset cleared
twofa_secretand returned a signed-in token, so email access alone defeated 2FA. - Sessions are seven-day JWTs with no revocation, so a reset left every stolen session working.
/reset-password,/resend-activationand/activate-userwere outside the auth lockout, and only the 300/min public limiter applied.
Decision
- Migration
000046addsusers.lost_password_code_at(issue time) andusers.sessions_valid_after. Codes issued before the migration are cleared, because they have no issue time. - A code is valid for 30 minutes (
repository.ResetCodeTTL).GetByLostPasswordCodeandResetPasswordboth check the time. ResetPassword(userID, code, hash)spends the code, sets the password and stampssessions_valid_after = NOW()in one statement, so a code works once even under concurrent requests. It does not touchtwofa_secret.- Every JWT-authenticated request passes the token's
iattoValidateJWT, which refuses a token issued beforesessions_valid_after(to the second). The product has no refresh tokens. Scoped API tokens and the legacyapi_keyare not sessions and are not revoked by a reset. - An account with 2FA gets no token from a reset (
twofa_required: true). It signs in with the new password and its code. An account without 2FA is still signed in by the reset, with a token issued after the cutoff. - The three endpoints use the same
AuthLimiterbudget as login.
Consequences
- The web reset page must handle
twofa_required: truewith notokenby sending the user to sign in (hand-off toweb). - Changing the password from account settings does not yet end other sessions. That is a smaller follow-up using the same column.
Source: docs/decisions/0168-a-reset-code-expires-and-a-reset-ends-every-session.md