↑↓ to navigate Enter to open "…" all these words ANDOR to combine

Architecture Decision Record

ADR-091: Cache-Backed Password Reset

Status

Accepted (2026-08-22). Extends ADR-029 (the cache-backed login-protection idiom this record reuses) and ADR-032 (which decided how a password is stored, never how a user who has lost one gets a new one). The existing authentication chain is untouched: this is an additive sibling, not a revision. Revised 2026-10-01 (redemption serialized under a distributed lock, a reset revokes refresh sessions, and the link carries the token in the URL fragment; see Revision below). Revised 2026-10-07: anchors refreshed after the v1.233.0 release. Revised 2026-10-21: session revocation is saved before the new password is applied and stands even when the aggregate rejects it, and the reset email is localized (English and Spanish). Revised 2026-10-26: anchors refreshed after the v1.261.0 release. Revised 2026-10-28: anchors refreshed after the v1.265.1 release. Revised 2026-11-23: both AppHosts now set PasswordReset__ResetUrl through the shared WithUiLinks helper, not MMCA.ADC's alone, and anchors are refreshed.

Context

Both consumer apps shipped authenticated password change (PUT /Auth/password) and nothing for a user who cannot sign in at all. The recorded fallback in MMCA.ADC's specification was for an organizer to delete the account so the attendee could re-register, which is a support burden, destroys the user's engagement history, and is not a posture a second consumer (MMCA.Store, where an account owns orders) can adopt at all.

Three shapes were available for the reset credential:

  1. Database columns on the user row (ResetTokenHash, ResetTokenExpiresAt, ResetAttempts): the conventional choice, and the one that costs a migration in every consumer, adds three columns to the hottest entity in the system, and needs a sweeper to reap expired rows because expiry is not a property the store enforces.
  2. A self-contained signed payload (an ASP.NET Core Data Protection token, or a short-lived JWT): no storage at all, but single-use is then unimplementable without a store anyway, since a signed token that has not expired stays valid however many times it is redeemed. Bolting a revocation list back on reintroduces the store while keeping the payload's opacity problems.
  3. A cache record keyed by the address, which is exactly the substrate ADR-029 already chose for login lockout and registration caps, and ADR-026 already guarantees is present in every host.

The endpoint contract carried its own decision. A naive forgot-password endpoint that answers 404 for an unknown address is an account-enumeration oracle: an attacker with a list of addresses learns which ones are registered, at any rate the anonymous limiter allows. So does a 400 on a throttled address, and so does a 500 when the SMTP hop is down.

