Skip to content
Back to CurriculumLesson 10 of 30
cryptography-passwordsExpert

WebAuthn & FIDO2: Biometric Hardware Passkeys, Secure Enclaves & Phishing Defense

WebAuthn (FIDO2) replaces shared secrets with asymmetric public-key cryptography bound to hardware security modules (Apple Secure Enclave, YubiKey, Windows Hello). Because the browser hardware cryptographically signs the origin domain, passkeys are mathematically immune to phishing.

Interactive Visual Concept ExplainerStep-by-Step Educational Simulation
Visual Step-by-Step Concept Explainercryptography-passwords
WebAuthn & FIDO2: Biometric Hardware Passkeys, Secure Enclaves & Phishing Defense
Steps:
Hardware Secure Enclave
Biometric Sensor: Touch ID / Face ID
Asymmetric Private Key: Locked in Silicon
The private key NEVER leaves the device hardware, making remote credential theft impossible.
Phishing Resistance (Domain Binding)
Allowed Origin: cscosmos.app
Attacker Fake Site: evil-cscosmos.app
Browser injects real origin into the signed challenge. Attacker phishing proxy is mathematically rejected!
Step 1 of 6
Auto-stepping (1x)

Step 1: Client requests registration or authentication options from server.

Security Guarantee: WebAuthn passkeys are mathematically phishing-resistant because private keys are hardware-bound and origin-scoped.
Why This Architectural Concept Exists

Phishing sites (e.g., evil-bank.com disguised as bank.com) can trick users into typing passwords and even TOTP 6-digit codes. WebAuthn eliminates this threat: the browser signs challenges using an asymmetric key pair strictly scoped to the relying party's domain (RP ID). The hardware will never sign for a phishing domain.

Intuitive Mental Model

The Royal Signet Ring with Built-In GPS: Unlike passwords (which you speak aloud to anyone who asks), a Passkey is a signet ring built into your laptop's secure silicon. It verifies the GPS location and building blueprint (origin domain) of the requesting entity before embossing its cryptographic stamp.

Architectural System TopologyProtocol Diagram
[ Browser / TouchID Secure Enclave ]              [ CosmosApp Server (RP) ]
                 │                                            │
                 │◄── (1) GET /auth/challenge (random 32b) ───┤
                 │                                            │
  1. Check Origin: 'cosmos.app' matches rpId?                 │
  2. Prompt TouchID / Fingerprint                             │
  3. Sign challenge using Hardware Private Key                │
                 │                                            │
                 ├── (2) POST /auth/verify ──────────────────►│
                 │   { authenticatorData, clientDataJSON,     │
                 │     signature }                            │
                 │                                            ├── Verify Signature with Alice's Public Key
                 │                                            ├── Verify Origin == 'https://cosmos.app'
                 │                                            ├── Verify Challenge == session.challenge
                 │◄── (3) 200 OK (Phishing-Proof Login) ──────┤
CosmosApp Production Milestone

CosmosApp implements WebAuthn Passkeys. Alice registers her MacBook's TouchID. The Secure Enclave creates an asymmetric P-256 key pair, sending only the public key to CosmosApp. When logging in, CosmosApp sends a cryptographic challenge. Alice taps TouchID; the hardware signs the challenge. An attacker spoofing CosmosApp on fake-cosmos.app cannot prompt the passkey because the browser validates the origin.

Step-by-Step Execution Sequence
01

Step 1: Client requests registration or authentication options from server.

02

Step 2: Server generates a cryptographically random challenge and stores it in the user's session.

03

Step 3: Client invokes navigator.credentials.create() or navigator.credentials.get().

04

Step 4: Device authenticates user via biometrics or PIN and signs the challenge with the hardware private key.

05

Step 5: Client transmits the signed assertion (authenticatorData, clientDataJSON, signature) to server.

06

Step 6: Server verifies the signature using the stored public key, validates the origin and RP ID, and checks the challenge.

Production Architecture Blueprint
import { verifyAuthenticationResponse } from '@simplewebauthn/server';

// CosmosApp WebAuthn Verification:
export async function verifyPasskeyLogin(req: Request, userPasskey: PasskeyCredential) {
  const body = await req.json();
  const expectedChallenge = await getSessionChallenge(req);

  const verification = await verifyAuthenticationResponse({
    response: body,
    expectedChallenge,
    expectedOrigin: 'https://cosmos.app',
    expectedRPID: 'cosmos.app',
    authenticator: {
      credentialPublicKey: userPasskey.publicKey,
      credentialID: userPasskey.id,
      counter: userPasskey.counter,
    },
  });

  if (!verification.verified) throw new Error('Passkey verification failed');

  // Update signature counter to prevent replay
  await updateCredentialCounter(userPasskey.id, verification.authenticationInfo.newCounter);
  return { success: true };
}
Common Architectural Misconceptions
  • ✕Biometric data (fingerprint/face) is sent to the server (Biometric data never leaves the local Secure Enclave; only a digital signature is sent).
  • ✕Passkeys can be stolen if the server database is breached (The server stores only public keys; public keys cannot be used to forge authentication signatures).

Key Architectural Takeaways

  • ✓WebAuthn passkeys are mathematically phishing-resistant because private keys are hardware-bound and origin-scoped.
  • ✓Servers only store public keys, completely neutralizing the risk of credential theft via database leaks.
  • ✓Always enforce signature counters to detect and prevent cloned hardware authenticators.
Common Architectural Pitfall

Failing to verify the origin and RP ID on the server, allowing an attacker to relay assertions from other domains.

Production Best Practice Fix

Strictly validate that clientDataJSON.origin matches the exact domain and protocol of the application.

Interactive Knowledge Check

Why are WebAuthn passkeys completely immune to phishing attacks, unlike passwords and TOTP codes?