opyebPasskeyLab

RP ID and origin validation: why passkeys bind to the wrong site

Validation · 7 min read

In one line: How rpIdHash is computed, the protocol, host and port rules for origins, and the subdomain and localhost exceptions, with real mismatch cases.

Half of all "the passkey registers but sign-in fails" reports come down to an RP ID and origin mismatch. They look interchangeable but play different roles.

rpIdHash is the hash of the RP ID

rpIdHash = SHA-256(RP ID), over the RP ID string, not the origin. A credential registered with RP ID example.com hashes example.com even when the origin is https://login.example.com.

SHA-256("example.com")
= 3a6eb02f8ba0140d9f8e0c3d3e712f6d…  (32 bytes)

If the decoder keeps reporting a mismatch, put the exact RP ID from the attestation into panel ②. Very often a www. prefix or a subdomain was used instead.

The three parts of an origin

PartExampleWhat to check
Schemehttps:http is allowed only for localhost
Hostlogin.example.comEqual to the RP ID or a subdomain of it
Port8443A non-default port changes the origin

Allowed combinations

RP IDOriginResult
example.comhttps://example.comAllowed
example.comhttps://login.example.comAllowed (subdomain)
login.example.comhttps://example.comNot allowed (cannot widen to the parent)
example.comhttps://example.com:8443Not allowed (non-default port origin)
localhosthttp://localhost:3000Allowed as a development exception
example.comhttp://example.comNot allowed (HTTPS required)

The origin the server knows and the origin the browser recorded

Server applications usually sit behind a reverse proxy or CDN. The "our origin" the server knows may be an internal address such as http://10.0.2.5:8080, while the browser records the public domain the user sees in the address bar. Even when the proxy forwards X-Forwarded-Host and X-Forwarded-Proto, a comparison goes wrong unless the framework is configured to trust them. It is safer to compare clientData against an allow list written in configuration than against request headers.

If a service answers on both https://example.com and https://www.example.com, allow both origins but pin a single RP ID such as example.com, so the same passkey works whichever address the user visits.

Mismatches you will actually hit

  • www or not — setting the RP ID to www.example.com means the same passkey cannot be used on example.com later. If the whole service should share credentials, use the parent domain.
  • Changing ports — a new development port changes the origin. localhost is exempt from the port rule; a real domain is not.
  • iframes and crossOrigin — a ceremony inside an embedded iframe on another site can set crossOrigin to true in clientData, and many servers reject that.
  • Redirects — if the sign-in page redirects to another host, the origin changes even when the RP ID does not, and the server's origin allow list may not contain the new host.

A checking sequence

  1. Compare rpIdHash in the attestation with SHA-256 of the RP ID.
  2. Compare clientData.origin with the origin the server expects, as exact strings.
  3. Confirm the RP ID equals the origin host or is a parent domain of it.
  4. Confirm the scheme is https and that no unexpected port is present.
  5. Confirm UV is set if your policy requires it.

Decoding happens right in the browser. The payload you paste is not stored.

Open the PasskeyLab decoder

Frequently asked questions

Can the RP ID be changed later?

Existing credentials are bound to the original RP ID and cannot move. You have to register again under the new RP ID; the old credentials remain valid but unused.

Do I need a separate passkey for each subdomain?

If the RP ID is the parent domain, every subdomain can use the same credential. If you want isolation per site, use the subdomain as the RP ID.

Can a passkey made on localhost be used on the production domain?

No. localhost and the real domain are different RP IDs, so credentials are not shared.

Sources

Read next