Sub topic 9
Why passkeys resist phishing: origin binding
This chapter assumes you know what a passkey is and how WebAuthn registration and sign-in work at a high level. You should also know why a TOTP code can be phished. Here you will see the mechanism that makes passkeys different, where the check happens, and where the protection stops.
The problem origin binding solves
A phishing site copies an exchange's login page and asks for your password and your six-digit code. A relay attacker then forwards both to the real exchange within seconds. The TOTP code is valid for 30 seconds, so the real site accepts it. The code carries no information about where you typed it.
A passkey works differently. The thing you send is a signature, and that signature covers the origin of the page that requested it. The origin is the scheme, host and port, for example https://exchange.example. A signature made for a fake site is useless on the real one.
Two checks, two layers
Origin binding is enforced twice. One check runs in the browser and one runs on the server.
Layer 1: the browser scopes the credential
Every passkey is registered for a relying party ID (RP ID). The RP ID is a domain such as exchange.example. When a page calls navigator.credentials.get(), the browser applies these rules:
- The
rpIdmust be the page's own domain or a parent of it, which the spec calls a registrable domain suffix. A page onexchange-example.comcannot ask forexchange.example. The call fails. - If the page does not set
rpId, it defaults to the page's own host. - The authenticator offers only credentials registered under that exact RP ID. On a lookalike domain, no matching passkey exists, so the sign-in prompt has nothing to offer.
You never compare domains by eye. Your attention is not part of the security check.
Layer 2: the browser writes the origin into the signed data
When a matching credential is used, the browser builds a clientDataJSON document. It contains the operation type, the server's challenge, and the origin the browser actually saw. The page's JavaScript cannot set the origin field. The authenticator signs the concatenation of authenticatorData and the SHA-256 hash of clientDataJSON. The authenticatorData begins with the SHA-256 hash of the RP ID.
So the signed message binds together:
- the server's one-time challenge,
- the real origin of the page,
- the hash of the RP ID,
- flags saying whether the user was present and verified.
<br>
What the server checks
The server does not trust the browser's word alone. Verifying an assertion means checking the signed fields against values the server already knows. The following Python code does the field checks. It does not verify the cryptographic signature, which you should always leave to a maintained WebAuthn library. The code then runs a genuine assertion and a phished one through the same function.
import base64
import hashlib
import json
import os
def b64url(data: bytes) -> str:
return base64.urlsafe_b64encode(data).rstrip(b"=").decode()
def check_assertion(client_data_json, auth_data, expected_challenge,
expected_origin, rp_id):
client = json.loads(client_data_json)
if client["type"] != "webauthn.get":
raise ValueError("wrong operation type")
if client["challenge"] != expected_challenge:
raise ValueError("challenge mismatch")
if client["origin"] != expected_origin:
raise ValueError("origin mismatch")
if auth_data[:32] != hashlib.sha256(rp_id.encode()).digest():
raise ValueError("RP ID hash mismatch")
flags = auth_data[32]
if not flags & 0x01:
raise ValueError("user not present")
if not flags & 0x04:
raise ValueError("user not verified")
def make_assertion(origin, rp_id, challenge):
client = json.dumps({
"type": "webauthn.get",
"challenge": challenge,
"origin": origin,
}).encode()
# 32-byte RP ID hash, flags (UP + UV), 4-byte signature counter
auth = hashlib.sha256(rp_id.encode()).digest() + bytes([0x05]) + b"\x00" * 4
return client, auth
challenge = b64url(os.urandom(32))
expected = dict(expected_challenge=challenge,
expected_origin="https://exchange.example",
rp_id="exchange.example")
good = make_assertion("https://exchange.example", "exchange.example", challenge)
check_assertion(*good, **expected)
print("genuine site: accepted")
fake = make_assertion("https://exchange-example.com", "exchange-example.com", challenge)
try:
check_assertion(*fake, **expected)
except ValueError as err:
print("phishing site: rejected,", err)The second call prints phishing site: rejected, origin mismatch. In a real attack the browser would usually stop the flow earlier, as described in Layer 1. The server check is the backstop if a client misbehaves.
A real server also verifies the signature with the public key stored at registration. It then checks that the signature counter has not gone backwards, when the authenticator uses one. It must also issue a fresh random challenge for each attempt, store it server-side, and delete it after one use.
How this compares with other factors
| Factor | Secret travels to the site | Code or response reusable by a relay | Bound to the real domain |
|---|---|---|---|
| Password | Yes | Yes | No |
| SMS code | Yes, the code | Yes, within its lifetime | No |
| TOTP code | Yes, the code | Yes, within about 30 seconds | No |
| Passkey or security key | No, only a signature | No | Yes |
With a passkey, the private key never leaves the authenticator. A breach of the exchange's database exposes only public keys, which cannot sign in.
Where the protection ends
Origin binding is strong but narrow. Know these edge cases.
Downgrade through weaker fallbacks
If the account still allows a password plus SMS or TOTP, the attacker simply phishes the weaker path. The passkey protects only the sign-ins that use it. This is why the later chapters on recovery and exchange controls matter. A phishing-resistant factor that sits beside a phishable one gives you a stronger option, not a stronger account.
Compromise on the real origin
The signature proves the request came from the genuine origin. It cannot tell you that the genuine page is honest. Cross-site scripting (XSS) on the exchange can ride your authenticated session. A malicious browser extension, malware on your device, or session cookie theft after sign-in also bypasses the passkey. A passkey protects the moment of authentication, not the session afterward.
Overly broad RP IDs
An RP ID can be a parent domain, such as example.com, so that login.example.com and app.example.com share passkeys. The cost is that any subdomain you do not control, for example through a dangling DNS record that an attacker takes over, can request those credentials. A well-run exchange sets the RP ID as narrowly as it can.
Cross-device sign-in
A phone can authenticate a laptop session by showing a QR code. The protocol includes a Bluetooth proximity check, so a remote attacker cannot pass off a QR code from a distant victim. The browser still verifies the origin. Treat any prompt you did not start as suspicious regardless.
Social engineering outside the login
Origin binding cannot stop you from being talked into disabling security. A fake support agent can persuade you to register the attacker's passkey, change your email, or approve a recovery. Those attacks target account changes, which later chapters cover.
Verification you can perform yourself
You do not need to inspect any bytes to benefit from origin binding. Two habits make it work well:
- Register the passkey from the exchange's official site, typed or bookmarked yourself.
- When the browser says "no passkey found" on a page that looks like your exchange, treat it as an alarm. Close the tab and open the exchange from your bookmark.
A passkey that silently refuses to appear is the protection doing its job.
Exercise
A phishing page on exchange-login.example copies your exchange's login page exactly and asks for your passkey. The real exchange's RP ID is exchange.example. Describe the two points at which the attack fails, and name one attack that origin binding does not stop.
Show answer
First, the browser rejects the request or finds no credential. exchange-login.example is not exchange.example or a subdomain of it, so the page cannot ask for that RP ID. The authenticator holds no passkey registered for the phishing domain. Second, even if a signature were somehow produced, the signed clientDataJSON would contain the origin https://exchange-login.example and the authenticatorData would hash the wrong RP ID, so the real server's origin and RP ID hash checks would reject it. Origin binding does not stop session cookie theft or malware on your device after sign-in, XSS on the real site, or being tricked into approving a recovery or registering an attacker's passkey. It also does not protect an account that still accepts a phishable fallback such as SMS.
Exercise
Why does a server need to issue a new random challenge for every sign-in attempt and discard it after use?
Show answer
The challenge is part of the signed data. A fresh, single-use challenge means a captured signature cannot be replayed later. If the challenge were fixed or reusable, an attacker who recorded one valid assertion could submit it again.