Repository navigation
Recovery codes and seed-preserving password reset - #1470
Conversation
|
Maple development preview: https://7e7ca68d.maple-ca8.pages.dev Commit: Uses development API, billing, flags and PCR configuration. Cloudflare Access applies. |
…nt password boundaries The backend accepted any password string - including the empty string - at every user-account password boundary. Platform routes already validated 8-64 via the validator crate, but /register, /password-reset/confirm and /protected/change_password did not. Add a shared password policy (8-64 Unicode characters, counted per character like the Agent client) and enforce it before any database or seed-wrap effect at those three boundaries. Login is intentionally not length-validated: a wrong-length attempt is an authentication failure, and existing accounts (including short-password ones) keep working. Rejects return 400 with a specific message (PasswordTooShort / PasswordTooLong) so clients can surface the reason. A rejected reset does not consume the one-shot reset request; a rejected password change leaves the current credential intact. Covered by unit tests plus disposable-database route tests proving rejection without side effects on register and change_password. The transport-v2 password-reset completion route lands with the recovery credentials work (#1470) and will pick up the same policy there.
|
Follow-up from #1477: once that PR merges, this branch should pick up the same server-side password policy for The new shared policy lives in validate_password(&request.new_password)?;( |
…nt password boundaries The backend accepted any password string - including the empty string - at every user-account password boundary. Platform routes already validated 8-64 via the validator crate, but /register, /password-reset/confirm and /protected/change_password did not. Add a shared password policy (8-64 Unicode characters, counted per character like the Agent client) and enforce it before any database or seed-wrap effect at those three boundaries. Login is intentionally not length-validated: a wrong-length attempt is an authentication failure, and existing accounts (including short-password ones) keep working. Rejects return 400 with a specific message (PasswordTooShort / PasswordTooLong) so clients can surface the reason. A rejected reset does not consume the one-shot reset request; a rejected password change leaves the current credential intact. Covered by unit tests plus disposable-database route tests proving rejection without side effects on register and change_password. The transport-v2 password-reset completion route lands with the recovery credentials work (#1470) and will pick up the same policy there.
91d4487 to
18ca345
Compare
AnthonyRonning
left a comment
There was a problem hiding this comment.
This is in good shape. The backend design, reset transactions and reset UI all look right to me. Most of the notes below are about the last step: making sure a user really ends up with a working code. This is from reading the code at 18ca3456; it hasn't been run.
Before merge
- Feature flag. Add a key to
FEATURE_FLAGSand gate the recovery section inSecuritySettings.tsxwithuseFeatureFlag. Frontend only: the endpoints stay live, and the reset flow stays unflagged because it runs logged out and enrolled users need it. - Native pass on the reset flow. It goes live for everyone on merge, so it needs one run on macOS and a phone first.
Before the flag goes on
-
"Save text file" probably doesn't work on macOS, iOS or Android.
downloadCodeis a plain<a download>blob. Tauri sets no download handler by default and we don't add one, so wry cancels it on WebKit (src/wkwebview/navigation.rs:68-73, wry 0.57), and neither wry nor our Android project handles downloads.click()doesn't throw, so nothing tells the user it failed, and they can still tick "I've saved this". This comes from the source, so please confirm on a Mac. Either make it work natively or hide it there and rely on Copy. -
Confirm the code before Done. Consider having the user paste the code back. It needs no backend change, and it catches a failed save that would otherwise only surface when they need the code.
-
Check the checksum on the client.
normalizeRecoveryCodeonly checks syntax, so one wrong character reaches the server. The server correctly leaves the request alone, but the generic 400 wipes the form and tells the user to request a new email. Verifying it locally and throwingRecoveryCodeFormatErrorwould keep the form intact. It's the first 5 bytes of SHA-256 over the version byte and secret, andhashSecretalready usescrypto.subtle. A show/hide toggle on the masked field would also help anyone typing from paper. -
Rate limit the reset proof. Nothing limits email code guesses. This predates the PR, but
verify_password_reset_proofnow gives us one place to fix it. It has to live in the enclave, because the edge only sees/v2/request, we have no client IP, and the inference limiter is per process. My suggestion, both in Postgres:- Allow 5 wrong codes per request, counted against open requests matching the submitted secret, so an attacker can't burn the real user's request.
- Cap reset requests at about 5 per account per hour. Past that, return the same generic response and send no email.
A follow-up is fine if you'd rather keep this PR focused. The platform reset has the same gap.
Small
- The reset form has no 64-character limit, so since #1477 a longer password gets the same form wipe and a misleading message.
- The "recovery code used" email tells the reader to change their password, but if someone else used the code, they're locked out. It should send them to a reset with their code, then support.
- The settings copy should say recovery also needs access to the account email.
enrolled_atreally means last issued, so considerissued_atbefore the SDKs publish.- Nits: the
#[path = "recovery_smoke.rs"] mod local_flow_smokerename, thedebug_assert!(false)arm inpassword_reset_v2_complete,RecoveryCode::generatereturning aResultthat's alwaysOk, and thetokio::join!race tests over sync diesel. The real threads in the DB tests are the better pattern. - MaplePrivacyLabs/code-docs#108 needs a refresh or closing. It still has the old baseline and test counts, and doesn't cover this PR.
Deploy note: run both migrations before the new enclave, because every seed-wrap read selects the new columns. The old binary is fine on the new schema.
|
@AnthonyRonning Addressed the code feedback in
Opened #1486 for database-backed email-code guess budgets and reset-email caps, including platform resets. Refreshed the architecture notes' stale status and backend/client contracts while keeping the backend focus and preserving historical evidence. Validation passed locally: frontend/web and native Rust lanes, both SDK/package lanes, 97 disposable-DB tests including the real-thread races, encrypted recovery HTTP smoke, TypeScript API and Rust account integration checks, and actual Linux desktop save/cancel/confirmation checks with a fixture API. The PR description has the exact counts and ignored-test boundaries. The macOS and phone reset-flow runs you requested are still outstanding; we haven't treated Linux checks as a substitute. The migration-before-enclave ordering is recorded in the PR description. |
|
Okay the flow seemed to work really well! I wonder if we should go ahead and change the email reset code to be either a UUID or something longer. The 8 digit code for verification might have been okay at one point but I don't think I like the idea of it being brute forcable as we rely on it more. And DB-saved rate limits only go so far. Edit: Or maybe they go far enough anyways. Just speaking out loud here. We can chat about it more if you have thought about this. |
AnthonyRonning
left a comment
There was a problem hiding this comment.
Final pass at 4f0f454c: no blockers. This was a security read of the backend, both SDKs and the Research client, and the disposable-database suite passes at this head (97 tests, 43 of them recovery). The recovery wrap follows the same credential-bound seed-wrap design as password and OAuth, and the submitted code is the only thing that opens it. Threat-model notes are on MaplePrivacyLabs/code-docs#108.
Thanks for the patience on this one, Alex.
Small things, none blocking the merge
- The new reset flow pins the emailed code to exactly 8 characters.
PasswordResetFlow.tsx:83tests/^[A-Z0-9]{8}$/and:218setsmaxLength={8}; the released form already haspattern="[A-Z0-9]{8}". Please relax the new check to a range (say 8 to 32 of[A-Z0-9]) before the next Research release, so the server could change the length later without waiting out old clients. No change to code generation. - Paste extraction only tries the first
MPLRC1match (recoveryCodeInput.ts). A notes file with an old code above the current one submits the old one. It is well formed, so the server consumes the reset request and the user has to ask for a new email. Pasting the same file fails the same way. Suggest checking every match: accept when exactly one distinct code passes the checksum, and ask for just the code when more than one does. Fine as a follow-up. disposable_db_tests.sh --redo-latest Nredoes the newest migration N times, not the last N.diesel migration redo -n "$redo_count"does what the script's comment describes. Both recovery migrations were cycled by hand with an enrolled row present and pass, so nothing is missing for this PR.
Reset code length
Following up on my comment above: I'd leave the code at 8 characters. With the limits in #1486 a guesser gets a few hundred tries a day against 36^8 codes, which is enough. The first bullet just keeps the option open.
Rollout order
Both migrations, then the enclave, then the Research release. The new reset screen calls only the V2 routes, so a client that ships before the enclave would break password reset. The phone reset-flow run is still open before the next mobile release. As in the earlier review, #1486 comes before the recovery flag goes on.
4f0f454 to
d3a4bf0
Compare
Validate recovery-code checksums before transport, hide mobile file export, align password validation, and clean up recovery metadata and race tests.
d3a4bf0 to
1a23f43
Compare
|
I'm rolling this out now. I'm not sure why email settings were changed here, there's a handful of things that need to be cleaned up from this. |
Summary
Adds opt-in recovery codes so users can reset their password while preserving their account seed and encrypted data. Users without a usable code can explicitly choose the existing destructive reset behavior.
Consolidates and supersedes #904 (backend) and #1435 (SDKs), imported as separate squash commits. The branch is rebased on
masterata1839576, including the shared password policy from #1477 and the reset limiter from #1546. Backend, SDKs, Research integration and lifecycle emails can be reviewed together here; the original PRs retain their discussions.Changes
issued_atfor the active code's issuance, including replacement. Research consumes the in-tree SDKs; this PR does not publish them.recoveryflag gates the Security settings section. Backend endpoints and the logged-out reset flow remain available independently. A late flag-off response cannot discard a code already being issued or confirmed.RecoveryCodeFormatErrorlocally. The backend keeps character normalization, its byte cap, literal prefix/exact lengths, non-ASCII rejection, checksum and padding checks. Local code errors retain verified proof; a real server 400 clears the verified form.support@maple.ai; sender defaults and verification URLs use the updated domain without rewriting stored sender settings. Remove the infallible generator'sResult, the unreachable debug panic, and the smoke-module alias. Recovery route races now run on separate OS threads so synchronous Diesel work can overlap.Local validation
d3a4bf0d. That verified baseline passed strict Clippy, 1,193 unit tests (106 ignored), 102 guarded database tests including 44 recovery tests, and encrypted recovery HTTP smoke including the reset-email cap. Both recovery migrations were rolled back and reapplied with the corrected helper.Earlier evidence at
4f0f454c: 17 TypeScript API integration tests, Rust account-management integration (7 passed, 3 ignored), Research Rust (93 passed, 1 model-backed OCR test ignored), and Linux desktop fixture checks for native Save/Cancel, exact saved text/mode0600, checksum-error retention, whole-file confirmation and show/hide. These are historical checks, not new native-runtime proof for the rebased heads.Earlier Chromium/Linux Tauri MDE checks at
82f4b8f3exercised real local account/reset proofs, clipboard readback, reload/relaunch, preserving and destructive reset, and lifecycle mail capture. Encrypted conversation metadata and saved instructions survived preservation and were removed by destructive reset. Those are historical full-app checks.Rollout and remaining evidence
2026-10-28-000000_recovery_credential_kindand2026-11-02-000000_recovery_wrap_use_trackingbefore starting the new enclave, since seed-wrap reads select the new columns. No deployment or shared migration is performed by this PR.For MDE testing, keep the local backend running and force the management flag from the Maple checkout when launching the desktop: