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.
Step 1: Client requests registration or authentication options from server.
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.
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.
[ 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 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 1: Client requests registration or authentication options from server.
Step 2: Server generates a cryptographically random challenge and stores it in the user's session.
Step 3: Client invokes navigator.credentials.create() or navigator.credentials.get().
Step 4: Device authenticates user via biometrics or PIN and signs the challenge with the hardware private key.
Step 5: Client transmits the signed assertion (authenticatorData, clientDataJSON, signature) to server.
Step 6: Server verifies the signature using the stored public key, validates the origin and RP ID, and checks the challenge.
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 };
}- ✕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.
Failing to verify the origin and RP ID on the server, allowing an attacker to relay assertions from other domains.
Strictly validate that clientDataJSON.origin matches the exact domain and protocol of the application.
Why are WebAuthn passkeys completely immune to phishing attacks, unlike passwords and TOTP codes?