Decision

  1. The reset token is a cache record, not a schema change. IPasswordResetTokenService (Source/Core/MMCA.Common.Application/Auth/IPasswordResetTokenService.cs) is two methods, IssueAsync(email, userId) and ValidateAndConsumeAsync(email, token), both returning Result. The implementation (Source/Core/MMCA.Common.Infrastructure/Auth/PasswordResetTokenService.cs) writes one pwdreset:token:{email} record and one pwdreset:req:{email} counter through ICacheService, deliberately mirroring LoginProtectionService down to the address normalization, the key-builder shape, and the IncrementAsync throttle with its disclosed read-modify-write race (PasswordResetTokenService.cs:68). Redemption does not share that race: ValidateAndConsumeAsync takes an IDistributedLock on lock:{tokenKey} (:36, :107; 10-second TTL and 5-second wait at :41 and :43) and reads through GetFromSharedStoreAsync (:128), so two concurrent redemptions of one token cannot both succeed, and a redemption that cannot take the lock is answered as an invalid token. Expiry is the cache TTL: there is no sweeper and no reaper job, because there is no row to reap.
  2. The token's security properties are in the service, not in the caller. 256 bits from RandomNumberGenerator, Base64Url-encoded; only its SHA-256 is stored, so a cache dump hands out no working links; comparison is CryptographicOperations.FixedTimeEquals; issuing overwrites, so one address has at most one live token; a wrong guess increments an attempt counter and rewrites the record with its remaining lifetime rather than a fresh one, so guessing cannot extend the window; the record is discarded at MaxValidationAttempts. Every bound lives in PasswordResetSettings (section PasswordReset, [Range]-validated and ValidateOnStart per ADR-070): 30-minute TTL, 5 validation attempts, 3 requests per address per 60-minute window, plus an optional ResetUrl.
  3. The anti-enumeration contract lives in the handler base, where it cannot be forgotten. ForgotPasswordHandlerBase returns Result.Success() on every path: malformed address, no account, throttled, and failed send each log a reason and report success. ResetPasswordHandlerBase collapses every rejection (unknown, expired, mismatched, attempt-capped token, and an account that no longer resolves) into one Auth.InvalidResetToken error, which the edge maps to 401. Once a token is redeemed and the account resolves, the handler revokes and saves every live refresh session on the account before it applies the new password, and that revocation stands even when the aggregate then rejects the password (ADR-097; Source/Core/MMCA.Common.Application/Users/UseCases/ResetPassword/ResetPasswordHandlerBase.cs:48, :106, :110, :112). After the save (:117) it clears the account's login lockout (:120). A consumer therefore inherits the property rather than re-deriving it; the only app-specific member on the forgot base is FindUntrackedByEmailAsync, because each app's User stores its address differently.
  4. The endpoints ship as an opt-in sibling controller base. PasswordResetAuthControllerBase (Source/Presentation/MMCA.Common.API/Controllers/) exposes POST forgot-password (202) and POST reset-password (204), both [AllowAnonymous], both [Idempotent], both under the auth-ip per-IP policy from ADR-019. It is a sibling of AuthControllerBase rather than two more actions on it because both apps' AuthController already occupies that single inheritance chain; a consumer routes the new controller to the same Auth prefix, so the existing gateway route forwards it with no gateway change. Nothing about the existing auth chain changes, so adopting this is additive.
  5. The email is composed in the handler, with overridable hooks, and delivered best-effort. ComposeSubject, ComposeBody and ComposeResetLink are protected virtual. The default body carries the reset link and the raw token, because the MAUI head cannot follow a deep link and its user has to type the token into the reset page. A blank ResetUrl degrades to the token alone rather than shipping a broken link. Subject and body come from UserEmailResources and are composed in the recipient's stored preferred culture when the account has one, otherwise in the culture of the forgot-password request (ForgotPasswordHandlerBase.cs:82, :114, :129 to :134; UserEmailResources.cs:32-35), with English and Spanish shipped (UserEmailResources.es.resx). The send is awaited and its failure caught, logged and swallowed.
  6. Consumers opt in with thin wiring. Each app adds a ForgotPasswordCommand / ResetPasswordCommand record, a handler that is a constructor call on the base, and a sealed PasswordResetController supplying the two command factories. Configuration is one key (PasswordReset:ResetUrl) in each Identity service's appsettings.json (MMCA.ADC Source/Services/MMCA.ADC.Identity.Service/appsettings.json:168, MMCA.Store Source/Services/MMCA.Store.Identity.Service/appsettings.json:118) and as PasswordReset__ResetUrl in infra/main.bicep for production (MMCA.ADC :2288, MMCA.Store :1961). Both Aspire AppHosts also set it for local runs through the shared WithUiLinks helper, which derives the link from the UI resource's https endpoint (MMCA.Common/Source/Hosting/MMCA.Common.Aspire.Hosting/IdentityLinkExtensions.cs:74, :84; MMCA.ADC Source/Hosting/MMCA.ADC.AppHost/Program.cs:474, MMCA.Store Source/Hosting/MMCA.Store.AppHost/Program.cs:381), so the appsettings.json default serves only a standalone run outside the AppHost. MMCA.ADC and MMCA.Store both adopted it in v1.160.0.

Rationale

  • No migration is the whole point. A reset credential is short-lived by nature, and the expiry semantics a reset needs (a TTL, a single use, an attempt cap) are native to a cache and bolted on to a relational table. Choosing the cache means the feature ships to both production apps (MMCA.ADC and MMCA.Store) without touching a schema, and the "expired token" state is enforced by the store instead of by a query filter someone can forget to write.
  • Reusing the login-protection idiom is a correctness argument, not a style one. The address normalization in particular is load-bearing and easy to get wrong: keys built from raw request input give User@x.com and user@x.com independent tokens and independent counters while resolving to one account. Reusing the proven method removes that class of bug rather than re-litigating it.
  • A contract that must hold on every path belongs in the base. Anti-enumeration is the kind of property that survives review and dies in the second consumer's copy of the handler. Making Result.Success() the only return of the forgot-password workflow means a subclass cannot leak the distinction even by accident.
  • Single-use is what rules out the signed-payload option. The cheap-looking alternative, a Data Protection token with no server state, cannot express "redeemable once" without adding server state, at which point it has the storage cost of this design plus an opaque payload.

Trade-offs

  • Cache eviction invalidates outstanding tokens. A Redis restart, an eviction under memory pressure, or a fall back to the in-memory store on a different replica all silently kill live reset links. Accepted: re-requesting a link costs the user one page and one email, the failure mode is self-explanatory ("the link is invalid or has expired, request a new one"), and the same reasoning already governs login lockout state.
  • A timing oracle remains. The response body and status code disclose nothing, but a registered address does more work (a database read, a cache write, an SMTP round trip) than an unregistered one, so the duration still correlates with existence. Closing that would mean either constant-time padding or moving the send off the request path onto the outbox. Neither is done, and this is the known residual of the always-202 contract rather than a defect in it.
  • Email delivery has no outbox and no retry. A send that fails is logged and dropped. The transactional-email posture recorded in ADR-024 places IEmailSender outside the durable notification channel (this workflow is one of its framework-level consumers), and the token surviving the failure is what makes a user-driven retry sufficient. A reset email that must not be lost would need the outbox, which is a larger decision than this record makes.
  • The request throttle undercounts under concurrency. IncrementAsync is a read-modify-write on every backing store (ADR-026), so simultaneous requests can slip past the per-address cap. It loosens the throttle and never tightens it, and the auth-ip limiter sits underneath, so the failure mode is bounded.
  • The token is consumed before the password is written. A password change that fails a later aggregate invariant burns the token, costing the user one more request. The alternative, holding the token live until the write succeeds, opens a replay window, which is the worse of the two.
  • The email speaks only the shipped cultures. The copy is resource-backed and written in the recipient's stored preferred culture, or the request culture when none is stored (ADR-027), but only English and Spanish resources ship, so a culture outside those two reads the English fallback.

Revision (2026-10-01)

Three behaviors changed after acceptance, and four statements are corrected: one was omitted at acceptance, two were wrong as written, and one had drifted from a later revision of ADR-024.

  • Redemption is serialized. ValidateAndConsumeAsync now runs its read, compare and remove under an IDistributedLock on lock:{tokenKey} (MMCA.Common/Source/Core/MMCA.Common.Infrastructure/Auth/PasswordResetTokenService.cs:107, TTL and wait at :41 and :43) and reads through GetFromSharedStoreAsync (:128), so two concurrent redemptions of one token cannot both succeed; a contended redemption is answered as an invalid token. The constructor requires the lock (:36), a breaking change recorded in MMCA.Common/CHANGELOG.md:86 and :91. Only the IncrementAsync request throttle (:68) keeps the read-modify-write race, so Decision 1 no longer claims the service mirrors that race end to end.
  • A successful reset revokes refresh sessions. It also clears the login lockout, which it has done since acceptance and the original record omitted. ResetPasswordHandlerBase takes a required IRefreshSessionStore (MMCA.Common/Source/Core/MMCA.Common.Application/Users/UseCases/ResetPassword/ResetPasswordHandlerBase.cs:47) and, after the save, revokes every live session on the account (:106, per ADR-097) and calls ResetFailedAttemptsAsync (:110). Decision 3 records both.
  • The reset link carries the address and token in the URL fragment. The default ComposeResetLink builds {ResetUrl}#email=...&token=... (MMCA.Common/Source/Core/MMCA.Common.Application/Users/UseCases/ForgotPassword/ForgotPasswordHandlerBase.cs:155), so the live token is never sent to a server and stays out of ingress logs.
  • Corrections. PasswordReset:ResetUrl is set by MMCA.ADC's AppHost only (MMCA.ADC/Source/Hosting/MMCA.ADC.AppHost/Program.cs:470); MMCA.Store's local runs rely on its appsettings.json default. MMCA.Helpdesk has not adopted password reset, so the Rationale names the two production apps only. The Trade-offs line on ADR-024 now matches that record's 2026-08-31 revision, which no longer calls IEmailSender an app-level-only primitive while keeping it outside the channel model.

Revision (2026-10-06)

No behavior changed; only line anchors moved.

  • Decision 6 anchors updated: MMCA.ADC Identity appsettings.json:114, MMCA.ADC infra/main.bicep:1790, and the MMCA.ADC AppHost key at Source/Hosting/MMCA.ADC.AppHost/Program.cs:462 (the AppHost anchor recorded as :470 in the 2026-10-01 Corrections bullet now sits at :462).
  • The breaking IDistributedLock constructor change and its fix, recorded above at MMCA.Common/CHANGELOG.md:86 and :91, now sit at :427 and :432 under [1.213.0].
  • All other anchors (PasswordResetTokenService.cs, ResetPasswordHandlerBase.cs, ForgotPasswordHandlerBase.cs, MMCA.Store appsettings.json:105 and infra/main.bicep:1551) were re-verified against current source and hold.

Revision (2026-10-07)

Re-verified against current source. No behavior changed: the cache-backed token, the distributed lock on redemption, the refresh-session revocation and the URL-fragment link all hold as recorded; only line anchors moved.

  1. Anchors re-verified against current source: MMCA.ADC infra/main.bicep:1822 (PasswordReset__ResetUrl, was :1790) and the MMCA.ADC AppHost key at Source/Hosting/MMCA.ADC.AppHost/Program.cs:465 (was :462; the :470 recorded in the 2026-10-01 Corrections bullet is now the email-confirmation comment). The breaking IDistributedLock constructor change and its fix sit at MMCA.Common/CHANGELOG.md:452 and :457 under [1.213.0] (heading :448), not the :427 and :432 recorded on 2026-10-06. Unchanged and holding: PasswordResetTokenService.cs:36, :41, :43, :68, :107, :128; ResetPasswordHandlerBase.cs:47, :106, :110; ForgotPasswordHandlerBase.cs:155; MMCA.ADC Identity appsettings.json:114; MMCA.Store Identity appsettings.json:105 and infra/main.bicep:1551.

Revision (2026-10-21)

Re-verified against current source. The cache-backed token, the distributed lock on redemption, the anti-enumeration contract and the URL-fragment link are unchanged. Two statements moved: the ordering of session revocation against the password save, and the language of the reset email.

  1. Session revocation precedes the password write. ResetPasswordHandlerBase revokes and saves every live refresh session (MMCA.Common/Source/Core/MMCA.Common.Application/Users/UseCases/ResetPassword/ResetPasswordHandlerBase.cs:106) before it hashes and applies the new password (:110, :111) and before the unit-of-work save (:117); a password the aggregate rejects fails the check at :112 and returns at :114 with the revocation already standing. Only the lockout clear (:120) follows the save. Recorded in MMCA.Common/CHANGELOG.md:75 (M240, under [1.247.0]). Decision 3 now says this; the 2026-10-01 wording "after the save" no longer describes the handler.
  2. The reset email is localized. ForgotPasswordHandlerBase composes subject and body under UserEmailResources.InRecipientCulture (MMCA.Common/Source/Core/MMCA.Common.Application/Users/UseCases/ForgotPassword/ForgotPasswordHandlerBase.cs:85) from resource keys (:117, :132 to :137), and MMCA.Common/Source/Core/MMCA.Common.Application/Users/Emails/UserEmailResources.es.resx ships Spanish (MMCA.Common/CHANGELOG.md:197, under [1.243.0]). Decision 5 and the Trade-offs bullet no longer say the copy is English only.
  3. Anchors re-verified against current source: ResetPasswordHandlerBase.cs:48 (the required IRefreshSessionStore, was :47) and :120 (ResetFailedAttemptsAsync, was :110, which is now HashPassword); MMCA.ADC Identity appsettings.json:115 and MMCA.Store Identity appsettings.json:115 (the ResetUrl key, was :114 and :105); MMCA.ADC infra/main.bicep:1978 (was :1822) and MMCA.Store infra/main.bicep:1640 (was :1551); the MMCA.ADC AppHost key at Source/Hosting/MMCA.ADC.AppHost/Program.cs:504 (was :465; the email-confirmation comment is now :507), and the MMCA.Store AppHost still sets no PasswordReset key. The IDistributedLock breaking change and its fix sit at MMCA.Common/CHANGELOG.md:771 and :776 under [1.213.0] (heading :767). Holding: PasswordResetTokenService.cs:36, :41, :43, :68, :107, :128; ResetPasswordHandlerBase.cs:106; ForgotPasswordHandlerBase.cs:155.

Revision (2026-10-26)

