Skip to content

Lesson 4 of 9 · 25m

WebAuthn Registration: The Ceremony Behind Create

What navigator.credentials.create really does, how attestation and credential IDs work, and the server checks that make registration trustworthy.

WebAuthn registration is not 'saving a public key' in the casual sense. It is a challenge-response ceremony between the browser, the operating system, the authenticator, and your server. If you skip the server-side validation, you have built a very expensive password manager.

The browser call is only the beginning

const credential = await navigator.credentials.create({
  publicKey: {
    challenge,                         // random bytes from your server
    rp: { id: "login.sudosecurity.org", name: "SudoSecurity" },
    user: {
      id: userHandle,                  // stable opaque bytes, not email
      name: "traven@example.test",
      displayName: "Traven",
    },
    pubKeyCredParams: [
      { type: "public-key", alg: -7 },    // ES256
      { type: "public-key", alg: -257 },  // RS256
    ],
    authenticatorSelection: {
      residentKey: "preferred",
      userVerification: "preferred",
    },
    timeout: 60000,
  },
});

The authenticator generates a new asymmetric key pair scoped to the relying party ID. The private key stays inside the authenticator or sync fabric. The browser returns an attestation object and client data JSON.

The server owns trust decisions

Registration validation must check at least:

  • The challenge matches the one issued to this user and has not expired.
  • origin is exactly an allowed origin for this relying party.
  • type is webauthn.create.
  • The RP ID hash matches the relying party.
  • The attestation statement is acceptable under your policy.
  • The credential ID and public key are not already registered elsewhere.

The user handle should be opaque and stable. Do not use the email address: emails change, can be reused, and leak identity across services.

Attestation is mostly an enterprise concern

Basic attestation can prove the authenticator model or batch provenance, but consumer passkeys often use none for privacy. For most applications, requiring attestation breaks legitimate users without buying much. Use attestation policy only when you truly need managed-device assurance, and expect edge cases either way.

Store more than the public key

A credential row normally includes credential ID, public key, sign count or backup metadata, transports, user verification behavior, creation time, last use, friendly name, and revocation state. Those fields become essential when users lose devices or when you investigate suspicious registration.

Field notes

  • Challenges are single-use. Never accept the same challenge twice.
  • rp.id binds the credential to a registrable domain scope; choose it before launch because changing it means new credentials.
  • Credential IDs are binary. Encode consistently, usually base64url, and avoid lossy conversions.
  • Do not expose whether a credential exists to unauthenticated callers unless you deliberately accept enumeration risk.

Was this lesson helpful?

Sign in to rate