WebAuthn/FIDO2 replaces passwords with per-site asymmetric keypairs generated inside a user's hardware authenticator, where private keys never leave the device and signatures are cryptographically bound to the exact Relying Party origin.
TL;DR30-second simplified summary▾
Traditional passwords and SMS/TOTP one-time codes are shared secrets: if a user is tricked into typing them into an adversary-in-the-middle (AiTM) phishing proxy, the attacker replays the credentials against the real site in real time. WebAuthn and FIDO2 eliminate shared secrets by using per-site asymmetric keypairs (typically ES256 / P-256 or Ed25519) anchored in a hardware Secure Enclave, TPM, or roaming security key.
During registration (navigator.credentials.create()), the Relying Party (RP) server issues a fresh cryptographic challenge and its rpId (e.g., app.example.com). The authenticator verifies user presence/biometrics locally, generates a unique keypair scoped to that rpId, retains the private key inside hardware, and returns the public key and credentialId to the server.
During authentication (navigator.credentials.get()), the server sends a one-time random challenge; the browser constructs clientDataJSON containing the exact active TLS origin, and the authenticator signs sha256(authenticatorData) || sha256(clientDataJSON). Because the signature binds both the server challenge and the browser-verified origin, a phishing domain like app-example.com produces an invalid signature that the real RP immediately rejects.
Key trade-offs and failure modes: synced passkeys (iCloud Keychain, Google Password Manager) solve device-loss lockouts via end-to-end encrypted key sync, but often report signCount = 0 rather than monotonically incrementing counters—so servers must not blindly reject signCount == 0 when backupEligible is set. Servers must also enforce single-use challenge TTLs and strict rpIdHash checks.
From patterns to decisions.
Understand how WebAuthn registration and assertion ceremonies work, why origin binding defeats phishing proxies, and how to handle signCount cloning and multi-device passkey recovery.
Why Passwords and TOTP Fail Against Reverse-Proxy Phishing.
Even with 6-digit TOTP or SMS codes, an Adversary-in-the-Middle (AiTM) reverse proxy sits between the victim and the legitimate login page, forwarding the username, password, and OTP in real time and stealing the resulting session cookie.
FIDO2/WebAuthn defeats AiTM phishing because the browser enforces origin binding: the authenticator signs the TLS origin observed by the browser (https://evil-login.com), which never matches the legitimate Relying Party's expected origin (https://example.com).
The WebAuthn Registration Ceremony (Attestation).
- Server Challenge: RP generates a 32-byte CSPRNG
challenge, stores it in short-lived state (e.g., Redis with 5-minute TTL), and specifiesrp.id,user.id, and allowed algorithms (-7ES256,-8EdDSA). - Browser & Authenticator:
navigator.credentials.create()invokes the platform authenticator (Touch ID, Windows Hello, Android Biometrics) or roaming key. - Server Verification: RP verifies the challenge matches and has not expired, validates
rpIdHash == sha256(rp.id), checksUP(User Present) andUV(User Verified) flags, and stores(credentialId, publicKey, signCount).
WebAuthn Registration Data Flow
Assertion Verification, Origin Binding & Replay Protection.
When signing in, navigator.credentials.get() returns authenticatorData, clientDataJSON, and signature.
The RP server must verify all of the following in order:
- Challenge:
clientDataJSON.challengematches the stored single-use challenge (and delete it immediately to prevent replay). - Origin & Type:
clientDataJSON.type === 'webauthn.get'andclientDataJSON.originmatches your exact allowlisted HTTPS origin. - RP ID Hash: First 32 bytes of
authenticatorDataequalsha256(expectedRpId). - Signature: Verify
signatureoverauthenticatorData || sha256(clientDataJSON)using the stored COSE public key.
Safe Challenge Lifecycle & Assertion Verification with Atomic Consumption.
Always consume challenges atomically (GETDEL in Redis) so concurrent replay attempts fail immediately, and handle synced passkeys (signCount == 0) properly:
import hashlib, json, base64
def verify_assertion(redis_client, session_id, assertion, stored_cred, expected_origin, expected_rp_id):
# 1. Atomically consume single-use challenge (prevents replay race conditions)
expected_challenge = redis_client.getdel(f'webauthn:chal:{session_id}')
if not expected_challenge:
raise AuthError('Challenge missing, expired, or already consumed')
client_data = json.loads(base64.urlsafe_b64decode(assertion['clientDataJSON'] + '=='))
if client_data.get('type') != 'webauthn.get' or client_data.get('origin') != expected_origin:
raise AuthError('Origin or ceremony type mismatch (possible phishing proxy)')
if client_data.get('challenge') != expected_challenge:
raise AuthError('Challenge mismatch')
auth_data = base64.urlsafe_b64decode(assertion['authenticatorData'] + '==')
if auth_data[:32] != hashlib.sha256(expected_rp_id.encode()).digest():
raise AuthError('RP ID hash mismatch')
# 2. Verify cryptographic signature over auth_data || sha256(clientDataJSON_raw)
if not verify_cose_signature(stored_cred.public_key, auth_data, assertion['clientDataJSON'], assertion['signature']):
raise AuthError('Invalid WebAuthn signature')
# 3. Check signCount (only flag cloning when both stored & new counters are > 0)
new_count = int.from_bytes(auth_data[33:37], 'big')
if stored_cred.sign_count > 0 and new_count > 0 and new_count <= stored_cred.sign_count:
raise SecurityAlert('Potential cloned hardware authenticator detected')
stored_cred.update_sign_count(new_count)Resident (Discoverable) Keys vs. Enterprise Hardware Keys.
- Synced Passkeys (Multi-Device): Stored in iCloud Keychain, Google Password Manager, or 1Password;
BE(Backup Eligible) andBS(Backed Up) flags are1. Great for consumer UX because losing a phone does not lock out the account. - Device-Bound Keys (Single-Device): YubiKeys or enterprise TPMs where
BE=0. Required for high-assurance government/fintech compliance where keys must never leave physical hardware.
Preventing Lockout Without Weakening Security.
If a user registers a single hardware key and loses it, falling back to an unverified SMS reset reintroduces SIM-swap risk.
Best practices:
- Encourage 2+ passkeys (e.g., platform passkey + backup security key or synced password manager).
- Use WebAuthn Conditional UI (
mediation: 'conditional') for one-tap autofill login. - Gate recovery with high-entropy recovery codes or identity-verified re-enrollment delays.
Subdomain rpId Scope, signCount=0 False Positives & Browser Quirks.
rpIdDomain Mismatch: SettingrpIdtologin.example.comprevents credentials from working onapp.example.com. Use the registrable domain (example.com) if passkeys span subdomains—but never a public suffix.- False Cloned-Key Lockouts: Multi-device synced passkeys intentionally emit
signCount = 0. Always checkstored_count > 0 && new_count > 0before flagging a clone.
Practice: Make the trade-off yourself.
An employee clicks a link to `https://corp-sso-login.com` (an AiTM reverse proxy for `https://sso.corp.com`) and taps their FIDO2 passkey. Why does the login fail?