Skip to content
Toolkit

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:

  1. lost_password_code never expired.
  2. A reset cleared twofa_secret and returned a signed-in token, so email access alone defeated 2FA.
  3. Sessions are seven-day JWTs with no revocation, so a reset left every stolen session working.
  4. /reset-password, /resend-activation and /activate-user were outside the auth lockout, and only the 300/min public limiter applied.

Decision

  • Migration 000046 adds users.lost_password_code_at (issue time) and users.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). GetByLostPasswordCode and ResetPassword both check the time.
  • ResetPassword(userID, code, hash) spends the code, sets the password and stamps sessions_valid_after = NOW() in one statement, so a code works once even under concurrent requests. It does not touch twofa_secret.
  • Every JWT-authenticated request passes the token's iat to ValidateJWT, which refuses a token issued before sessions_valid_after (to the second). The product has no refresh tokens. Scoped API tokens and the legacy api_key are 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 AuthLimiter budget as login.

Consequences

  • The web reset page must handle twofa_required: true with no token by sending the user to sign in (hand-off to web).
  • 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

Library