For over four decades, digital identity and web security have been anchored to shared secrets: passwords. Despite password managers, salted hashing algorithms (Argon2id, bcrypt), and time-based one-time passwords (TOTP), credential stuffing, database leaks, and adversary-in-the-middle (AiTM) phishing continue to account for the overwhelming majority of account compromise incidents in modern systems.
WebAuthn (Web Authentication) and Passkeys—standardized by the FIDO Alliance and W3C under the FIDO2 umbrella—replace shared secrets with asymmetric public-key cryptography natively integrated into modern operating systems, hardware security modules (Apple Secure Enclave, Android Titan M, Windows Hello TPM), and physical security keys (YubiKeys). With passkeys, credentials are bound to specific origin domains, rendering phishing mathematically impossible.
In this technical guide, we dissect the internal protocol mechanics of WebAuthn: registration and ceremony lifecycles, Client to Authenticator Protocol (CTAP2), attestation vs. assertion statements, challenge-response verification, and the engineering trade-offs of synced vs. hardware-bound passkeys.
---1. The Cryptographic Paradigm Shift: Shared Secrets vs Asymmetric Credentials
Traditional password authentication requires both the user and the server to know (or verify) a shared secret. Even with one-way salted hashes, the server stores verifiable data that can be brute-forced if exfiltrated, and users can be tricked into disclosing secrets to spoofed domains.
WebAuthn fundamentally flips this dynamic:
- Private Key Isolation: A unique public/private keypair (typically
ES256ECDSA over curve P-256 orEd25519) is generated inside the user device's hardware security chip. The private key never leaves the device. - Public Key Ingestion: Only the public key and a globally unique credential identifier are transmitted to and stored by the backend authentication server.
- Origin-Bound Cryptographic Signatures: Every authentication challenge requires the authenticator to sign a payload that includes the server's exact origin (
https://example.com). Even if an attacker lures a user tohttps://examp1e.com, the browser supplies the spoofed origin, causing the signature verification to fail immediately.
2. The WebAuthn Ceremony Lifecycles
Every WebAuthn interaction is governed by a strict cryptographic ceremony orchestrated between three parties: the Relying Party (Backend Server), the Client (Browser / Operating System), and the Authenticator (Secure Enclave / Security Key).
2.1. Registration Ceremony (Credential Creation)
To register a new passkey, the server issues a cryptographic challenge:
// 1. Client requests registration options from server
const options = await fetch('/api/auth/passkey/register-challenge').then(res => res.json());
// 2. Invoke browser CredentialsContainer API
const credential = await navigator.credentials.create({
publicKey: {
challenge: Uint8Array.from(atob(options.challenge), c => c.charCodeAt(0)),
rp: { id: "sejan.dev", name: "Sejan Dev" },
user: {
id: Uint8Array.from("user_123", c => c.charCodeAt(0)),
name: "[email protected]",
displayName: "Mominul Haque"
},
pubKeyCredParams: [
{ type: "public-key", alg: -7 }, // ES256 (ECDSA w/ SHA-256)
{ type: "public-key", alg: -257 } // RS256 (RSASSA-PKCS1-v1_5 w/ SHA-256)
],
authenticatorSelection: {
authenticatorAttachment: "platform", // Secure Enclave / TouchID / Windows Hello
userVerification: "required", // Biometric / PIN check mandatory
residentKey: "required" // Discoverable credential (passkey)
},
timeout: 60000,
attestation: "none" // Privacy-preserving: omit hardware vendor telemetry
}
});
The authenticator generates the keypair, securely stores the private key, and returns an Attestation Object containing the raw public key encoded in CBOR (Concise Binary Object Representation) format.
2.2. Authentication Ceremony (Assertion Verification)
During login, the server issues a random nonce challenge (32+ cryptographically secure bytes). The client passes this to the authenticator, which prompts the user for biometric verification (Face ID, fingerprint, PIN), signs the challenge using the private key, and produces an Authenticator Assertion:
const assertion = await navigator.credentials.get({
publicKey: {
challenge: Uint8Array.from(atob(loginOptions.challenge), c => c.charCodeAt(0)),
rpId: "sejan.dev",
userVerification: "required"
}
});
// Transmit assertion.response.authenticatorData, clientDataJSON, and signature to backend
await fetch('/api/auth/passkey/verify-assertion', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(formatAssertion(assertion))
});
---
3. Backend Verification Architecture (Node.js & PHP)
When the backend receives the assertion response, it must perform five mandatory validation steps in strict sequence:
- Challenge Matching: Verify that the decoded
clientDataJSON.challengematches the active, unexpired challenge stored in the user's session cache (e.g. Redis). Expire the challenge immediately to prevent replay attacks. - Origin Verification: Ensure
clientDataJSON.originmatches the expected fully qualified domain (e.g.,https://sejan.dev). - RP ID Hash Check: Compute the SHA-256 hash of your Relying Party ID (
sejan.dev) and confirm it matches the first 32 bytes ofauthenticatorData. - User Verification Bit: Verify that the User Present (UP) and User Verified (UV) flag bits (bits 0 and 2) in the authenticator data byte are set to
1. - Cryptographic Signature Verification: Using the stored public key (retrieved from your database via
credentialId), verify thatsignatureis a valid cryptographic signature overauthenticatorData || SHA-256(clientDataJSON).
4. Synced Passkeys vs Hardware-Bound Security Keys
| Feature | Multi-Device Synced Passkeys | Device-Bound Passkeys (Hardware Keys) |
|---|---|---|
| Backing Storage | Apple iCloud Keychain, Google Password Manager, 1Password | Yubico YubiKey, Nitrokey, dedicated hardware TPM chips |
| Cross-Device Portability | Automatic end-to-end encrypted sync across authenticated user devices | Physically inserted via USB-C, Lightning, or tapped over NFC |
| Account Recovery | Handled via platform provider's recovery mechanisms (Apple ID / Google Account) | Requires secondary registered hardware key or manual enterprise fallback |
| Attestation Verification | Generally "none" (preserves user anonymity across ecosystems) | Enterprise direct attestation (cryptographic proof of FIPS/CC certification) |
| Threat Model Fit | Consumer web applications, SaaS platforms, developer portals | High-assurance banking, defense, root cloud infrastructure admins |
5. Production Engineering Considerations
- Graceful Fallback & Step-Up: Passkeys should be implemented as an addition to existing authentication mechanisms initially. Offer passkeys as the primary fast-path while retaining TOTP or magic links for account recovery.
- Sign-in with Conditional UI (Autofill): Modern browsers support
mediation: 'conditional', which displays registered passkeys directly inside the browser's native email/username autocomplete drop-down. - Sign Count Anomaly Detection: For non-synced authenticators, track the
signCountmonotonically. If the received sign count is lower than the last recorded count, alert on a possible cloned authenticator attack.
By transitioning from passwords to WebAuthn and passkeys, web applications eliminate the single largest attack vector in software engineering while simultaneously providing users with instantaneous, biometric sign-ins.