Skip to content

fix(auth): stop passkey sign-in from revealing usernames - #117

Merged
PiquelChips merged 2 commits into
mainfrom
fix/login-username-enumeration
Oct 14, 2026
Merged

PiquelChips merged 2 commits into
mainfrom
fix/login-username-enumeration

Conversation

@PiquelChips

@PiquelChips PiquelChips commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Passkey sign-in by username told anyone whether an account exists. POST /webauthn/authenticate/start with an unknown username returned 400 "No passkey is available for this username.", while an existing username returned a challenge listing that account's credential IDs. No invitation was needed, and the per-IP rate limit only slowed down enumeration.

Fix

A username without an active account or passkey now gets a challenge shaped like a real one:

  • One lookup for every case. A new compile-time checked passkeys().list_active_by_username query (cached in crates/database/.sqlx/) joins users and credentials. Missing, inactive and passkey-less accounts all come back empty from the same single query. Both paths then run one query, the same start_passkey_authentication call and one ceremony insert, and both set the ceremony cookie.
  • Stable decoy credentials (passkey/decoy.rs). When the lookup is empty, allowCredentials lists decoy credential IDs that DecoyKey computes by HMAC from the username. The key comes from the persistent PEM key, under a new domain-separation context (piquel-passkey-decoy-credential-v1), the same way refresh_key is derived. Repeated requests return the same IDs, across restarts and replicas, just as for a real account. The number of decoys (1 or 2, mostly 1) and their ID lengths (16, 20 or 32 bytes) are also drawn from the username's key. The choice uses an HMAC input separate from the IDs, so ID bytes are independent of the chosen shape. Compile-time assertions keep every count and length within one digest. Decoys list no transports, because stored credentials normally have none: webauthn-rs keeps transports only from packed or TPM attestation, and passkey registration requests none.
  • Fails only at finish, generically. The decoy is stored as Ceremony::Decoy, which holds no WebAuthn state, so it cannot succeed. Finishing it returns AccountUnavailable, which now gets the same 400 "This passkey could not be verified. Please try again." as an unregistered passkey on a real account. The logs still tell the two apart, at debug level.
  • Config. AuthConfig::from_environment reads AUTH_KEY_PROVIDER once and gives it to both PasskeyConfig (decoy key) and OidcConfig (signing key, refresh key). AuthConfig::derive_key holds the derivation both keys share, and PasskeyConfig wraps the decoy key in DecoyKey.

Username sign-in still works for security keys that need allowCredentials. Active accounts with passkeys get the same response as before. An active account without passkeys now gets decoys instead of an empty list, like an unknown username.

Leaks this does not fix

  • Registration. Registration finish still returns UsernameTaken (409). When invitations are required this needs a valid invitation. Without them (AUTH_INVITE_REQUIRED=false, as on previews), anyone can check usernames this way.
  • Shape statistics. Decoys imitate a fixed set of shapes. An account with 3 or more passkeys, credential IDs of another length, or stored transports can be recognised as real. The ID lengths are my guess at common authenticators. It is worth checking them against production: SELECT length(credential_id), credential->'cred'->'transports', count(*) FROM passkey_credentials WHERE revoked_at IS NULL GROUP BY 1, 2;
  • Changes over time. A real account's list changes when its owner adds or removes a passkey, while a decoy's never does. Replacing the PEM key changes every decoy but no real ID, so responses recorded before and after a replacement reveal real usernames. The README now says so next to key replacement.
  • Timing. Both paths run the same queries, but they are not equally fast. At start, the real path decodes credential JSON and stores a larger ceremony state, while the decoy path computes a few HMACs. At finish, a forged assertion for a listed real ID gets its signature checked, while a decoy ceremony is rejected without one. These differences are small but unmeasured, and someone timing many requests may be able to tell the paths apart.

UX change

Someone who mistypes their username no longer sees "No passkey is available for this username." Their browser looks for the decoy credentials, finds none, and the page shows the usual "cancelled or unavailable" message.

Testing

  • New database test unknown_usernames_get_stable_decoys_that_fail_like_unregistered_passkeys, using a software authenticator. Apart from the challenge and the credential list, the start options for a known and an unknown username are identical. Decoy descriptors have the same fields and type as real ones, repeat for the same username and differ between usernames. A passkey the server never registered gets the same status and body at finish against both ceremonies.
  • Unit test decoys_use_exactly_the_configured_shapes: across 256 usernames, decoys use every configured count and ID length and nothing else, and repeat per username.
  • Repository test username_lookup_hides_disabled_accounts_and_revoked_passkeys: the username lookup lists an account's passkey, then nothing once the account is disabled or its only passkey is revoked.
  • just db test against a disposable PostgreSQL: 55/55 passed before the rebase; after rebasing onto main, the passkey tests pass again and cargo sqlx prepare --check confirms the query cache. just lint-rust and cargo fmt --all -- --check are clean.
  • On a preview (just preview), with Playwright and Chromium's virtual authenticator:
    • Registering, then signing in by username through the UI, still reaches settings.
    • curl of /webauthn/authenticate/start for an existing and a nonexistent username: both return 200 with a ceremony cookie. The keys and options (rpId, timeout, userVerification, no mediation or extensions) are identical. Each lists one {id, type} descriptor, and repeated requests return the same ID. The real credential (32 bytes) also has no transports, which confirms the point above.
    • Bob's real passkey against Alice's ceremony and against a nonexistent username's ceremony: both return 400 {"error":"This passkey could not be verified. Please try again."}, byte-for-byte the same.
    • Over 30 requests each, the mean start time was 53 ms for the existing username and 51 ms for the unknown one. That sample is too small to rule out the timing difference listed above.

Note

Written by Claude Opus 5.5 in Claude Code and reviewed by GPT 6.1 Sol and Claude Opus 5.5 (via T3 Code)

🤖 Generated with Claude Code

@PiquelChips
PiquelChips force-pushed the fix/login-username-enumeration branch from bdbb6b3 to 5519d7c Compare October 14, 2026 09:51
@PiquelChips PiquelChips self-assigned this Oct 14, 2026
@PiquelChips PiquelChips added bug Something isn't working apps/auth-service Origin Auth at auth.sourceorigin.dev, its settings and developer console, and the operator CLI labels Oct 14, 2026
@PiquelChips PiquelChips added this to the 0.1 milestone Oct 14, 2026
Username sign-in rejected unknown usernames at start, and listed an
existing account's credential IDs, so anyone could check which usernames
exist. A username without an active account or passkey now gets a
challenge with stable decoy credentials, derived from the username with a
key from the persistent PEM key. Its ceremony fails at finish with the
same message as an unregistered passkey.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@PiquelChips
PiquelChips force-pushed the fix/login-username-enumeration branch from 5519d7c to 923175d Compare October 14, 2026 11:59
DecoyKey holds the decoy HMAC key and derives a username's credentials,
returning only CryptoError, so the shape rules are tested without a
database. Compile-time assertions keep the decoy counts and ID lengths
within one digest. A repository test checks that the username lookup
hides disabled accounts and revoked passkeys, and the README notes that
replacing the PEM key changes every decoy but no real credential ID.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@PiquelChips
PiquelChips merged commit 0f85b91 into main Oct 14, 2026
9 checks passed
@PiquelChips
PiquelChips deleted the fix/login-username-enumeration branch October 14, 2026 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

apps/auth-service Origin Auth at auth.sourceorigin.dev, its settings and developer console, and the operator CLI bug Something isn't working

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant