Passkey registration creates a public-key credential for a relying party. The browser asks an authenticator to create a key pair, while the application server later stores the credential identifier and public key for one account. A successful browser create call does not by itself authorize account attachment. The server must issue an unpredictable, short-lived challenge, remember its purpose and account context, and verify the returned client data and authenticator data before persisting anything. Registration is a privileged account mutation; a stolen active session or weak recovery flow can still attach an attacker-controlled credential.
Passkey Registration Challenge and Credential Binding
Working case
Reviewer 29 is signed into organization 6 and chooses Add a passkey from account settings. The server creates challenge C-47 scoped to that account, registration action, expected relying-party ID, and expiration. The browser opens the authenticator prompt. When the response returns, the server checks that C-47 is current and unused, verifies the client origin and relying-party scope, checks required flags and credential data using a maintained verification implementation, then stores the public key under reviewer 29. A second request that attempts to reuse C-47 is rejected. An account switch during the prompt cannot bind the result to reviewer 62.
Implementation boundary
function registrationContextMatches(pending, current) {
return pending.actorId === current.actorId && pending.action === "register-passkey" && !pending.used && current.now < pending.expiresAt;
}
console.log(registrationContextMatches({ actorId: 29, action: "register-passkey", used: false, expiresAt: 80 }, { actorId: 62, now: 47 }));
// Output: falseGenerate challenges with a cryptographically secure source on the server and store an opaque challenge record bound to the current authenticated actor and action. Do not trust an account ID or display name echoed by the browser to choose the owner. Validate expected origin, relying-party ID hash, challenge, credential type, and user-presence or verification policy through a maintained WebAuthn server library. Attestation policy depends on the product and should not be confused with proof that the user owns an account. Consume the challenge once, reject duplicate credential IDs where required, and persist credential metadata with a minimal device label the person can manage later.
Cost and boundaries
Creating a challenge is O(1) storage and random generation; verification includes cryptographic work and parsing bounded response data. Each credential adds a public key record and account-management surface. An account with several synced or device-bound credentials needs duplicate and removal rules, and a registration prompt can remain pending while the page changes. Measure challenge expiry and replay rejection, failed verification reasons without logging sensitive raw assertions, and how often users can finish registration. Correctness matters more than shaving a small verification cost.
Failure trace
A server accepts any registration response as long as a signed-in session exists. An attacker replays an old response or switches accounts during a delayed prompt and gets a credential attached to the wrong profile. Bind and consume the challenge under the original actor. Another implementation accepts a passkey created for a lookalike origin because it checks only the credential identifier. Verify origin and relying-party scope. Test expired and reused challenges, a canceled prompt, duplicate credential IDs, an account switch, and a session revoked before final registration.
Verification
- A returned credential binds only to the challenge owner.
- Expired or reused challenges cannot create credentials.
- Origin and relying-party scope are verified before storage.
Practice drill
Issue a registration challenge for reviewer 29, then submit a valid response through a real verification library. Replay the same response, alter the origin, bind it to reviewer 62, and let the challenge expire. Confirm each invalid path leaves no credential record. Interrupt the browser prompt and check that no pending challenge grants access. Add two valid passkeys with distinct labels and inspect the account settings list before testing one-credential removal.
Decision note
Treat registration as a server-authorized account mutation whose challenge, origin, and credential data are verified before storage.
Common Mistakes
- Treating browser create success as server verification.
- Choosing the account from client-supplied fields.
- Reusing one challenge for registration and sign-in.
Connected lessons
Passkeys and Account Assurance; Passkey Assertion, Origin, and Signature Verification; Passkey Conditional Sign-In and Fallback; Passkey Management, Recovery, and Step-Up; Password Verification and Login Budgets; Account Recovery and Session Revocation; Sessions and CSRF: keep identity on the server.
Apply and check
Build Project: passkey account lifecycle and review Web Development: passkey and checkout decisions quiz.
