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:
- 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. - 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.
- 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
- 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)andValidateAndConsumeAsync(email, token), both returningResult. The implementation (Source/Core/MMCA.Common.Infrastructure/Auth/PasswordResetTokenService.cs) writes onepwdreset:token:{email}record and onepwdreset:req:{email}counter throughICacheService, deliberately mirroringLoginProtectionServicedown to the address normalization, the key-builder shape, and theIncrementAsyncthrottle with its disclosed read-modify-write race (PasswordResetTokenService.cs:68). Redemption does not share that race:ValidateAndConsumeAsynctakes anIDistributedLockonlock:{tokenKey}(:36,:107; 10-second TTL and 5-second wait at:41and:43) and reads throughGetFromSharedStoreAsync(: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. - 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 isCryptographicOperations.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 atMaxValidationAttempts. Every bound lives inPasswordResetSettings(sectionPasswordReset,[Range]-validated andValidateOnStartper ADR-070): 30-minute TTL, 5 validation attempts, 3 requests per address per 60-minute window, plus an optionalResetUrl. - The anti-enumeration contract lives in the handler base, where it cannot be forgotten.
ForgotPasswordHandlerBasereturnsResult.Success()on every path: malformed address, no account, throttled, and failed send each log a reason and report success.ResetPasswordHandlerBasecollapses every rejection (unknown, expired, mismatched, attempt-capped token, and an account that no longer resolves) into oneAuth.InvalidResetTokenerror, 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 isFindUntrackedByEmailAsync, because each app'sUserstores its address differently. - The endpoints ship as an opt-in sibling controller base.
PasswordResetAuthControllerBase(Source/Presentation/MMCA.Common.API/Controllers/) exposesPOST forgot-password(202) andPOST reset-password(204), both[AllowAnonymous], both[Idempotent], both under theauth-ipper-IP policy from ADR-019. It is a sibling ofAuthControllerBaserather than two more actions on it because both apps'AuthControlleralready occupies that single inheritance chain; a consumer routes the new controller to the sameAuthprefix, so the existing gateway route forwards it with no gateway change. Nothing about the existing auth chain changes, so adopting this is additive. - The email is composed in the handler, with overridable hooks, and delivered best-effort.
ComposeSubject,ComposeBodyandComposeResetLinkareprotected 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 blankResetUrldegrades to the token alone rather than shipping a broken link. Subject and body come fromUserEmailResourcesand 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,:129to:134;UserEmailResources.cs:32-35), with English and Spanish shipped (UserEmailResources.es.resx). The send is awaited and its failure caught, logged and swallowed. - Consumers opt in with thin wiring. Each app adds a
ForgotPasswordCommand/ResetPasswordCommandrecord, a handler that is a constructor call on the base, and a sealedPasswordResetControllersupplying the two command factories. Configuration is one key (PasswordReset:ResetUrl) in each Identity service'sappsettings.json(MMCA.ADCSource/Services/MMCA.ADC.Identity.Service/appsettings.json:168, MMCA.StoreSource/Services/MMCA.Store.Identity.Service/appsettings.json:118) and asPasswordReset__ResetUrlininfra/main.bicepfor production (MMCA.ADC:2288, MMCA.Store:1961). Both Aspire AppHosts also set it for local runs through the sharedWithUiLinkshelper, which derives the link from the UI resource's https endpoint (MMCA.Common/Source/Hosting/MMCA.Common.Aspire.Hosting/IdentityLinkExtensions.cs:74,:84; MMCA.ADCSource/Hosting/MMCA.ADC.AppHost/Program.cs:474, MMCA.StoreSource/Hosting/MMCA.Store.AppHost/Program.cs:381), so theappsettings.jsondefault 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.comanduser@x.comindependent 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
IEmailSenderoutside 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.
IncrementAsyncis 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 theauth-iplimiter 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.
ValidateAndConsumeAsyncnow runs its read, compare and remove under anIDistributedLockonlock:{tokenKey}(MMCA.Common/Source/Core/MMCA.Common.Infrastructure/Auth/PasswordResetTokenService.cs:107, TTL and wait at:41and:43) and reads throughGetFromSharedStoreAsync(: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 inMMCA.Common/CHANGELOG.md:86and:91. Only theIncrementAsyncrequest 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.
ResetPasswordHandlerBasetakes a requiredIRefreshSessionStore(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 callsResetFailedAttemptsAsync(:110). Decision 3 records both. - The reset link carries the address and token in the URL fragment. The default
ComposeResetLinkbuilds{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:ResetUrlis set by MMCA.ADC's AppHost only (MMCA.ADC/Source/Hosting/MMCA.ADC.AppHost/Program.cs:470); MMCA.Store's local runs rely on itsappsettings.jsondefault. 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 callsIEmailSenderan 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.ADCinfra/main.bicep:1790, and the MMCA.ADC AppHost key atSource/Hosting/MMCA.ADC.AppHost/Program.cs:462(the AppHost anchor recorded as:470in the 2026-10-01 Corrections bullet now sits at:462). - The breaking
IDistributedLockconstructor change and its fix, recorded above atMMCA.Common/CHANGELOG.md:86and:91, now sit at:427and:432under[1.213.0]. - All other anchors (
PasswordResetTokenService.cs,ResetPasswordHandlerBase.cs,ForgotPasswordHandlerBase.cs, MMCA.Storeappsettings.json:105andinfra/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.
- Anchors re-verified against current source: MMCA.ADC
infra/main.bicep:1822(PasswordReset__ResetUrl, was:1790) and the MMCA.ADC AppHost key atSource/Hosting/MMCA.ADC.AppHost/Program.cs:465(was:462; the:470recorded in the 2026-10-01 Corrections bullet is now the email-confirmation comment). The breakingIDistributedLockconstructor change and its fix sit atMMCA.Common/CHANGELOG.md:452and:457under[1.213.0](heading:448), not the:427and:432recorded 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 Identityappsettings.json:114; MMCA.Store Identityappsettings.json:105andinfra/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.
- Session revocation precedes the password write.
ResetPasswordHandlerBaserevokes 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:112and returns at:114with the revocation already standing. Only the lockout clear (:120) follows the save. Recorded inMMCA.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. - The reset email is localized.
ForgotPasswordHandlerBasecomposes subject and body underUserEmailResources.InRecipientCulture(MMCA.Common/Source/Core/MMCA.Common.Application/Users/UseCases/ForgotPassword/ForgotPasswordHandlerBase.cs:85) from resource keys (:117,:132to:137), andMMCA.Common/Source/Core/MMCA.Common.Application/Users/Emails/UserEmailResources.es.resxships 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. - Anchors re-verified against current source:
ResetPasswordHandlerBase.cs:48(the requiredIRefreshSessionStore, was:47) and:120(ResetFailedAttemptsAsync, was:110, which is nowHashPassword); MMCA.ADC Identityappsettings.json:115and MMCA.Store Identityappsettings.json:115(theResetUrlkey, was:114and:105); MMCA.ADCinfra/main.bicep:1978(was:1822) and MMCA.Storeinfra/main.bicep:1640(was:1551); the MMCA.ADC AppHost key atSource/Hosting/MMCA.ADC.AppHost/Program.cs:504(was:465; the email-confirmation comment is now:507), and the MMCA.Store AppHost still sets noPasswordResetkey. TheIDistributedLockbreaking change and its fix sit atMMCA.Common/CHANGELOG.md:771and:776under[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.
- Anchors re-verified against current source:
ForgotPasswordHandlerBase.cs:82(theUserEmailResources.InRecipientCulturecall, was:85, which is nowemailSender.SendAsync),:114(ForgotPassword.Subject, was:117) and:129to:134(ForgotPassword.LinkText,Intro,CodeandIgnoreinComposeBody, recorded as:132to:137on 2026-10-21); MMCA.Store Identityappsettings.json:114(theResetUrlkey, was:115); MMCA.ADCinfra/main.bicep:2014(was:1978) and MMCA.Storeinfra/main.bicep:1646(was:1640); the MMCA.ADC AppHost email-confirmation comment atSource/Hosting/MMCA.ADC.AppHost/Program.cs:508(recorded as:507on 2026-10-21). InMMCA.Common/CHANGELOG.md: M240 at:290under[1.247.0](heading:260), the localized-email entry at:412under[1.243.0](heading:380), and theIDistributedLockbreaking change and its fix (L91) at:986and:991under[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 Identityappsettings.json:115; the MMCA.ADC AppHost key atSource/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.
- Anchors re-verified against current source: MMCA.ADC
infra/main.bicep:2011(PasswordReset__ResetUrl, was:2014) and MMCA.Storeinfra/main.bicep:1647(was:1646). InMMCA.Common/CHANGELOG.md: M240 at:333under[1.247.0](heading:303), the localized-email entry at:455under[1.243.0](heading:423), and theIDistributedLockbreaking change and its fix (L91) at:1029and:1034under[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,:129to: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.
- Both AppHosts set the reset link. The
WithUiLinksextension inMMCA.Common/Source/Hosting/MMCA.Common.Aspire.Hosting/IdentityLinkExtensions.cs:74setsPasswordReset__ResetUrlfrom 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. - Anchors re-verified against current source: MMCA.ADC Identity
appsettings.json:168(theResetUrlkey, was:115) and MMCA.Store Identityappsettings.json:118(was:114); MMCA.ADCinfra/main.bicep:2288(was:2011) and MMCA.Storeinfra/main.bicep:1961(was:1647). InMMCA.Common/CHANGELOG.md: M240 at:1270under[1.247.0](heading:1240), the localized-email entry at:1392under[1.243.0](heading:1360), and theIDistributedLockbreaking change and its fix (L91) at:1966and:1971under[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,:129to:134,:155;UserEmailResources.cs:32-35.