Skip to content

[Bug]: auth low-severity flow hardening and dead passkey/external-lookup code #465

Closed

Description

@jimhoyd

Runtime revision and environment

main at d939969 (static source review; not executed against a deployment). Node/OS/deployment: not applicable.

Minimal reproduction

Reported by review, not independently reproduced. Grouped because each item is low severity. Exploit-level detail is intentionally omitted per SECURITY.md.

  • Raw session token stored in a flow record. The OIDC link flow stores the caller's session token (encrypted) in auth_flows (packages/auth/src/auth-flows.ts lines 101 and 133). packages/auth/SECURITY.md:17 says session tokens are stored only as hashes.
    • Fix: store a reference (session hash plus account id) and re-authenticate from the cookie on return, or narrow the SECURITY.md claim.
  • Flows consumed before the browser binding is checked. consumeFlow runs before checkBinding (auth-flows.ts lines 114-117; also 173, 188, 224), so a request from the wrong browser still burns the flow.
    • Fix: check the binding before consuming, or consume atomically only when the binding matches.
  • Email change reveals address availability before the second factor. email_unavailable is returned before the factor is consumed (packages/auth/src/auth-store.ts lines 1583-1584).
    • Fix: verify the factor first, then report availability.
  • Dead code.
    • advancePasskeyCounter (auth-core.ts:1380) and the store's advancePasskey case (auth-store.ts:1130, which updates a counter without an account check) are called only from tests.
    • findExternal (auth-core.ts:1325) is called only from tests.
    • Fix: remove them, or give advancePasskey an account check if it stays public.

Activity

  1. added
    bug
    extension
    on Sep 22, 2026
  2. jimhoyd commented on Sep 22, 2026

    @jimhoyd
    CollaboratorAuthor

    Partial progress in #494 (merged): raw session tokens are no longer stored in auth_flows (session-hash-only storage), the browser binding is now checked before a flow is consumed, email-change availability is no longer disclosed ahead of the second factor, and the dead advancePasskeyCounter/store advancePasskey case was removed.

    Not done, left open deliberately: findExternal (auth-core.ts:1325) was kept — it's a permission-gated read used by roughly 7 existing tests, with no security defect of its own (it doesn't mutate anything or leak data beyond what the caller is already authorized to see). Removing it would mean rewriting that test surface for no security benefit, so it wasn't touched. If it should still go, that's a small standalone cleanup: delete the export and inline/rewrite the ~7 call sites in its test file.

  3. jimhoyd commented on Sep 22, 2026

    @jimhoyd
    CollaboratorAuthor

    Closing out the deferred item from this issue: I re-verified whether findExternal (packages/auth/src/auth-core.ts) is safe to remove, and it is not — leaving it in place.

    findExternal is declared as a member of the exported AuthService interface (auth-core.ts:400), and AuthService is re-exported as a public type from the package's entry point (packages/auth/src/index.ts: export type { AuthService, ... } from './auth-core.ts';). It sits alongside the other external-identity methods on that same interface (linkExternal, createExternalAccount, getExternalProof), so it's part of the package's documented public contract, not an orphaned internal helper — even though within this repository's own src/ tree only the 7 test call sites (across admin-account-operations.test.ts, manual-recovery-http.test.ts, mailbox-claim.test.ts, auth-core.test.ts, manual-recovery.test.ts) exercise it directly. Production code paths (admin account removal, mailbox-claim, manual recovery) don't need to call it themselves, but external integrators building on AuthService — e.g. checking whether a provider/subject pair is already linked before calling createExternalAccount, or building custom admin/support tooling — would reasonably use it, the same way they'd use getExternalProof or getUser.

    It isn't listed in packages/auth/docs/JSON-API.md, but that page documents the HTTP contract, not the raw TypeScript AuthService surface — several of its interface siblings (getExternalProof, linkExternal) aren't listed there either, so absence from that page isn't a signal of dead code for this interface.

    No security defect, no dead-code finding — leaving findExternal as-is. No code change in this pass; verified npm run typecheck stays green on the current state. Not closing this issue on this comment alone, in case a maintainer wants to reclassify it, but I'd consider the deferred findExternal question resolved.

  4. jimhoyd commented on Sep 23, 2026

    @jimhoyd
    CollaboratorAuthor

    Re-verified against current main: all three remaining hardening items are already fixed via #494.

    1. Raw session token in OIDC link flow — packages/auth/src/auth-flows.ts (~95-106, 139-140) stores only sessionReference(actorToken) (a hash), never the raw token, with a comment citing SECURITY.md's "stored only as hashes" claim.
    2. Consume-before-binding-check ordering — every flow-consuming call site (auth-flows.ts OIDC callback ~121-123, enroll ~185-187, complete ~201-203, passkey ceremonies ~238-240) now calls peekFlow/checkBinding before consumeFlow; auth-core.ts (~395-399) documents this ordering as part of the AuthService contract.
    3. Email-availability disclosure before second factor — packages/auth/src/auth-store.ts (~1657-1672) calls consumeFactor before checking email_unavailable/email_unchanged.
    4. Dead passkey code — advancePasskeyCounter and the store's advancePasskey case no longer exist anywhere in packages/auth/src (removed in Fix account-enumeration, rate-limit, CSRF-binding and store-lock security gaps #494 along with their test coverage).

    findExternal was left untouched, consistent with the earlier decision on this issue that it's part of the public AuthService contract, not dead code.

    Verification run: npm run typecheck green; packages/auth test suite 213/213 passing, including the binding-check-before-consume and email-availability-after-factor regression tests.

    No further code change needed — closing.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugextension

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions