Skip to content

feat(auth): let a person change their own password - #151

Merged
aRustyDev merged 3 commits into
mainfrom
feat/change-password
Nov 14, 2026
Merged

aRustyDev merged 3 commits into
mainfrom
feat/change-password

Conversation

@aRustyDev

Copy link
Copy Markdown
Owner

What

WP3 of the locked-out-recovery plan (issue #46, Refs, closes nothing). Profile -> Security calls POST /auth/change-password/, which Thrust did not serve, so a person given a temporary password by the operator (#149, D-038) could sign in with it and never replace it. It is served now, through the compat plane, as JSON.

A change checks the old password, applies sign-up's strength rule (D-023), writes the hash, ends every session of the account, and sets a new session in the same answer, so the caller stays signed in. No web/ change, no ALLOWED-CHANGES edit: the stock client already sends exactly this.

What the pin does (recorded as X09, from a fresh stack; the other 70 fixtures came out byte-identical)

Refusals in its order: 401 with no session; 5138 for an old password that is nothing, then for a new one; 5135 for a wrong old one (whatever else is wrong); 5021 for a weak new one. A change is 200 {"message": "Password updated successfully"} and a new session-id. After it, the session held before is a 401, the old password no longer signs in, the new one does, and changing to the password already held is allowed.

Measured on the pin and not recorded, because the fixture format holds JSON bodies and no request headers: a session without the CSRF token is a 403 CSRF Failed: CSRF token missing.; another browser's session is a 401 after the change; a form-encoded body works; a new_password that is not text, or a body that is not a JSON object, is a 500 HTML page.

D-039: six deliberate differences, for you to confirm

  1. JSON bodies only (a form post is an empty body).
  2. A body that is no object, or a new_password that is not text, is a 400 here (5138 / 5021), where the pin has a 500 page.
  3. A signed-in caller's guesses at the old password are limited. They count in the account's sign-in allowance (the signin:<email> key: one allowance for guessing a password by either door), before any hashing, and the answer is 429 with Retry-After. The pin does not limit a signed-in caller here, so a stolen session cookie can guess without end. This needs no new Worker binding.
  4. An API key cannot change a password (401, nothing changes): a key is a script's credential, and this is an account takeover.
  5. The cookies are Thrust's two; the CSRF refusal is Thrust's JSON 403.
  6. An account with no password (single sign-on) cannot change it (5135, with the hash work of any wrong guess): Thrust reports is_password_autoset as false for everyone, so the page always asks for an old password. The operator's reset (D-038) gives such an account one.

How it was checked

  • cargo nextest run --profile ci --workspace: 3726 passed (WP2: 3616). Doctests, cargo fmt --check, cargo clippy --workspace --all-targets -D warnings, and the Worker's wasm32 clippy as CI runs it: clean. check-acceptance-list.sh (and its self-test), gen-acceptance.py --check, check-deps.sh, check-web-diff.sh: clean.
  • Contract suite, main pass: 70 of 70 on native-memory, native-pg, worker-memory and worker-cf (EXPECT_MAIN 68 to 70).
  • Generative first: a core property, an exhaustive old-by-new matrix with the hash work each refusal costs, the shared allowance in both directions, and a model_ sequence against a reference of passwords and sessions with its own coverage control. The handler's 77-case matrix (11 old-password values by 7 new-password values) is checked against an expected-answer table written from the pin's Python, and it found a real bug in my first handler (a non-text old password with a missing new one must be 5138, not 5135) before it was ever recorded.
  • Controls, each run and each failing: the old password unchecked, no strength check, sessions left alive (the core tests, the handler tests, and parity_x09_change_password all fail on each), and an API key allowed (only the contract suite can kill this one). On the real server, each of the four fails the main pass on native-memory with exactly the one change-password test aimed at it (69 of 70, exit 101). They are four new rows of scripts/mutants.sh, run by hand. Three parity controls: a change that sets no session cookie, a change that ends no session, a wrong old password that is accepted.

Not measured

  • No browser drives the Security page. The form's own validation and toasts are untested here; neither the sign-up nor the sign-in journey changes a password (G-30, G-31). A journey (sign up, change the password in Profile -> Security, sign out, sign in with the new one) on both targets is the next change, in a PR of its own, so that this one does not wait on the browser cell.
  • Nothing was run against a deployed Worker. scripts/stage2-contract.sh's main pass count (59) is already behind (68 before this); I left it alone.
  • scripts/mutants.sh was run for its four new rows only, not as a whole.
  • mdbook build was not run (mdbook-mermaid is not installed here).
  • The atomicity of "write the hash, end the sessions, make a new one" is the same three writes as the operator's reset, not one transaction.

Docs: D-039, G-33 (and G-28's count and its list of unreproduced 500s), the runbook sentence in infra.md that said "until change-password exists", app.md, mutation.md, TRACEABILITY F-A03.

🤖 Generated with Claude Code

aRustyDev and others added 3 commits November 13, 2026 18:09
The operator's reset (D-038) gives a locked-out person a temporary password, and Profile -> Security is where they are meant to
replace it, but Thrust did not serve POST /auth/change-password/, so the temporary password stayed their password. It is served now,
as JSON, through the compat plane: the old password is checked, the new one must pass sign-up's strength rule (D-023), the hash is
written, every session of the account ends, and the caller gets a new one in the same answer, so they stay signed in.

The answers are the pin's, recorded from a fresh stack as X09 (the refusals in its order: no session; 5138 for an old password that is
nothing, then for a new one; 5135 for a wrong old one; 5021 for a weak new one; and the change, the session held before it ending, the
old password refused and the new one accepted at sign-in). Six deliberate differences are D-039, proposed and not yet confirmed:
JSON bodies only; a body that is no object or a new password that is not text is a 400 where the pin has a 500 page; a signed-in
caller's guesses at the old password are limited, in the account's sign-in allowance, where the pin has no limit; an API key cannot
change a password; the cookies are Thrust's; an account with no password (single sign-on) cannot change it, and the operator's reset
is how it gets one.

Tests: 16 in thrust-core (a property, an exhaustive matrix with the cost of each refusal, the shared allowance, a model against a
reference of passwords and sessions with its coverage control); 90 in thrust-compat-plane (11 old-password values by 7 new-password
values against a table written from the pin's Python, which found an ordering bug in the handler while it was being written); the
parity row and three controls; two contract tests on all four cells (EXPECT_MAIN 68 to 70). Four planted bugs (old password
unchecked, no strength check, sessions kept, an API key let in) are features of the server and rows of scripts/mutants.sh.

Not covered: no browser drives the Security page, nothing was run on a deployed Worker, and another browser's session ending, the 403
for a missing CSRF token and the pin's 500 pages are measured on the pin and not recorded (the fixture format holds JSON bodies and no
request headers). G-33 says so.

Refs: #46
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@aRustyDev
aRustyDev merged commit 76bd94d into main Nov 14, 2026
35 checks passed
@aRustyDev
aRustyDev deleted the feat/change-password branch November 14, 2026 05:18
aRustyDev added a commit that referenced this pull request Nov 15, 2026
…tests (#172)

* test(contract): port the slice's OIDC checks that the compat tests lacked

Step 5d of moving off /api/_slice: the slice's OIDC pair (`GET /api/_slice/auth/oidc/start` and `/callback`) has a Plane-shaped replacement since #163 (`GET /auth/oidc/` and `/auth/oidc/callback/`, D-040), so the pair and its six `oidc_` tests can go. #163's `compat_oidc_*` tests already cover most of what the six assert (login completes, the link decides by subject, a tampered, unknown, missing, refused or replayed state, the five ID-token tamperings, no verified email, no provisioning, a deactivated user by email and by link). Five assertions of the six were in no compat test, and deleting the six without them would lose real coverage, so they come first, while the slice route still exists to compare with. No test is added: they go into the two existing compat tests, so the main pass stays 73 of 73.

Ported:
- The OIDC session's cookies carry the attributes of a password sign-in's (Secure, HttpOnly, SameSite=Lax, Path=/, no Domain, Max-Age 30 days), a 64-hex session token and a 32-hex CSRF value. Before this, the hermetic test held Secure, HttpOnly, Lax, Path and Domain, and nothing held Max-Age for the OIDC callback.
- A different subject with another account's verified email is a different login and goes to that account (the control for "the subject decides").
- The email is matched like a password sign-in's: case and padding do not matter.
- A subject that is already linked does not get around the verified-email rule (a different code path from the three unlinked cases).
- The mock identity provider refuses an exchange whose PKCE verifier is not the challenge's (the control that shows the target's own verifier is what makes the logins work).

Controls, each a temporary mutation of one file that was reverted (the tree was clean again after each, checked), each run through the native-memory main pass. The compat test named failed at the ported assertion, read from its panic message:
- The callback's cookies live half as long: `compat_oidc_login_completes...` fails at "30 days" (Max-Age 1296000).
- The provider's email is not normalized: `compat_oidc_login_completes...` fails because the padded-email login is refused (the panic is in the helper's "a session cookie"; that login is the only one whose email is not already normalized).
- The link is made on the issuer and not the subject: `compat_oidc_login_completes...` fails at "a different subject is a different login" (and `compat_oidc_every_refusal...` fails too, earlier, because the memory adapter's links are shared by every test of the run).
- The verified-email rule is applied only to an identity not yet linked: `compat_oidc_every_refusal...` fails at "a linked subject with an unverified email" (the slice's own test failed too).
- The mock accepts any PKCE verifier: `compat_oidc_login_completes...` fails because the exchange answered 200 and not 400.

Checked: native-memory main 73 of 73 with the ports in. Not run here: the other three targets (CI runs them).

Refs: #58
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* refactor(api): delete the slice's OIDC routes and their six contract tests

Step 5d of moving off /api/_slice. #163 put Plane's routes (`GET /auth/oidc/` and `/auth/oidc/callback/`, D-040) over the same core `oidc_start` and `oidc_callback`, with `compat_oidc_*` contract tests, so the slice's pair has a Plane-shaped replacement and the owner's standing decision of 2026-11-11 applies: it goes. The previous commit ported what the six `oidc_` tests held that the compat tests did not.

Deleted:
- `GET /api/_slice/auth/oidc/start` and `/callback`, their handlers and the callback's query struct (thrust-api), and the two unused imports they leave; the two entries of `slice_auth_routes()` (so `the_slice_routes_are_gone_from_the_reserved_v1_prefix` walks 5 routes there, no longer 7) and its `no_redirect` comment.
- The six `oidc_` tests of `tests/auth/mod.rs` and their helpers (`begin`, `finish`, `assert_logged_in`, `assert_refused`, `unique_sub`, the mock-IdP import). `EXPECT_MAIN` is 67.

Changed:
- `scripts/contract.sh` registers the mock identity provider's redirect URI as `<origin>/auth/oidc/callback/`, the app's callback (D-040 says a deployment must register that one), where it was the slice's callback. The compat tests send the browser to the URL the mock hands back, and assert that it is the app's callback, so the registration is no longer a path the target happens not to look at. No deployment has a provider (G-35), so no registration moves.
- A hole found by running the mutants: G-35 records that `mutant_oidc_state_reusable` was killed at contract level only by the slice's replay test. The compat route tells a used state and a used code alike (5301) and the mock refuses a reused code too, so with the six gone the `oidc-state-reusable` row of `scripts/mutants.sh` survived: the main pass was 67 of 67 with the mutant built in. The compat refusal test now replays a used state with a second, fresh code for the same login (the mock's `authorize` can be called twice on one Location); only the used state can refuse that code, and the mutant is killed there.
- Comments and docs that named the slice's pair: flows/app.md (the route rows, the OIDC paragraph, which now describes the compat routes and their redirects with `error_code`, and the error table's OIDC cases and 502 row), contract-suite.md, defect-matrix.md (X24 names the compat tests and the three mutants), status.md (G-12, G-26 with the step and its controls, G-35's note on the state mutant), the compat OIDC module's header and the stage2 script's comment.

Not changed: `scripts/stage2-contract.sh` still expects 59 for its `main` set. It skips every `oidc_` test, so the set does not change here; the list of that set is 61 on main today, so the 59 was already out of date before this commit (set at #128). It is a guard of a manual run against a deployed Worker, and what it should now say needs a run there.

Checked on this tree:
- native-memory main 67 of 67, sweeper 3 of 3, csrfoff 6 of 6, engine 4 of 4; worker-memory main 67 of 67; worker-cf main 67 of 67 (both again after the replay assertion went in).
- clippy `--workspace --all-targets -D warnings` and `cargo fmt --all --check` clean; every script of CI's `deps` job and its self-tests pass; `sh -n` of `contract.sh` and `stage2-contract.sh` under dash in Ubuntu 24.04, with a deliberately broken script that fails the check.

Controls (temporary, restored and checked):
- The OIDC pair back in `slice_auth_routes()`: `the_slice_routes_are_gone_from_the_reserved_v1_prefix` fails ("GET /api/_slice/auth/oidc/start: not mounted (404)"), so the routes are gone and the list would notice.
- The three OIDC rows of `scripts/mutants.sh`, on native-memory main with the slice tests gone: `mutant_unverified_email` and `mutant_oidc_failure_redirect_no_code` fail `compat_oidc_every_refusal...` (exit 101); `mutant_oidc_state_reusable` passed 67 of 67 before the replay assertion, and fails `compat_oidc_every_refusal...` at "a fresh code for a state that is used" after it.

Not run here: native-pg (CI runs it) and a deploy.

Refs: #58
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* fix(scripts): stage2's main pass counts 61 tests, not 59

`scripts/stage2-contract.sh main` ends with a guard: when `cargo test` exits 0 and the passed count is not `EXPECT`, it exits 5 ("exit 0 but passed count != expected"), so that a filter that selects nothing cannot report green. `EXPECT` for `main` was 59, set at #128. The set its filters select is 61: #151 added two tests (`compat_change_password_is_for_a_session_and_not_for_an_api_key` and `compat_change_password_refuses_in_planes_order_changes_nothing_then_swaps_it_and_ends_every_session`), and nothing in CI runs this script (it needs a deployed Worker, by hand), so nothing noticed. A correct run against a Worker would have failed at the guard.

Found while finishing step 5d, which does not change this set (the script skips every `oidc_` test, before and after). Measured, not assumed: for each pass of the script, the number of tests its own filters select (`cargo test -p thrust-contract-tests --test <binary> -- --list --format terse`, the `: test` lines), next to the `EXPECT` it holds. Before: `main` 61 listed, 59 expected, flagged as differing. After: all thirteen passes agree (main 61, csrfoff 6, worker 1, bindings 3, cron 1, crontrigger 1, sweeper 3, panic 1, blast 1, email 1, engine 4, budget 1, ratelimit 1). Only `main` was wrong.

The two extra tests were found by listing the test names of the suite at #128 and of today's `main` set: the change-password pair is new; `v1_requests_are_rate_limited_per_key` is also not in the old list but is the create-limit test renamed at stage 4 (#142), so it is not an addition.

Changed:
- `EXPECT` for `main`, 59 to 61, and the header's "59 tests", with a comment in the script that says how to derive the number again and what went wrong this time.
- `docs/src/testing/techniques/contract-suite.md`: the two places that quote the count (59, and a 31 from the spike's time) say 61 and name what the pass skips.
- G-26 in `docs/src/testing/status.md` records it.

Checked: `sh -n` of the script under dash in Ubuntu 24.04, with a deliberately broken script that fails the check; the thirteen counts above.

Not run: the script itself against a Worker (it needs a deployed one). The 61 ties out against the runs of this PR: `main` is 67 tests, the script skips three `oidc_` and three `operator_` tests, and all 67 passed on `worker-cf` and on `worker-memory`. A run against a deployed Worker is what shows that all 61 pass there, and what shows whether either change-password test needs something a deployed Worker lacks.

Refs: #58
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

---------

Co-authored-by: Claude Sonnet 5.5 <[email protected]>
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant