Repository navigation
fix(auth): stop passkey sign-in from revealing usernames - #117
Merged
Merged
Conversation
PiquelChips
force-pushed
the
fix/login-username-enumeration
branch
from
October 14, 2026 09:51
bdbb6b3 to
5519d7c
Compare
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
force-pushed
the
fix/login-username-enumeration
branch
from
October 14, 2026 11:59
5519d7c to
923175d
Compare
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Passkey sign-in by username told anyone whether an account exists.
POST /webauthn/authenticate/startwith 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:
passkeys().list_active_by_usernamequery (cached incrates/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 samestart_passkey_authenticationcall and one ceremony insert, and both set the ceremony cookie.passkey/decoy.rs). When the lookup is empty,allowCredentialslists decoy credential IDs thatDecoyKeycomputes 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 wayrefresh_keyis 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 notransports, because stored credentials normally have none: webauthn-rs keeps transports only from packed or TPM attestation, and passkey registration requestsnone.Ceremony::Decoy, which holds no WebAuthn state, so it cannot succeed. Finishing it returnsAccountUnavailable, 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.AuthConfig::from_environmentreadsAUTH_KEY_PROVIDERonce and gives it to bothPasskeyConfig(decoy key) andOidcConfig(signing key, refresh key).AuthConfig::derive_keyholds the derivation both keys share, andPasskeyConfigwraps the decoy key inDecoyKey.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
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.SELECT length(credential_id), credential->'cred'->'transports', count(*) FROM passkey_credentials WHERE revoked_at IS NULL GROUP BY 1, 2;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
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.decoys_use_exactly_the_configured_shapes: across 256 usernames, decoys use every configured count and ID length and nothing else, and repeat per username.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 testagainst a disposable PostgreSQL: 55/55 passed before the rebase; after rebasing onto main, the passkey tests pass again andcargo sqlx prepare --checkconfirms the query cache.just lint-rustandcargo fmt --all -- --checkare clean.just preview), with Playwright and Chromium's virtual authenticator:curlof/webauthn/authenticate/startfor an existing and a nonexistent username: both return 200 with a ceremony cookie. The keys and options (rpId,timeout,userVerification, nomediationorextensions) 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.{"error":"This passkey could not be verified. Please try again."}, byte-for-byte the same.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