Repository navigation
Description
Problem
In pkgs/id, DirectoryAuth keeps one pending email code per address, shared across both code purposes — and a correct presentation in the wrong flow burns the code. Three consequences, all verified this run:
-
Cross-purpose replacement.
codes: HashMap<String, PendingCode>is keyed by address alone (src/directory_auth.rs:109-113);PendingCode.purposeis a field of the single stored record (src/directory_auth.rs:92-99).issue_codeunconditionally inserts over any existing record for the address (src/directory_auth.rs:167-189). So aPurpose::SignInissuance replaces a pendingPurpose::Confirmcode for the same address, and vice versa — the earlier code, mailed up to a minute earlier, is useless long before its 15-minute TTL (CODE_TTL_MS,src/directory_auth.rs:24). -
The replacement is remotely triggerable without authentication. The sign-in flow needs no session:
DirectoryAction::SignInEmailissues a code for any address that belongs to an account (src/directory_view.rs,SignInEmailarm). Anyone who knows an address can, once per resend window (CODE_RESEND_MS= 60 s,src/directory_auth.rs:25), replace that address's pending confirmation code — repeatedly invalidating an address-confirmation the owner is mid-flow on, with a fresh mail sent each time. -
A correct code presented in the wrong flow is consumed.
check_coderemoves the pending record on a digest match and only then returns the purpose (src/directory_auth.rs:198-215). Both callers match on the purpose after the call (ConfirmEmailandConfirmSignInarms insrc/directory_view.rs): presenting a sign-in code to the confirm form (or the reverse — the user just has a code in their mail, the flows look alike) succeeds at the digest layer, burns the code, and then refuses with "no matching code". The user must wait out the resend window and start over.
Evidence (verified this run)
- Laptop probe at
~/git/fleet/wt-codeprobe/pkgs/id/tests/probe_directory_auth.rsagainst laptop main (worktree off2a72d9478), run withcargo test --test probe_directory_authon the laptop: 3 tests pass, each asserting the current behaviour —- a
SignInissuance atsent_at + CODE_RESEND_MSmakes the pendingConfirmcode failcheck_code; - a
Confirmissuance likewise replaces a pendingSignIncode; check_codeon aConfirmcode returns the purpose and removes the record, so a second presentation (the correct flow) fails.
- a
- Code reading (same tree): the map key, the unconditional insert, and the remove-on-match are at the file:lines above; both
directory_viewcallers check purpose only after consumption. - Dedup: no open or closed issue covers the cross-purpose slot (searched
directory_auth code purpose,pending code address sign-in confirm,RateAuthorisation-style title scans). The closed id(directory_auth): pending email codes are never evicted — the codes map keeps every expired code whose address never comes back #1732 covered only eviction of expired codes. The per-purpose attempt limit and resend throttle themselves work as documented — this is the shared slot, not the limits.
Why it matters
Email codes are the directory's account-recovery and address-confirmation mechanism. A single unauthenticated endpoint that can invalidate another flow's in-flight code once a minute is a denial-of-service on address confirmation (and a mail-spam lever against the address owner), and the burn-on-wrong-flow behaviour turns a routine user mix-up into a lost code with a misleading error.
Acceptance criteria
- Pending codes are keyed per (address, purpose) — or an equivalent shape — so a
SignInissuance never replaces, throttles, or consumes aConfirmcode for the same address, and vice versa; each purpose keeps its own resend window and attempt count. - A code presented to the wrong flow is not consumed: the wrong-flow refusal leaves the pending code usable by its own flow (purpose is checked before, or as part of, the consuming match — e.g.
check_codetakes the expected purpose, or the digest comparison is scoped to the purpose's slot). - Regression tests (oracle: the two purposes are independent slots) cover: cross-purpose issuance leaves the other purpose's code valid; wrong-flow presentation does not burn the code; same-purpose replacement, the 1-minute resend throttle, the 5-attempt limit, and the 15-minute TTL behave exactly as before.
- Existing
directory_authanddirectory_viewtests pass unchanged except where they asserted the shared-slot behaviour.
Activity
developing-today commentedon Nov 5, 2026
CODE-1791
dezren39 commentedon Nov 5, 2026
🤖 Agent note · filed
~/git/fleet/wt-codeprobe/pkgs/id/tests/probe_directory_auth.rson the laptop (3/3 pass against laptop main f2a72d9); body filehidden_files/issue-directory-auth-cross-purpose-codes.mdin the keep-the-four-repos-healthy goal workspace.dezren39 commentedon Nov 5, 2026
🤖 Agent note · picked up
159 remaining items
dezren39 commentedon Nov 11, 2026
🤖 Agent note · parked — one Codex P1 remaining (task 14041)
cargo test --lib directory_authin pkgs/id — 24 passed, 0 failed, including the patched test.proptestfor pending-code flow isolation per AGENTS.md L42–46 — interleaved issuance / verification / time advancement across both flows, asserting one slot's operations preserve the other slot's code, resend window, and attempt budget. Then re-run the directory_auth suite, reply + resolve, request re-review, and merge on a clean round (checks will likely still be QUEUED in the CI stall; merge on the locally verified suite per standing authority).dezren39 commentedon Nov 11, 2026
🤖 Agent note · done — fixed and merged via PR #6479 (task 14041, lane any-a)
pending_code_slots_are_isolated_across_flowsgenerates interleaved issuance / verification / time-advance operations across both flows and checks every step against an independent per-slot model, including byte-exact snapshots of the other slot's digest, sent_at, expires_at, and attempts around each operation (commit 1fab4a5; reply at discussion_r4536400962). directory_auth suite: 25/25 (was 24). The Codex P2 (collision-safe example test) was already fixed at the previous head. Codex had not re-reviewed the final head within the re-check window; the P1 thread carries the full evidence reply for its re-review.dezren39 commentedon Nov 11, 2026
🤖 Agent note · done (already_done) — task 9971, lane code-c
already_donewith that evidence; no duplicate work was done.