←Back to Guides
๐Ÿ”Identity & Auth Securityโฑ๏ธ 14 min read•Updated November 2026•โœ๏ธBy Chris

Modern Authentication: Passkeys (WebAuthn / FIDO2), CSRF Defense & Stateful Sessions vs JWT

Design phishing-resistant authentication in 2026: implement Passkeys (WebAuthn / FIDO2) backed by P-256 origin-bound signatures, avoid JWT localStorage pitfalls, and pair HttpOnly session cookies with Fetch Metadata CSRF checks.

#Passkeys#WebAuthn#FIDO2#CSRF#Session Cookies#JWT#ECDSA#P-256

1. Why Passkeys Defeat 100% of Lookalike Phishing Sites

Password managers and SMS/TOTP 6-digit codes can still be phished by real-time reverse-proxy domains like login-bank-verify.com. WebAuthn Passkeys solve this cryptographically: the device authenticator (FaceID, Windows Hello, YubiKey) signs a server-issued nonce challenge with a hardware-backed ECDSA P-256 private key only when the browser authentic rpId (Relying Party origin) matches identically.
Browser Passkey Assertion Invocation (navigator.credentials.get)
const assertion = await navigator.credentials.get({
  publicKey: {
    challenge: base64UrlToBytes(serverChallenge),
    rpId: "mayonlinetools.com",
    userVerification: "preferred"
  }
});

A single-use random server challenge prevents replay attacks; the private key never leaves the OS enclave.

Auth FactorPhishable via Reverse ProxyServer Storage RiskRecovery RequirementCopy
Password + SMS 2FAYes (real-time MitM proxy captures OTP)Credential stuffing / SIM swapEmail reset flows
TOTP Authenticator AppYes (attacker forwards 6-digit code)Shared HMAC secret in DBBackup recovery codes
Passkey (WebAuthn FIDO2)No (bound strictly to TLS origin rpId)Public key only (useless if leaked)Synced cloud keychain / 2nd key

2. Stateful HttpOnly Session IDs vs Stateless JWTs in localStorage

Putting a long-lived JWT inside browser localStorage exposes it to every XSS gadget or third-party script. For first-party web apps, opaque random session IDs stored inside __Host-sid HttpOnly; Secure; SameSite=Lax cookies paired with Redis/DB revocation remain simpler, smaller, and instantly revocable upon logout or breachโ€”reserving short-lived JWTs strictly for cross-service federated access.
Session ArchitectureInstant RevocationXSS Token Theft ResistanceCopy
HttpOnly Cookie + Redis StoreYes (delete key = immediate logout)High (JS cannot read HttpOnly cookies)
JWT in localStorageNo (valid until exp claim expires)Low (any JS eval exfiltrates token)

3. Modern CSRF Defense: SameSite=Lax + Sec-Fetch-Site Headers

Cross-Site Request Forgery exploits browsers attaching cookies to state-changing cross-origin form POSTs. Combining SameSite=Lax cookies with server validation of the browser-immutable Sec-Fetch-Site header (`same-origin` or `same-site` on unsafe methods `POST/PUT/DELETE`) defeats CSRF cleanly without brittle hidden tokens everywhere.
Reject Cross-Site Unsafe Mutations Using Fetch Metadata
// Middleware guard for POST / PUT / PATCH / DELETE
const site = req.headers['sec-fetch-site'];
if (site && !['same-origin', 'same-site', 'none'].includes(site)) {
  return res.status(403).json({ error: 'Blocked cross-site state mutation' });
}

Modern Chromium, Firefox, and Safari lock Sec-Fetch-* headers against spoofing from client JavaScript.

4. Step-Up Verification for Sensitive Account Actions

Even after signing in, require fresh WebAuthn re-verification (`userVerification: "required"`) within the preceding 5 minutes before exporting API secrets, changing payout IBAN details, or disabling MFA.
๐Ÿ‘จโ€๐Ÿ’ป
Authored & Reviewed by ChrisMayPixels • Netherlands

Independent software developer focused on client-side architectures, local-first computing, WebAssembly, and privacy-first web systems.

About MayOnlineTools→

๐ŸŽ“Explore More Guides

โœจ