Repository navigation
feat(auth): the password reset by email, first half: the port, the token store and the routes, dark until a mail service is wired - #169
Merged
Conversation
… reset by email First half of email recovery (F-A03, D-041): what a reset needs under the routes, with no route and no real mail service yet, so nothing is switched on. The `EmailSender` port (ADR-0073, Q-0073.1) is optional on `Ports`, like the OIDC provider: a deployment with none cannot mail, and `MemoryEmail` is the reference implementation that tests read. Reset tokens are 256 random bits, mailed once and stored as their SHA-256 digest (migration 0017, `password_resets`; the memory and Postgres adapters; the model test of the Postgres adapter). A token is single use (`take` deletes it), expires, and a user has at most one that works: an insert replaces the user's older ones in one statement, and is refused, sending nothing, when the user's last token is younger than the cooldown (inclusive at the boundary). `find` leaves the token in place, so that a weak new password does not burn the link. The use-cases in the core: `request_password_reset` (the pin's order: this deployment can mail; the address is one; an account has it; then make a link and mail it), `reset_password` (the link is checked, then the password; the link is used up only when the password passed; every session of the account ends; nobody is signed in) and `issue_password_reset`, which a test seam will use to get a token without a mailbox. The link starts with `public_base_url`, a configured setting: never a request's Host header, which would let a forged one mail a victim a working token to another page. Controls: seven planted bugs (a link that works twice, after it expired, for another account, that a weak password burns, a weak password accepted, sessions left alive, no cooldown), each failing the core's tests. A first run of the generated model did NOT catch an off-by-one in the cooldown boundary of the Postgres adapter (`>=` written as `>`): two inserts are rarely exactly the cooldown apart. The compound op `ResetCooldown` now makes one on the boundary, and the same planted bug fails it at its first step. Measured: memory adapter tests 25 of 25; Postgres adapter suite 70 of 70 (the model, its class coverage with the ten new classes, the schema snapshot, the digest-length control); core tests 13 of 13; workspace clippy (native, and the Worker's wasm32) and fmt clean. Not measured: the routes (next commit), the contract suite, any real mail. Refs: #46 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…ail service is wired Second half of email recovery (F-A03, D-041). `POST /auth/forgot-password/` and `POST /auth/reset-password/<uidb64>/<token>/` are the two routes behind the stock app's "Forgot your password?" link; the app's own forgot-password page already posts JSON and its reset page is a native form, so the web needs no change. Both were measured on the pinned Plane first (a fresh oracle, an SMTP host set in its instance configuration for the request rows and a link made in its Django shell for the form rows) and recorded as X10-dark, X10 and X11. The request answers 5025 to everything without a mail service, then 5005, 5060 and the message; the form answers every outcome with a 302 and signs nobody in. Recording found two things the source had not said: a uid that is not text is INVALID_PASSWORD_TOKEN, not EXPIRED_PASSWORD_TOKEN; and a JSON body is no password, because the pin reads only the form. The pin's own link lifetime is an hour (PASSWORD_RESET_TIMEOUT = 3600), which I had first taken for Django's three days. It is dark: no composition root wires a mail service yet (the SMTP adapter is E2, the Worker's `send_email` binding E3), so every deployment answers 5025 and says `is_smtp_configured: false`, and the app keeps drawing the "ask your admin" line. The link needs a configured `THRUST_PUBLIC_BASE_URL`, never a request's Host header. The contract targets have no mailbox, so a test route `POST /internal/issue-password-reset` (behind `THRUST_TEST_ROUTES` and the admin token) returns the token a mail would carry; with it the reset form is exercised against every adapter's token table, Postgres included, on all four targets. Harness: a world that can mail, the pin's 302 projected as the 302 it is (not D-022's JSON) and its form posted as a form, a check that a reset sets no cookie, and a replay that mints Thrust's own link after the fixture's sign-up. X10 and X11 join the acceptance list (59 rows). Controls: eight new scripts/mutants.sh rows (each killed, exit 101, by the contract test aimed at it), two compat mutants, and three parity controls (a cookie, a code-less redirect, a mutated recording). The recorded X11 fails six of the seven core mutants; the recorded S01 fails the flag one. Measured: contract 76 of 76 on native-memory, native-pg, worker-memory and worker-cf; compat crate 894 of 894; whole workspace 3928 passed; doctests, fmt, clippy (native and wasm32) and all nine guard runs of the deps job (dependency graph, topology and its self-test, Plane 500 and its self-test, acceptance list and its self-test, placement, and the web diff) clean. Not measured: any real mail, a deployed Worker, a browser journey of the two pages, the whole of scripts/mutants.sh, and this change's CI. Refs: #46 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The owner confirmed the nine differences of the password reset by email from the pin (the token is stored and used up, and a new request replaces the old link; a cooldown per account; a deactivated account is mailed nothing and told it was; a configured base URL and a percent-encoded address in the link; the mail is sent in the request, so a failing mail service is a 500; a plain-text mail; a relative redirect; EXPIRED_PASSWORD_TOKEN never answered; no set-password and no email code) on 2026-11-14. Refs: #46 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This was referenced Nov 14, 2026
aRustyDev
added a commit
that referenced
this pull request
Nov 15, 2026
…s stale (#181) `scripts/contract.sh` and `scripts/stage2-contract.sh` each exit 5 when the number of tests that passed is not the number they expect, but only when they are run. Most of contract.sh's passes run in CI cells; `blast`, `budget` and `engine` run in none (contract-all.sh has nine passes and not those, and only mutants.sh runs the last two, against broken builds); and stage2-contract.sh needs a deployed Worker. Its `main` count was 59 until 2026-11-14 while the suite had listed 61 since #151, and #169's three tests made it 64 the same day. Nothing noticed. `scripts/check-contract-counts.sh` reads every arm of both scripts (13 in stage2, 10 in contract.sh), runs the arm's own filters through libtest (`cargo test -p thrust-contract-tests --test <bin> -- --list --format terse <filters>`, which needs no server and no environment), counts the lines that end in `: test`, and compares. It copies no filter, so a filter cannot drift from its count. It fails closed with exit 2 on an arm it cannot read, a different number of arms read than written, no arm at all, a count that is not a number, an `EXPECT_` variable with no value or two, a listing that fails, and a filter that selects nothing (libtest prints nothing and exits 0 for that). The self-test (a step of `deps`, no compile) runs it on 16 worlds with a fake lister, each read to be refused for the reason it names: a count one too high and one too low, a filter that selects nothing, a failing listing, a script with nothing to read, an arm with no count, a variable with none and with two, the default arm of contract.sh read as `main`, one pass asked for alone. The real run (a step of `hermetic`, after the suite is built) ends with a control on the real stage2-contract.sh with its `main` count made wrong, which must be refused. Shown on the real suite: all 23 arms agree today (stage2 `main` 64, contract `main` 70, `bindings` 3 and 5), and renaming one test out of `sweeper_` makes four arms fail with exit 1 (stage2 `main` 65 for 64 and `sweeper` 2 for 3, contract `main` 71 for 70 and `sweeper` 2 for 3). The file was restored and compared. The self-test passes under dash on this Mac, under the Mac's sh, and in an ubuntu:24.04 container (dash with GNU sed and grep). The prose that had rotted in stage2-contract.sh is fixed with it: its usage line named 6 of its 13 passes, its header said `bindings` runs 5 tests where it runs 3, and `crontrigger`, `blast` and `ratelimit` had no entry. evidence-and-controls.md and contract-suite.md now say what enforces the rule they state, and status.md no longer says the count "has not been kept up". Not run here: the new `hermetic` step on a runner. `cargo test -p thrust-contract-tests` unifies features differently from `--workspace`, so it may rebuild some dependencies there; the job's timeout is 30 minutes. Refs: #58 Co-authored-by: Claude Sonnet 5.5 <[email protected]>
This was referenced Nov 15, 2026
Closed
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The first half of email recovery (F-A03): the two routes behind the stock sign-in screen's "Forgot your password?" link, built on a new optional
EmailSenderport and a single-use token store, shipped dark.POST /auth/forgot-password/asks for a link.POST /auth/reset-password/<uidb64>/<token>/is the form the link leads to.Refs #46 (it does not close it).
No mail service is wired in any deployment yet (the SMTP adapter is E2, the Worker's
send_emailbinding is E3), so every deployment answers the requestSMTP_NOT_CONFIGURED(5025), as the pin does withoutEMAIL_HOST, and/api/instances/saysis_smtp_configured: false. The app keeps drawing the "ask your admin" line (D-037, D-038) and not the link. No web change: the app's forgot-password page already posts JSON and its reset page is a native form, soweb/ALLOWED-CHANGESstays at its two files.The plan, and where this PR sits
EmailSenderport, the token table, the two routes,is_smtp_configuredfrom configuration, the test seam, the pin recordedlettrefor the self-hosted set, proved against a local mail sinksend_emailbinding, wired inwrangler.deploy.toml, and a real send on staging: needs the owner's sender domain and an explicit go-ahead before anything is sentWhat is already decided and was not re-asked: Q-0073.1 and ADR-0073 (an
Emailport, Cloudflare Email Sending on the Worker side,lettreSMTP for self-hosting). A real send through the deployed Worker's binding was already made once (spike 0002 step 10, 2026-10-24): the binding accepted it and an unowned sender was refused; delivery to a mailbox was never confirmed.The pin, measured first
Recorded on a fresh oracle as
X10-dark(3 exchanges),X10(6) andX11(14); the other 71 fixtures came out byte-identical; the acceptance list is 59 rows.forgot-passwordwith no SMTP host answers 5025 to everything (even a missing address); with one (set in its instance configuration for the rows, removed after): the message, 5060 for an address nobody has, 5005 for a bad, missing ornullone. It takes a form body as well as JSON.reset-passwordanswers every outcome with a 302, never signs anyone in, and reads only the urlencodedpassword: a JSON body is "no password". A weak password leaves the link working. After a reset the link is used up, the old password is refused, the new one works, and the session held before it is over.INVALID_PASSWORD_TOKEN, notEXPIRED_PASSWORD_TOKEN; and the pin's link lifetime is an hour (PASSWORD_RESET_TIMEOUT = 3600in the fork's settings), which I had first taken for Django's default of three days.D-041 (owner confirmed 2026-11-14): how Thrust differs
password_resets, migration 0017) and used up, where the pin's is stateless: a new request replaces the older link.THRUST_PUBLIC_BASE_URL, never the request's Host (a forged Host would mail a victim a working token to another page); the address in it is percent-encoded.EXPIRED_PASSWORD_TOKENis never answered. 9.set-passwordand the email code are not built.Not a difference, kept as the pin has it: the form says whether an account exists (
USER_DOES_NOT_EXIST), as the pin's sign-in does, so it is not made uniform.Tests and controls
password_reset.rs, 13): 5 deployments by 6 addresses, 30 worlds against the pin's order; 7 links by 3 passwords, 21 worlds, with the hash work of each and what a refusal leaves; the cooldown at 6 ages and the lifetime at its boundary to the second; a generated loop of any address and any strong passphrase through the mail.tests/reset.rs, 4) and the recorded rows (parity_x10_*,parity_x11_*, with three parity controls: a cookie, a code-less redirect, a mutated recording). The harness learned: a world that can mail, the pin's 302 projected as the 302 it is and not as D-022's JSON, its form posted as a form, a no-cookie check, and a replay that mints Thrust's own link after the fixture's sign-up.EXPECT_MAIN76): the dark request, the whole reset against each adapter's token table (Postgres included) through the test seamPOST /internal/issue-password-reset(behindTHRUST_TEST_ROUTESand the admin token, which no deployment turns on), and a link for its own account and its replacement by a newer one.scripts/mutants.shrows, run by hand onnative-memory, each killed (exit 101).>=→>in the Postgres adapter's cooldown, because two random inserts are almost never exactly the cooldown apart. A compound op now sends one request on the boundary, and the same bug fails it at its first step.Measured
scripts/contract.sh <target> main,native-memory,native-pg,worker-memory,worker-cfworker-memoryneeded one re-run: the first pass failed (16 of 76) while the Mac slept mid-run (power log: maintenance sleep 14:46 to 15:13; the Worker's log shows ~15 min requests), and the re-run alone was 76 of 76cargo nextest run --profile ci --workspace-p thrust-compat-plane)cargo test --doc,cargo fmt --check, clippy native and wasm32, and the deps job's guards (dependency graph, topology and its self-test, Plane 500 and its self-test, acceptance list and its self-test, placement) and the web diffscripts/mutants.shrows by handNot measured
scripts/mutants.shas a whole (its eight new rows by hand),mdbook build, and this PR's own CI.Files
crates/thrust-ports(EmailSender,NewPasswordReset),thrust-core(password_reset.rs, config,Ports.email, 7 mutants),thrust-adapters-memory(MemoryEmail, the table),thrust-adapters-postgres(migration 0017 and its methods),thrust-adapters-selfhosted/tests(model, schema snapshot),thrust-compat-plane(reset.rs, the flag, the codes, tests, three fixtures, the harness),thrust-api(the test seam),thrust-serverandthrust-worker(configuration; the sender staysNone),thrust-contract-tests,scripts/contract.shandmutants.sh,tools/compat-record(the recorder steps and the acceptance rows), and the docs:DEVIATIONS.md(D-041; D-037 amended),docs/src/testing/status.md(G-37),TRACEABILITY.md,QUESTIONS.md,docs/src/architecture/infra.md(a runbook section),app.md,mutation.md.🤖 Generated with Claude Code