Designing a Passkey Login System
I need to produce a clear explanation for designing a passkey/WebAuthn login system. This includes detailing ceremonies for registration and authentication, device binding, recovery, and fallbacks that are phishing-resistant. I should cover aspects like the architectural overview, step-by-step flows, server requirements, and security considerations. Key topics include RP ID, challenges, origins, attestation, user verification, multi-device passkeys, and account recovery methods. I’ll need to suggest effective fallback options while ensuring that security is prioritized.Structuring Passkey System Design
I need to provide pseudo-code examples or sequence diagrams for a passkey system. It's important to include multi-factor authentication, step-up, and reauthentication methods. I should mention FIDO2 and CTAP2.2 while outlining a recovery strategy that incorporates multiple passkeys, adding new passkeys while logged in, recovery codes, and ID verification. Preventing account enumeration and supporting usernameless login is vital. My structure should cover goals, glossary, data model, registration, authentication ceremonies, device binding, and recovery flows, ensuring clarity and organization.Developing Phishing-Resistant Login Plans
I need to consider phishing-resistant fallbacks for my login system, such as using security keys, device-to-device QR codes, and app-based WebAuthn options. Avoiding OTP is wise because it's still vulnerable, but if I use OTP, it should be domain-bound and incorporate in-app push notifications. I could also explore alternatives like magic links with WebAuthn step-up, though those can be phished too. Additionally, I’ll need to focus on session binding, device management, and security/UX details, keeping in mind the user’s request for a comprehensive design document that covers these elements effectively.Outlining Passwordless Approach with Passkeys
I need to recommend a passwordless system that uses passkeys as the primary factor. Registration should require a verified email or phone, but I know those can be phished. For sign-up, I can use an email link paired with passkey creation, while sign-in will strictly use passkeys. It's crucial to include defenses against enumeration, like keeping response times consistent. I'll consider device binding with device-bound credentials and the WebAuthn backup eligibility extensions for device binding decisions, though I need to keep user experience in mind.Defining Device Binding and Recovery Strategies
When strict device binding is necessary, I should require "non-backup-eligible" credentials, like a hardware key or enterprise policy, but the web doesn’t fully guarantee this. I also have options like the "uvm" extension and "devicePubKey," though I’ll stick with established methods like attestation, AAGUID, and transport for hardware key decisions. For user device binding, I’ll issue device tokens post-WebAuthn and store them in cookies.
For recovery, registering multiple passkeys is crucial, along with cross-device sign-in and security keys. I must also mention phishing-resistant fallbacks for older browsers and include details on verifying origin with rpId.
Below is a practical blueprint for a passkey (WebAuthn/FIDO2) login system that covers: ceremony flows (register + authenticate), how to think about “device binding,” recovery, and phishing‑resistant fallbacks.
1) Core concepts / decisions you must make up front
RP ID (domain binding)
rp.id is what passkeys are bound to (phishing resistance comes from the browser enforcing origin + rpId).
- Pick an RP ID you can keep forever, typically your registrable domain, e.g.:
- Origin:
https://app.example.com
- RP ID:
example.com (allows reuse across subdomains)
- Enforce HTTPS everywhere.
Passkeys you’ll see in the wild
- Platform authenticator (built-in): Touch ID/Face ID/Windows Hello/Android screen lock.
- Roaming authenticator (external): security key (YubiKey, etc).
- Synced passkeys (multi-device): may sync via iCloud Keychain / Google Password Manager / 3rd-party managers. These are still phishing-resistant for your domain, but not “single device”.
Account model choice
- Discoverable credentials (resident keys) enable “username-less” / “passkey-first” flows.
- Recommendation for passkey-first UX: require discoverable credentials (
residentKey: "required") and user verification (userVerification: "required").
2) Server-side data model (minimum)
Store one row per credential:
webauthn_credentials
id (internal)
user_id
credential_id (base64url; unique)
public_key (COSE key / converted)
sign_count (integer; see note below)
aaguid (optional; device model class)
transports (optional: internal, usb, nfc, ble)
backup_eligible / backup_state (if available from flags; helps reason about sync)
created_at, last_used_at
friendly_name (e.g., “Jane’s iPhone”)
revoked_at (nullable)
Important note on sign_count: with synced passkeys, counters may not strictly increase. Treat counter checks as “best effort” rather than hard-failing legitimate users.
3) Registration (Passkey creation) ceremony flow
Endpoint split (recommended)
POST /webauthn/register/options
POST /webauthn/register/verify
Flow (sequence)
-
User is signed in (ideal) OR is creating an account (you have a user_id).
-
Client requests options:
- Server creates a fresh random challenge (≥ 16–32 bytes), stores it server-side (session/DB) with TTL.
- Server returns
PublicKeyCredentialCreationOptions.
-
Browser calls:
navigator.credentials.create({ publicKey: options })
-
Client sends attestation result to server for verification.
-
Server verifies and stores the credential.
Recommended creation options (high-level)
rp: { id: "example.com", name: "Example" }
user: { id: <stable user handle bytes>, name/email, displayName }
- User handle must be stable and opaque (not an email string).
challenge: <random>
pubKeyCredParams: include ES256 (-7) at minimum.
authenticatorSelection:
residentKey: "required" (for passkey-first)
userVerification: "required" (biometric/PIN)
attestation: "none" for most consumer apps (privacy-friendly).
- Use
direct/enterprise only if you truly need hardware provenance and can handle privacy/policy implications.
Verification checklist (server)
- Challenge matches what you issued; not expired; one-time use.
origin is exactly your expected origin(s).
rpIdHash matches your RP ID.
- Attestation statement is valid (even if you don’t “trust” it, you still validate structure).
- Extract and store:
credentialId, publicKey, signCount, (optional) aaguid, flags.
- If you require UV: ensure
userVerified flag is set.
4) Authentication (Sign-in) ceremony flows
You typically support two entry points:
A) Passkey-first (username-less) flow (best UX, best anti-phishing)
-
Client calls POST /webauthn/auth/options with no username (or indicates “passkey-first”).
-
Server returns PublicKeyCredentialRequestOptions with:
challenge
rpId: "example.com"
- No
allowCredentials (lets the browser discover the right credential)
userVerification: "required"
-
Browser calls:
navigator.credentials.get({ publicKey: options })
-
Client posts assertion to POST /webauthn/auth/verify.
-
Server:
- Locates the credential by
credentialId
- Verifies signature over
clientDataHash + authenticatorData
- Verifies challenge, origin, rpIdHash
- Checks UV flag (required)
- Updates
sign_count (best effort) and last_used_at
- Creates session
This flow is very resistant to account enumeration and encourages passkey adoption.
B) Username-first flow (compat / migration)
- User types username/email.
- Server returns request options with
allowCredentials containing that user’s credential IDs.
- Browser calls
navigator.credentials.get.
- Verify as above.
Use username-first when:
- You have users with multiple accounts,
- You want a deterministic account selection step,
- Or you’re migrating gradually.
5) “Device binding”: what you can and can’t promise
Reality check
- A WebAuthn credential is bound to RP ID + credential private key, not to a single physical device in a way you can always enforce.
- Synced passkeys intentionally replicate the private key material (or an equivalent) across devices in the same ecosystem. That breaks strict “one device only.”
What you can do (practical patterns)
Pattern 1: “Credential binding” (recommended baseline)
Treat each registered passkey credential as a “login method”:
- Display it in account settings (“Jane’s MacBook passkey”).
- Allow revocation per credential.
- Use AAGUID/transports + timestamps for user visibility and anomaly detection.
Pattern 2: Prefer/require “non-synced” authenticators for high assurance
If your threat model requires no sync:
- Encourage/require roaming security keys (often non-backup-eligible) for admins/high-risk actions.
- Optionally enforce via policy:
- Require certain AAGUIDs (enterprise)
- Require attestation trust chain (complex, brittle for consumer)
This is the closest you get to “device binding” on the web today, but it’s really authenticator-class binding.
Pattern 3: Step-up binding for sensitive operations
Even if you allow synced passkeys for login, require stronger proof for critical actions:
- Re-auth with a security key (roaming authenticator), or
- Re-auth with a passkey + additional device signal (MDM-managed device cert, app attestation, etc., if you have an app).
6) Recovery: design for “lost all devices” without destroying phishing resistance
Best recovery strategy is prevention
Make it easy to add multiple authenticators:
- Prompt users after first successful login:
- “Add another passkey” (second device)
- “Add a security key” (kept offline)
- Show a clear “You have 1 passkey” warning banner until they add another.
Recovery options (ranked by phishing resistance)
(1) Use another already-signed-in device (cross-device passkey)
This is still WebAuthn-based:
- “Use a passkey from another device” (QR code / nearby device flow)
- This remains phishing-resistant because the WebAuthn ceremony enforces RP ID/origin.
(2) Recovery security key (offline)
User keeps a security key in a safe place.
- Still WebAuthn.
- Strong and phishing-resistant.
(3) Recovery codes (one-time) — not phishing-resistant, but practical
- Provide 8–12 single-use codes at enrollment.
- Treat as break-glass:
- Rate-limit heavily
- Require additional checks (cooldown, device/email notification, risk scoring)
- Force immediate re-enrollment of new passkeys
(4) Assisted recovery (support / KYC) — operationally expensive
- Manual verification, account hold periods, audited actions.
- Use for high-value accounts where you can justify overhead.
Avoid as “login fallback”: SMS / email OTP
- They are phishable and commonly intercepted.
If you must offer them:
- Position as account recovery only, not routine sign-in.
- Add friction and alerts:
- waiting period before new passkey becomes active,
- notifications to all existing authenticators,
- require re-auth with an existing passkey if any remain.
7) Phishing-resistant fallbacks (when passkeys aren’t available)
If “fallback” must remain phishing-resistant, it must still be origin-bound cryptography. Practical options:
-
External security keys (WebAuthn)
- Works on most modern browsers.
- Great for enterprise/admin use.
-
Cross-device WebAuthn (QR / nearby device)
- Lets a user authenticate using a phone passkey to sign into a desktop that has none.
-
Native app + passkey (if you have a mobile app)
- Use platform passkey APIs (iOS/Android) and complete the same WebAuthn verification server-side.
What is not phishing-resistant:
- TOTP codes
- SMS OTP
- Email links/codes
- Push approvals without strong origin binding (many are phishable via real-time relay)
If you include any of these, label them clearly as “recovery” and mitigate with step-up and delays.
8) Hardening + UX essentials
Hardening
- Always validate:
challenge, origin, rpIdHash, signature, and UV when required.
- Use short TTL challenges (e.g., 2–5 minutes) and one-time use.
- Rate-limit:
- options endpoints (to slow down abuse)
- verify endpoints (to slow down replay/bruteforce)
- Prevent account enumeration:
- In username-first, return the same shape/time whether user exists or not.
- Session security:
- Secure, HttpOnly cookies; rotate session on login; bind sessions to risk signals if needed.
UX
- Support both:
- “Continue with passkey” (passkey-first)
- “Use email” only under “Trouble signing in?” (recovery)
- Provide device list + revoke:
- show last-used, created date, name
- Encourage adding a second authenticator immediately.
9) Minimal set of endpoints (reference)
POST /webauthn/register/options
POST /webauthn/register/verify
POST /webauthn/auth/options
POST /webauthn/auth/verify
GET /account/security-keys (list)
POST /account/security-keys/:id/revoke
POST /account/recovery-codes/regenerate (requires strong re-auth)
If you tell me your constraints (consumer vs enterprise, do you require username-less, do you have a mobile app, and whether you need strict “no-sync device binding”), I can turn this into concrete request/response JSON examples for the options endpoints and a verification checklist tailored to your stack (Node/Java/Go/Python) and library choice.