Passkeys (WebAuthn)
What Actually Crosses the Wire
Web developmentweb development / security & auth
The myth
"A passkey is fingerprint login. My server stores the user's fingerprint, and it's just a nicer password."
Actually
Your server never sees a fingerprint. The biometric is a local gate that unlocks a private key held by the platform (iCloud Keychain, Google Password Manager, Windows Hello). What crosses the wire is a signature.
- Register: device generates a keypair → you store the public key + credential ID.
- Login: you send a random challenge → device signs it → you verify with the stored public key.
No shared secret exists on your server. A dump of your users table gives an attacker nothing to replay.
Why it's phishing-proof (the real differentiator)
The authenticator refuses to use a credential whose rpId doesn't match the page's origin, and it signs the origin into the payload. On g00gle.com the browser cannot produce a signature valid for google.com — not "the user should notice," mechanically impossible.
TOTP and SMS fail here: a reverse-proxy phishing kit relays those codes in real time. Passkeys break that attack by construction.
What intermediate devs get wrong
1️⃣ The challenge
Must be server-generated, ≥16 random bytes, single-use, short TTL, stored server-side against the session. Generating it client-side or reusing it = replay hole.
2️⃣ "The browser said OK" is not verification
On login you must check, server-side:
- clientData.type === "webauthn.get"
- clientData.challenge === the one you issued
- clientData.origin === "https://app.example.com" (exact match, allowlist)
- authData rpIdHash === SHA-256(rpId)
- flags: UP set; UV set only if you required it
- signature verifies over authData ‖ SHA-256(clientDataJSON)
Libraries (SimpleWebAuthn, webauthn4j) do this — but only if you pass them expectedOrigin and expectedChallenge. Hardcoding those wrong is the #1 bug.
3️⃣ rpId scope is a one-way door
rpId must be your registrable domain or a parent. login.example.com can set rpId "example.com" and the passkey works across every subdomain. Set it to "login.example.com" and you can never widen it — existing credentials are orphaned. Decide before launch.
4️⃣ Signature counters are mostly dead
Synced passkeys usually return signCount 0 forever. Treat a counter jump as a weak signal, not a cloning alarm.
5️⃣ "Device-bound" is false for consumer passkeys
They sync through the user's cloud account. Your security now partly rests on their Apple/Google account. If you need hardware binding, require attestation and pin AAGUIDs — and accept the UX cost.
The client call (the shape to memorize)
const cred = await navigator.credentials.get({
publicKey: {
challenge: fromServer, // ArrayBuffer, single-use
rpId: "example.com",
userVerification: "required"
}
});
// send cred.response.{clientDataJSON, authenticatorData, signature} + cred.id
⚠️ Also: always let users enroll 2+ credentials and keep one recovery path. A single passkey plus a lost phone plus no fallback = a support ticket you can't solve.
Your exercise
Open Chrome DevTools → ⋮ → More tools → WebAuthn → enable a virtual authenticator. Register and log in at webauthn.io. Then base64url-decode the clientDataJSON from the login response and read the origin and challenge fields with your own eyes.
Then answer: a phishing proxy sits at app-examp1e.com and forwards everything to the real site. Which exact field stops it, and why can't the attacker just rewrite it before relaying?