Skip to content

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

Closed

Description

@dezren39

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:

  1. 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).

  2. 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.

  3. 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.

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/triageQueue packet kind: verify, reproduce, and route this item
    source/creatorFiled by the new-issue-creator job
    priority/normalOrdinary priority (the default)
    on Nov 5, 2026
  2. developing-today commented on Nov 5, 2026

    @developing-today
    Contributor
  3. added
    app/idPackage/app: id (pkgs/ or apps/ in this repo)
    on Nov 5, 2026
  4. dezren39 commented on Nov 5, 2026

    @dezren39
    MemberAuthor

    🤖 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.
  5. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed on Nov 5, 2026
  6. dezren39 commented on Nov 5, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up

  7. 159 remaining items

  8. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · parked — one Codex P1 remaining (task 14041)

  9. added
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    status/parkedDeliberately paused with a recorded resume condition
    and removed
    queue/claimedQueue worker lifecycle state
    on Nov 11, 2026
  10. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    🤖 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.
  11. removed
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    work/assignedQueue worker lifecycle state
    on Nov 11, 2026
  12. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done (already_done) — task 9971, lane code-c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

app/idPackage/app: id (pkgs/ or apps/ in this repo)effort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/lowNice to have; do when convenientsource/creatorFiled by the new-issue-creator jobstatus:donetask/pr-shepherdQueue packet kind: shepherd an open PR or PR set to merge

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions