GeezerVison is showing github.com — id(directory_auth): pending email codes share one slot per address across purposes — cross-purpose issuance replaces the other flow's code, and a correct code presented in the wrong flow is consumed · Issue #6177 · developing-today/code
id(directory_auth): pending email codes share one slot per address across purposes — cross-purpose issuance replaces the other flow's code, and a correct code presented in the wrong flow is consumed #6177DescriptionProblem
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.purpose is a field of the single stored record (src/directory_auth.rs:92-99). issue_code unconditionally inserts over any existing record for the address (src/directory_auth.rs:167-189). So a Purpose::SignIn issuance replaces a pending Purpose::Confirm code 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::SignInEmail issues a code for any address that belongs to an account (src/directory_view.rs, SignInEmail arm). 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_code removes 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 (ConfirmEmail and ConfirmSignIn arms in src/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.rs against laptop main (worktree of f2a72d9478), run with cargo test --test probe_directory_auth on the laptop: 3 tests pass, each asserting the current behaviour —
- a
SignIn issuance at sent_at + CODE_RESEND_MS makes the pending Confirm code fail check_code;
- a
Confirm issuance likewise replaces a pending SignIn code;
check_code on a Confirm code returns the purpose and removes the record, so a second presentation (the correct flow) fails.
- Code reading (same tree): the map key, the unconditional insert, and the remove-on-match are at the file:lines above; both
directory_view callers 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
SignIn issuance never replaces, throttles, or consumes a Confirm code 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_code takes 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_auth and directory_view tests pass unchanged except where they asserted the shared-slot behaviour.
Activitydeveloping-today commented on Nov 5, 2026 dezren39 commented on Nov 5, 2026 🤖 Agent note · filed
- Agent: new-issue-creator job (new-issue-creator-code-a)
- Session / ID: new-issue-creator-code-a run, Thu 2026-11-05 03:05 CST
- Found via: filed this run
- Task: Filed this verified finding: DirectoryAuth pending email codes share one slot per address across the Confirm and SignIn purposes — cross-purpose issuance replaces the other flow's code (remotely triggerable via the unauthenticated SignInEmail action), and a correct code presented in the wrong flow is consumed before the caller can check its purpose.
- Expectation: effort s; done when pending codes are keyed per (address, purpose), a wrong-flow presentation no longer burns the code, and regression tests pin both purposes' independence plus the unchanged resend/attempt/TTL behaviour.
- Links: probe
~/git/fleet/wt-codeprobe/pkgs/id/tests/probe_directory_auth.rs on the laptop (3/3 pass against laptop main f2a72d9); body file hidden_files/issue-directory-auth-cross-purpose-codes.md in the keep-the-four-repos-healthy goal workspace.
dezren39 commented on Nov 5, 2026 dezren39 commented on Nov 11, 2026 🤖 Agent note · parked — one Codex P1 remaining (task 14041)
- Agent: repo-worker lane any-d
- State: PR fix(id): isolate pending email codes by flow #6479 rebased onto current main and pushed: head 3d20f41 (branch queue/9971-6177-directory-auth-purpose; worktree ~/git/fleet/queue-14041-6479 on the laptop). No hard-stop labels on the PR or on id(directory_auth): pending email codes share one slot per address across purposes — cross-purpose issuance replaces the other flow's code, and a correct code presented in the wrong flow is consumed #6177.
- Done this pass: Codex round-1 P2 (cross-flow test could flake on a 1-in-1,000,000 sampled-code collision) fixed in 3d20f41 — the test re-issues the sign-in code past its resend window until it differs from the confirmation code. Replied + thread resolved. Verification on the laptop:
cargo test --lib directory_auth in pkgs/id — 24 passed, 0 failed, including the patched test.
- Remaining (resume here): Codex round-2 P1 (thread PRRT_kwDOJWP47862FkWk, comment 4535651834, left open deliberately): add a
proptest for 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).
- Queue: task 14041 parked on PR fix(id): isolate pending email codes by flow #6479's CI/review condition.
dezren39 commented on Nov 11, 2026 🤖 Agent note · done — fixed and merged via PR #6479 (task 14041, lane any-a)
- Agent: repo-queue-worker lane any-a (task 14041)
- Fix: pending email codes are isolated per flow — the pending-code store is keyed by (address, PurposeKind), so Confirm and SignIn each hold an independent slot with its own code, resend window, and attempt budget; presenting one flow's code in the other neither consumes it nor counts an attempt (PR fix(id): isolate pending email codes by flow #6479, merged 410527c).
- This claim's work: rebased the PR onto current origin/main (clean), then answered the outstanding Codex P1 with the modelled property test it asked for:
pending_code_slots_are_isolated_across_flows generates 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 commented on Nov 11, 2026
🤖 Agent note · done (already_done) — task 9971, lane code-c
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|