Re-verified against current source. No behavior changed: the cache-backed token, the distributed lock on redemption, the session revocation ahead of the password write, the anti-enumeration contract, the URL-fragment link and the localized email all hold as recorded; only line anchors moved.

  1. Anchors re-verified against current source: ForgotPasswordHandlerBase.cs:82 (the UserEmailResources.InRecipientCulture call, was :85, which is now emailSender.SendAsync), :114 (ForgotPassword.Subject, was :117) and :129 to :134 (ForgotPassword.LinkText, Intro, Code and Ignore in ComposeBody, recorded as :132 to :137 on 2026-10-21); MMCA.Store Identity appsettings.json:114 (the ResetUrl key, was :115); MMCA.ADC infra/main.bicep:2014 (was :1978) and MMCA.Store infra/main.bicep:1646 (was :1640); the MMCA.ADC AppHost email-confirmation comment at Source/Hosting/MMCA.ADC.AppHost/Program.cs:508 (recorded as :507 on 2026-10-21). In MMCA.Common/CHANGELOG.md: M240 at :290 under [1.247.0] (heading :260), the localized-email entry at :412 under [1.243.0] (heading :380), and the IDistributedLock breaking change and its fix (L91) at :986 and :991 under [1.213.0] (heading :982). Holding: PasswordResetTokenService.cs:36, :41, :43, :68, :107, :128; ResetPasswordHandlerBase.cs:48, :106, :110, :112, :117, :120; ForgotPasswordHandlerBase.cs:155; UserEmailResources.cs:32-35; MMCA.ADC Identity appsettings.json:115; the MMCA.ADC AppHost key at Source/Hosting/MMCA.ADC.AppHost/Program.cs:504.

Revision (2026-10-28)

Re-verified against current source. No behavior changed: the cache-backed token, the distributed lock on redemption, the session revocation ahead of the password write, the anti-enumeration contract, the URL-fragment link and the localized email all hold as recorded; only line anchors moved.

  1. Anchors re-verified against current source: MMCA.ADC infra/main.bicep:2011 (PasswordReset__ResetUrl, was :2014) and MMCA.Store infra/main.bicep:1647 (was :1646). In MMCA.Common/CHANGELOG.md: M240 at :333 under [1.247.0] (heading :303), the localized-email entry at :455 under [1.243.0] (heading :423), and the IDistributedLock breaking change and its fix (L91) at :1029 and :1034 under [1.213.0] (heading :1025). Holding: PasswordResetTokenService.cs:36, :41, :43, :68, :107, :128; ResetPasswordHandlerBase.cs:48, :106, :110, :112, :117, :120; ForgotPasswordHandlerBase.cs:82, :114, :129 to :134, :155.

Revision (2026-11-23)

Re-verified against current source. The cache-backed token, the distributed lock on redemption, the session revocation ahead of the password write, the anti-enumeration contract, the URL-fragment link and the localized email all hold as recorded. One statement moved: how local runs get the reset link.

  1. Both AppHosts set the reset link. The WithUiLinks extension in MMCA.Common/Source/Hosting/MMCA.Common.Aspire.Hosting/IdentityLinkExtensions.cs:74 sets PasswordReset__ResetUrl from the UI resource's https endpoint (:84, :85), and both MMCA.ADC (Source/Hosting/MMCA.ADC.AppHost/Program.cs:474) and MMCA.Store (Source/Hosting/MMCA.Store.AppHost/Program.cs:381) call it; neither AppHost names the key literally. Decision 6 now says this; the earlier statement that only MMCA.ADC's AppHost sets the key, kept as written in the 2026-10-01 and 2026-10-21 revisions, no longer describes MMCA.Store.
  2. Anchors re-verified against current source: MMCA.ADC Identity appsettings.json:168 (the ResetUrl key, was :115) and MMCA.Store Identity appsettings.json:118 (was :114); MMCA.ADC infra/main.bicep:2288 (was :2011) and MMCA.Store infra/main.bicep:1961 (was :1647). In MMCA.Common/CHANGELOG.md: M240 at :1270 under [1.247.0] (heading :1240), the localized-email entry at :1392 under [1.243.0] (heading :1360), and the IDistributedLock breaking change and its fix (L91) at :1966 and :1971 under [1.213.0] (heading :1962). Holding: PasswordResetTokenService.cs:36, :41, :43, :68, :107, :128; ResetPasswordHandlerBase.cs:48, :106, :110, :112, :117, :120; ForgotPasswordHandlerBase.cs:82, :114, :129 to :134, :155; UserEmailResources.cs:32-35.