SECURITY ENGINEERING · PART 8 · WRITING SECURE CODE · AUTH · 117 OF 229

Passkeys and WebAuthn Explained

Passkeys replace passwords with public-key cryptography and are phishing-resistant by design. This episode explains how WebAuthn works: a key pair per site, the private key held in a device or security key, a signed challenge instead of a shared secret, why that defeats phishing, how registration and login flow, synced versus device-bound passkeys, and how to add them to an application.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 9
  9. 10
  10. 11
  11. 12
  12. 13
  13. 14
  14. 15
  15. 16
  16. 17
  17. 18
  18. 19
  19. 20
  20. 21
  21. 22
  22. 23
  23. 24
  24. 25
  25. 26
  26. 27
  27. 28
  28. 29
  29. 30
  30. 31
  31. 32
  32. 33
  33. 34
  34. 35
  35. 36
  36. 37
  37. 38
  38. 39
  39. 40
  40. 41
  41. 42
  42. 43
  43. 44
  44. 45
  45. 46
  46. 47
  47. 48
  48. 49
  49. 50
  50. 51
  51. 52
  52. 53
  53. 54
  54. 55
  55. 56
  56. 57
  57. 58
  58. 59
  59. 60
  60. 61
  61. 62
  62. 63
  63. 64
  64. 106
  65. 107
  66. 108
  67. 109
  68. 110
  69. 111
  70. 112
  71. 113
  72. 114
  73. 115
  74. 116
  75. 117
  76. 118
  77. 119
  78. 120
  79. 121
  80. 122
  81. 123
  82. 124
  83. 125
  84. 126
  85. 127
  86. 128
  87. 129
  88. 130
  89. 131
  90. 132
  91. 133
  92. 134
  93. 135
  94. 136
  95. 137
  96. 138
  97. 139
  98. 140
  99. 141
  100. 142
  101. 143
  102. 144
1 / 11

Press play to hear the narration, or step through at your own pace.

Key takeaways

  • Key pair per site
  • private key stays on the device
  • sign a challenge
  • origin-bound, so phishing fails

Notes

The core idea

Here is the core idea. When you register, your device creates a new key pair just for that site. The private key stays on the device, protected by a secure chip. Only the public key goes to the server. This flips the password problem: the server now stores something that is useless to an attacker. When a passkey site is breached, what leaks is a list of public keys, which cannot be used to log in and cannot be cracked. There is no shared secret to steal, phish or reuse.

No shared secret
  • at registration, your device creates a key pair for that site
  • private key stays on the device (secure chip)
  • public key goes to the server
  • the server stores something that is useless to steal
  • a breach of the server leaks public keys: no passwords to crack

Login by signature

Login works by signature, not by sending a secret. The server sends a random challenge. Your device asks you to confirm with a touch, your face or a PIN, which unlocks the private key locally. The device signs the challenge and sends the signature back. The server verifies it against the stored public key. Nothing secret ever crosses the network. And crucially, the browser binds the signature to the real site's origin, so a signature made for your bank cannot be used anywhere else.

Authentication flow
  • 1. server sends a random challenge
  • 2. device asks you to confirm (touch, face, PIN)
  • 3. device signs the challenge with the private key
  • 4. server verifies with the stored public key
  • nothing secret crosses the wire; the signature works only for this site

Why phishing fails

This is the property that matters most. When a passkey is created, the browser records which origin it belongs to, and it will only use that passkey on that exact origin. A phishing site that looks identical to your bank gets nothing: the browser does not offer the passkey, and there is no secret for you to type into the wrong box. Compare a password or a one-time code, which a user can be tricked into entering on a fake site. Passkeys remove that whole class of attack, by design, not by vigilance.

Phishing-resistant by design
  • the browser records which origin a passkey belongs to it only uses that passkey on that exact origin
  • a look-alike site gets nothing: no passkey, no signature
  • no secret for the user to type in the wrong place
  • the key advantage over passwords and OTP codes

WebAuthn and FIDO2

The standards behind this: WebAuthn is the browser API, standardised by the web consortium, that lets a site ask the device to create and use key pairs. CTAP is the protocol browsers use to talk to external authenticators. Together they are called FIDO2. An authenticator can be a platform one, built into your phone or laptop, or a roaming one, like a plug-in security key. Passkey is simply the user-friendly name for a WebAuthn credential. When someone says passkey, they mean a WebAuthn key pair.

The standards
  • WebAuthn: the browser API for public-key login (W3C)
  • CTAP: how browsers talk to external authenticators
  • FIDO2 = WebAuthn + CTAP
  • authenticators: platform (phone, laptop) or roaming (a security key like YubiKey)
  • passkey: a user-friendly name for a WebAuthn credential

Synced vs device-bound

There are two kinds. Synced passkeys are backed up to your platform account, Apple, Google, Microsoft or a password manager, so they work across your devices and survive a lost phone. Most consumer passkeys are synced, which solves the recovery problem. Device-bound passkeys never leave a single authenticator, such as a security key; they give the highest assurance with no cloud copy, for high-security use. You choose by whether recovery or maximum assurance matters more.

Two kinds of passkey
  • synced: backed up to your platform account or password manager; work across devices; easy recovery
  • device-bound: never leave one authenticator (a security key); highest assurance, no cloud copy
  • most consumer passkeys are synced; high-security is device-bound

Adding it to an app

To add passkeys you implement two ceremonies. Registration: the server sends options and a challenge, the browser creates a key pair and returns the public key and a credential id, stored against the account. Authentication: the server sends a challenge, the browser signs it, the server verifies. Use a WebAuthn library, not hand-written cryptography. On the server, always verify the origin, the challenge you issued, and the signature counter that detects cloned authenticators.

What you implement
  • registration: server sends options + challenge; browser creates the key; server stores the public key + id
  • authentication: server sends a challenge; browser signs; server verifies
  • use a library (SimpleWebAuthn, Spring, platform SDKs)
  • verify origin, challenge, signature counter server-side

Rollout in practice

In practice, passkeys arrive alongside existing login, not overnight. You offer them as an option, then make them the default. Keep a recovery path, and here is the catch: it must be strong, or you have just moved the weakness there, like the password reset problem from episode nine. Account recovery, not the cryptography, is the hard part. Passkeys can also serve as a strong second factor. And let a user register several, such as a phone and a backup key, so losing one is not a lockout.

Practical adoption
  • offer passkeys as an option, then as the default
  • keep a recovery path (and make it strong, not a weak password reset)
  • account recovery is the hard part, not the cryptography
  • passkeys also work as a strong second factor
  • allow several passkeys per account (phone + key)

Common mistakes

Mistakes. Implementing the WebAuthn cryptography by hand instead of using a library. Not verifying the origin, the challenge or the signature counter on the server, which throws away the guarantees. A weak recovery flow, which reintroduces exactly the phishing weakness passkeys remove. Allowing only one passkey per account, so losing the device means lockout. And treating an SMS one-time code as equivalent security, when it remains phishable and interceptable in ways a passkey is not.

Avoid these
  • implementing WebAuthn crypto by hand
  • not verifying origin, challenge or counter
  • a weak recovery flow that undoes the phishing resistance
  • only one passkey allowed, so loss = lockout
  • treating SMS OTP as equivalent (it is phishable)

Say it like this

In the interview: passkeys give each site its own key pair, private key in the device's secure hardware, never transmitted. Login signs a server challenge instead of sending a secret, so there is nothing to steal or phish. Phishing resistance comes from the browser binding the passkey to the origin, so a look-alike site gets no signature. I implement both ceremonies with a library, verify origin, challenge and counter, and invest in strong recovery, where the risk moves.

In the interview
  • "Each site gets a key pair;
  • the private key never leaves
  • the device, and login signs a challenge rather than sending
  • a secret. The browser binds
  • the passkey to the origin, so a fake site gets no signature.
  • I implement both ceremonies
  • with a library, verify origin
  • and counter, keep recovery
  • strong."

Interview questions

Q1What is a passkey?

A WebAuthn credential that replaces a password with a public-key pair. The private key is held in the user's device or security key and never leaves it; the server stores only the public key. Login is performed by signing a challenge rather than sending a secret.

Q2How do passkeys resist phishing?

The browser binds each passkey to the website's origin and only uses it on that exact origin. A look-alike phishing site is offered no passkey and receives no signature, and there is no secret for the user to type into the wrong place.

Q3What is WebAuthn?

A W3C standard browser API that lets websites register and authenticate users with public-key credentials. With the CTAP protocol for talking to external authenticators, it forms FIDO2, the basis of passkeys and security keys.

Q4What is the difference between a synced and a device-bound passkey?

A synced passkey is backed up to a platform account or password manager and works across the user's devices, easing recovery. A device-bound passkey never leaves a single authenticator, such as a hardware security key, giving the highest assurance but no cloud backup.

Q5What does a server store for a passkey?

The public key and a credential identifier for the account, plus metadata such as a signature counter. It never stores a private key or shared secret, so a breach exposes only public keys, which cannot be used to authenticate.

Q6Are passkeys more secure than SMS one-time codes?

Yes. SMS codes can be phished, intercepted through SIM swapping and interception, and entered on fake sites. Passkeys use origin-bound public-key cryptography with the private key never transmitted, which resists phishing and replay by design.

Q7What is the hardest part of adopting passkeys?

Account recovery. If the recovery path is weak, such as a simple password reset, it undermines the phishing resistance passkeys provide. Supporting multiple passkeys per account and a strong recovery process is essential.

Q8How do you add passkeys to an application?

Implement two WebAuthn ceremonies: registration, where the browser creates a key pair and the server stores the public key, and authentication, where the server issues a challenge and verifies the signature. Use a vetted library and verify the origin, challenge and signature counter server-side.