arthrop0d

Brief articles on varied topics.

WebAuthn Authentication Ceremonies

computer securitycryptographyweb development

WebAuthn authentication is a browser-mediated protocol in which an authenticator proves possession of a private key by signing a server-provided, one-time challenge. The browser includes the site’s origin in the data being signed, so a credential created for one site cannot normally be used to authenticate to a phishing site.

The problem WebAuthn solves

Traditional login usually sends a password, or a reusable password-derived secret, to a server. A phishing site can imitate the real login page and collect that secret. If the password is reused, the damage spreads to other services too.

WebAuthn replaces that shared secret with a public-key credential. During registration, an authenticator—such as a platform security chip, phone, or hardware security key—creates a key pair. The private key stays on the authenticator; the server stores only the corresponding public key. During a later login, the server asks the authenticator to sign fresh data. The server verifies the signature with the stored public key.

The login exchange is called an authentication ceremony: a coordinated sequence involving the server, browser, and authenticator. It is not just one HTTP request, because each participant contributes security checks.

Starting an authentication ceremony

A server begins by generating a cryptographically random challenge, meaning an unpredictable byte string intended for one login attempt. It sends that challenge to the browser along with the identity of the relying party (RP), the application that owns the credential. The RP is usually the site or service the user is logging in to.

The server must save the challenge temporarily, associated with the login attempt, and reject it after it is used or expires. In JavaScript, the application passes the challenge to the browser through the WebAuthn API, conceptually like this:

const assertion = await navigator.credentials.get({
  publicKey: {
    challenge,
    rpId: "example.com"
  }
});

The actual value is normally represented as bytes rather than the string shown here. The browser checks that the requested RP ID is valid for the page that called the API. An RP ID such as example.com can cover appropriate subdomains, but an unrelated domain cannot claim it.

How the browser binds the request to the site

A web page has an origin: its scheme, host, and port, such as https://example.com:443. The browser creates a structure called clientDataJSON for the ceremony. It records at least:

The browser then hashes this structure. The authenticator signs data that includes that hash; it does not need to parse the page’s URL itself. This distinction matters: the browser is the trusted component that tells the authenticator which origin initiated the operation, while the server later verifies what the browser reported.

The authenticator also produces authenticator data, a binary structure containing the hash of the RP ID, flags, and usually a signature counter. The RP ID hash connects the assertion to the service name requested by the browser. The flags indicate things such as user presence—typically a touch or button press—and, when required, user verification such as a PIN, fingerprint, or face check.

The signature covers the authenticator data combined with the hash of clientDataJSON. In simplified form:

signed bytes = authenticatorData || SHA-256(clientDataJSON)

The authenticator signs those bytes with the credential’s private key. The browser returns the signed assertion, the client data, and the authenticator data to the server.

What the server verifies

The server looks up the credential ID and its stored public key, then checks all of the following before accepting the login:

  1. The challenge in clientDataJSON matches the outstanding challenge for this login attempt.
  2. The operation type is the expected WebAuthn assertion operation.
  3. The origin is an allowed origin for the RP.
  4. The RP ID hash in authenticator data matches the expected RP ID.
  5. Required user-presence or user-verification flags are set.
  6. The signature is valid for the stored public key.
  7. The challenge has not expired or already been consumed.

The signature proves that the authenticator holding the private key approved this exact combination of data. It does not merely prove that the user owns some key.

Why phishing fails

Suppose the real site is https://example.com, but a user visits https://example-login.example.net. The phishing page can request WebAuthn, but the browser records the phishing page’s origin in clientDataJSON. A signature produced there therefore does not verify as an assertion for example.com. The attacker can forward messages between the victim and the real site, but cannot alter the origin or create a valid signature for the real site’s credential.

This is why WebAuthn is stronger than a code sent by email or SMS: those codes are usually independent of the page’s origin and can be relayed by a phishing site.

Why replay fails

An intercepted assertion is not a reusable login token. Its signature covers the random challenge, and the server accepts that challenge only once and only for the intended login attempt. Replaying the same assertion later produces the same signed challenge, which the server has already consumed or expired.

The authenticator’s signature counter can provide an additional signal about cloned or malfunctioning authenticators, although servers must handle counter behavior carefully because some authenticators do not maintain useful counters.

When WebAuthn appears in an application log, errors such as “challenge mismatch,” “origin not allowed,” “RP ID hash mismatch,” or “user verification required” usually identify which participant’s check failed. The ceremony succeeds only when the browser’s origin binding, the authenticator’s signature, and the server’s state validation all agree.

← All articles