oliver-zehentleitner / maity
auth: 'forgot password' — reset by mail, compatible with mail as second factor (contract first)
tsk-pk755085ctff Done An agent
Owner request (Oliver, req-vw42qtpb5ktv answer, 2026-11-08): there is no "forgot password". The sign-in link by mail (§2.6.3) is not the answer: Oliver switched it off on purpose and wants mail as the second factor instead (§2.8.5; the sign-in link is not offered while the second factor is mail). And POST /auth/password needs current, so a human who forgot the password cannot change it.
Step 1, a design note (no code), for a contract ask to Oliver through me:
- Flow: "Forgot password?" on the login page → address → always
202(no account enumeration, same timing rules as §2.6.3) → a single-use reset link by mail (short expiry, voids older links) → page to set a new password. - Second factor: after the reset, a human with a second factor still has to pass it at the next sign-in. With mail as second factor both arrive in the same mailbox — say plainly what that means and what we do about it (e.g. TOTP if set wins; recovery codes; reset ends every session; security notice to the address and in the account record §18.4; rate limits §2.6.4).
- What it does to sessions, devices, agents' credentials (proposal: ends every human session, leaves agent credentials alone — say why).
- Instance switch: admin can turn it off (like
email_link); mail settings must be complete. - Contract sections to change, routes, error codes, i18n keys, and the tests (enumeration timing, single use, expiry, second factor still required).
Boundary: design note only until Oliver answers the contract ask; then hub + web + contract. No change to existing sign-in methods, no weakening of §2.8. After #1516 and tsk-g83nf2q1j728.
Notes
An agent · Nov 8, 2026, 17:37 UTC
Forgot password design, part 1/5
Design note for "Forgot password?" (maity-coder-claude-005#zwhq). No code yet. Read against docs/api.md on main (§2.1, §2.3, §2.6, §2.8, §18.4–18.6).
What the mailbox gets today, and what a reset changes
- A sign-in link already makes the mailbox a way in, but a weak one. The session it makes is not in good standing: it cannot end the human's other sessions, enrol TOTP or change the address (§2.6.5, §2.3).
- A password reset by mail is stronger. Whoever reads the mailbox chooses a password, signs in with it, and holds a session in good standing (§2.6.5 "signed in by password"). From that session they can enrol TOTP of their own (§2.8.1: the proof is the password) and change the address (§2.6.3).
- So an agent with a mail connector (§2.3) could take the account over. The design below closes that per human and per instance, and keeps the second factor where one exists.
An agent · Nov 8, 2026, 17:37 UTC
Forgot password design, part 2/5
1. Flow
- On the login page, "Forgot password?" asks for an address:
POST /auth/password-reset {address}.
- It always answers
202 {expires_in: 1800}. The lookup and the send run in the background, after the answer, exactly as in §2.6.3: the body, the status and the timing are the same whether or not an account exists. There is no pending cookie, because the reset does not sign in. - Sec-Fetch-Site and transport rules are as §2.6.5.
- A mail goes out only when all of these hold:
- the address is a human's verified address;
- the account is not disabled and has a password (accounts without one: the accounts design, pending);
- the human's own switch is on (point 2);
- the instance setting is on (point 4).
- The mail has subject
[Maity] Reset your password. It contains:
- the link
<public>/sign-in/reset#<token>. The token stands in the fragment, so it reaches no log and no Referer, as in §2.8.8. It is valid for 30 minutes and single use; - when, from which browser and OS, and from which address the request came;
- "If you did not ask for this, ignore this mail; your password stays."
- No six-digit code: the reset does not sign this browser in, so the link may be opened on any device, and nothing guessable has to exist.
- The page reads the token from the fragment and removes it from the address bar.
POST /auth/password-reset/check {token}answers{display_name, handle, code: "totp" | null}.- The page "Set a new password for <name> (<handle>)" shows a field for the TOTP or recovery code where
codeis set. POST /auth/password-reset/complete {token, new, code? | recovery_code?}answers 200. It signs nobody in. The page links to the login with the address filled in, so the next sign-in runs §2.8.2 as always.
- The token works like §18.6: an HMAC with
MAITY_MAIL_SIGNING_KEY. The hub storessha256(nonce)and the expiry, and the token names the account's password generation. Any password change moves the generation (a reset,POST /auth/password), so every older reset link dies.
- A new request voids earlier unused links from the same source address only, as §2.6.3 does for sign-in links, so nobody elsewhere can void the link the human is about to use.
- An invalid, expired or used token, or one of a moved generation, is
code_invalid, never which of the reasons.
- On the login page, "Forgot password?" asks for an address:
An agent · Nov 8, 2026, 17:37 UTC
Forgot password design, part 3/5
2. Second factor, and mail as the second factor
- TOTP enrolled (any setting):
completeneeds a current TOTP code or a recovery code. A wrong code iscode_invalidand counts as §2.8.6 counts (10 per 15 minutes per human). So the mailbox alone changes nothing, not even the password. The next sign-in still asks for TOTP. - `second_factor: email`, no TOTP: here the mailbox is the second factor. A reset by mail plus the mail factor would be the mailbox twice, which is exactly why §2.8.8 rule 3 switches sign-in links off. I see four options:
- (a) Recommended: self-service is not offered for that human. The request still answers 202 (no enumeration), and the mail says: "For this account a password reset needs an instance admin. Ask one; set up an authenticator app to reset on your own next time." The admin path then works like §2.8.3:
-
POST /admin/users/{id}/password-reset {reason}: scopeinstance:admin, human, step-up.
- It mails the same link to the human's verified address, and the reset takes effect only when the human uses it.
- The dashboard tells the admin to confirm the request with the person by another channel first.
- The admin's own account goes through the operator:maity-hub password reset --handle(asmaity-hub second-factor reset).
- Mailbox plus a person, so §2.8 is not weakened.- (b) A 24-hour hold. The reset is announced in every live session, with "Cancel" from a session in good standing. But a human who forgot the password usually has no live session, so it mostly delays the honest human.
- (c) Accept the mailbox as enough and say so. This weakens §2.8.8, against the card's boundary.
- (d) No reset at all under
emailwithout TOTP: only the operator. Too hard for a team instance. - `optional` / `required_admins` / `off`, no TOTP: the mailbox alone resets the password, as on most sites. It is guarded by the human's switch below.
- The human's own switch (like
email.sign_in_link, §2.6.3):email.password_resetin the notification settings (§18.4),trueby default. - The dashboard shows it beside the sign-in-link switch, with the same sentence: "Turn this off if an agent or anyone else can read this mailbox: whoever reads it can set your password." §2.3 gets the matching bullet.
- Off: no mail, and the request still answers 202.
- Open question for Oliver: one switch for both ("the mailbox is a way in") or two keys. I recommend two keys: the reset is the stronger way in, and a human may want the link off but the reset on.
- Told:
- The account record
password_reset {ip, browser, os}is asecuritynotification (§18.1). - The security mail goes to the address at once, whatever
email.kinds.security.modesays, likesecond_factor_changed. - The other sessions are ended (point 3), so the mail and the record are what remain.
- A request that was never used writes nothing, so anonymous requests cannot fill the account record.
- TOTP enrolled (any setting):
An agent · Nov 8, 2026, 17:37 UTC
Forgot password design, part 4/5
3. Sessions, devices, agents
- The reset ends every session of the human (
ended_by: password_reset, a new value of §2.6.5), second-factor and enrolment sessions included. It voids open device codes, sign-in links and codes, and older reset links, asPOST /auth/passworddoes today (§2.6.5 "Ended with the password"). - Why: whoever reset it either forgot the password or suspects someone has it; a session made with the old password should not outlive it.
- The cost under the mailbox-agent case: a mailbox holder ends the human's good-standing sessions. That is why the per-human switch and the TOTP/admin rules above exist.
- Agent credentials stay. They are not derived from the password (§2.2), and ending them stops the team without stopping anyone who holds the password. A human who suspects more revokes agents on the Agents page; the security mail says so ("end your agents' access if you did not do this").
POST /auth/passwordbehaves the same way today. - The device cookie (`maity_device`) stays. It authenticates nothing (§2.6.5).
4. Instance switch
MAITY_SIGN_IN_PASSWORD_RESET/password_resetinGET, PATCH /admin/settings/sign-in(§2.6.6), defaulttrue.GET /auth/methodsgainspassword_reset:trueonly with the setting on and the mail settings complete and enabled (§16.2). It is offered undersecond_factor: emailtoo: TOTP humans reset on their own, the others get the admin mail of (a).missinggainsswitched_off/mailfor it, asemail_link.- Turning it off voids open reset links at once, and
completeanswersforbidden,method_disabled.
- The reset ends every session of the human (
An agent · Nov 8, 2026, 17:38 UTC
Forgot password design, part 5/5
5. Contract, routes, codes, i18n, tests
Contract: a new §2.10 "Human: a forgotten password", plus changes to:
- §2.1: the table line and the link;
- §2.3: the mailbox bullet;
- §2.6.1:
password_reset; - §2.6.4: the limit rows. The same per (address, source) and per-source limits as
email-link. The mails count againstsign_in_max_per_hour, not the security budget.check/complete: 10 per minute per source, shared with the login; - §2.6.5: the
ended_byvalue; - §2.6.6: the setting and
missing; - §2.6.7: "Forgot password?" on the login page, and in the paused-password answer beside the sign-in link;
- §2.8.3: the admin password reset, and the operator command;
- §2.8.8: the rule for
emailwithout TOTP; - §2.9: the record in the export;
- §16.11: the dashboard path
/sign-in/reset; - §18.1: the security row;
- §18.4:
email.password_reset; - §18.5: the two mails.
Routes:
POST /auth/password-reset;POST /auth/password-reset/check;POST /auth/password-reset/complete;POST /admin/users/{id}/password-reset;- the CLI command
maity-hub password reset --handle.
Codes: no new error code.
code_invalid: token or TOTP;invalid,new: too_short;forbidden, withmethod_disabledandhumans_only;rate_limited;- admin path:
409 mail_not_configured/409 address_unverifiedas §2.8.3;forbidden,own_account.
i18n keys (web): the login link; the request page and its "if this address belongs to an account" answer; the reset page (title, the code field, "use a recovery code"); success; invalid link; the switch and its warning; the admin dialog; the two mails (hub catalogue).
Tests (hub):
- the answer is the same for an unknown address, a known one and a switched-off one: status, body and timing, with the lookup after the answer;
- single use;
- expiry;
- a generation move kills older links;
- same-source voiding only;
- TOTP required and counted;
emailwithout TOTP sends the admin mail and never a link;- every session ended, agent credentials untouched;
- record and security mail;
- limits and the instance cap;
- the instance switch, and incomplete mail settings;
- the admin path: step-up, own account, no address;
- web e2e: request → link → set → sign in with the second factor.
Boundary kept: the existing sign-in methods are unchanged, and §2.8 is not weakened: TOTP stays required, and under
emailthe mailbox alone never suffices.Lotse · Nov 16, 2026, 18:44 UTC
Board grooming 2026-11-16: complete. Contract #1648, hub #1684/#1685 and web #1714 are all merged.