From Passwords to Phishing-Resistant Authentication
Why passwords, one-time codes and push approvals can be relayed by a real-time phishing proxy, what WebAuthn passkeys sign and check so that they resist it, and how SSO and conditional access build on that, with a runnable teaching model of WebAuthn verification and its negative tests.
Contentsand lesson path
On this page
- Why it matters
- Factors and passwords
- Why codes and push approvals can be phished
- What makes WebAuthn phishing-resistant
- A teaching model of the RP checks
- SSO and conditional access
- Check your understanding
- Apply it
- Review prompt
Lessons of Identity & Access Management
- Identity Lifecycle and Access Models Concept · 20 min
- From Passwords to Phishing-Resistant Authentication Concept · 15 min
- Federating an App with a Lab Identity Provider Lab · 30 min
- Privileged Access and Running an Access Review Worked example · 20 min
- Reading Sign-In Logs for Identity Attacks Lab · 25 min
- Identity & Access Check Knowledge check · 8 questions
What you will learn
- Configure phishing-resistant MFA and single sign-on federation (OIDC or SAML) for an application in a lab identity provider and explain each trust relationship.
01. Why it matters
Phishing remains a common way into an organisation. Many teams added multi-factor authentication (MFA) and expected the problem to go away. It did not, because most MFA methods produce something the user can be tricked into giving to the wrong site. Phishing kits now sit between the victim and the real site and pass everything through in real time.
NIST SP 800-63B-4, the US government's digital identity guideline (final, July 2025), draws the line clearly. It calls an authenticator phishing-resistant only if its output is bound to the real site or session, and it says verifiers at its middle assurance level (AAL2) must offer at least one phishing-resistant option. This lesson explains that binding.
02. Factors and passwords
An authentication factor is a kind of evidence that you are the account owner. There are three kinds: something you know (a password or PIN), something you have (a phone, a security key, a private key stored on a device) and something you are (a fingerprint or face). MFA combines at least two different kinds. Two passwords are one factor.
For passwords, SP 800-63B-4 requires at least 15 characters when a password is the only factor, and at least 8 when it is part of MFA. It forbids composition rules such as "one digit and one symbol", forbids forced periodic changes, and requires a check against a blocklist of common and breached passwords. It also states that passwords are not phishing-resistant: the user can type the secret into any page.
03. Why codes and push approvals can be phished
An adversary-in-the-middle (AiTM) phishing kit (ATT&CK T1557) runs a reverse proxy on a look-alike domain. The victim visits the fake page. The proxy forwards each request to the real site and each answer back, so the victim sees the genuine page under a slightly wrong address. The victim types the password, and the proxy sends it on. The real site asks for a one-time code, the victim reads it from an app or an SMS and types it, and the proxy sends that on too. The real site then sets a session cookie, and the proxy keeps a copy. The attacker now holds a signed-in session and does not need the password or the code again.
A one-time password (OTP) fails here because nothing in the code says which site it is for. A code typed into the fake page works just as well on the real one if it arrives within its validity window. Push approval fails for the same reason: the real site sends the prompt because the proxy started a real login, and the user approves it. Showing a number on the login page that the user must type into the app makes careless approval harder. It does not stop the relay, because the proxy shows the victim the real number.
Push also invites a second attack. If the attacker already has the password, they can trigger prompt after prompt until the user approves one to stop the noise. ATT&CK calls this T1621 Multi-Factor Authentication Request Generation, often called MFA fatigue. SP 800-63B-4 responds in two ways. A plain "Approve" button is no longer acceptable: a secret must be moved between the login screen and the device, for example by typing the displayed number. Picking the right number from a short list is not enough, because the user can guess. And the verifier should limit how many push prompts it sends since the last successful sign-in.
04. What makes WebAuthn phishing-resistant
WebAuthn is the W3C browser API for public-key sign-in. Level 3 became a W3C Recommendation on 25 August 2026. Together with the FIDO Alliance's CTAP protocol, which lets a browser talk to an external security key, it is often called FIDO2. A passkey is a WebAuthn credential that a user can sign in with, either kept on one device or synced through a password manager or platform account.
At registration, the authenticator creates a new key pair for one website. The website, called the relying party (RP), keeps the public key. The private key never leaves the authenticator, or for synced passkeys it leaves only in encrypted form to the user's other devices. Each key pair is tied to an RP ID, a domain name such as bank.example.
At sign-in, the RP sends a random, single-use challenge. The browser builds clientDataJSON, which contains the ceremony type, the challenge and the origin of the page that asked, for example https://bank.example. The browser writes the origin, not the page. The authenticator builds authenticatorData, which starts with the SHA-256 hash of the RP ID (rpIdHash), then a flags byte and a signature counter. Two flags matter most: UP (user present: someone touched the key) and UV (user verified: a PIN or biometric was checked). The authenticator signs authenticatorData followed by the SHA-256 hash of clientDataJSON.
The RP then checks, in this order of importance: the challenge is one it issued and has not used; the origin is its own; the rpIdHash is the hash of its RP ID; UP is set, and UV too if the RP asked for it; the signature verifies with the stored public key.
Now replay the AiTM attack. On the fake domain, the browser refuses to use a credential whose RP ID does not match the page, so the honest path stops before any signature exists. If a broken or malicious client signed anyway, clientDataJSON would carry the fake origin, and the real RP rejects it. NIST calls this verifier name binding. There is nothing for the user to copy, so a convincing page gains the attacker nothing.
The signature counter (signCount) is meant to detect cloned keys: each use should increase it. Synced passkeys are designed to live on several devices, and many report 0 every time. The spec says to skip the check when both stored and received values are 0, and to treat a non-increasing value as a risk signal, not proof. Newer flags, BE (backup eligible) and BS (backed up), tell the RP whether a credential can be synced. SP 800-63B-4 allows syncable passkeys up to AAL2 but not at AAL3, which requires a non-exportable key, such as a hardware security key.
05. A teaching model of the RP checks
The model below shows these checks in about 100 lines. It is a teaching model, not a WebAuthn implementation: it skips CBOR encoding, attestation, extensions and much of what browsers do. For a real service, use a maintained library such as py_webauthn or SimpleWebAuthn. You need Python 3.12 and cryptography 50.0.2. The signatures use ES256 (ECDSA on the P-256 curve with SHA-256), the most widely supported WebAuthn algorithm.
mkdir webauthn-model && cd webauthn-model
uv venv --python 3.12 && source .venv/bin/activate
uv pip install "cryptography==50.0.2""""Teaching model of WebAuthn assertion checks (W3C WebAuthn Level 3, sec. 7.2).
Not a full implementation: no CBOR, attestation, extensions or credential
discovery. In production use py_webauthn or SimpleWebAuthn.
"""
import base64
import hashlib
import json
import os
import struct
from urllib.parse import urlsplit
from cryptography.exceptions import InvalidSignature
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric import ec
UP, UV = 0x01, 0x04 # flag bits in authenticatorData
RP_ID, ORIGIN = "bank.example", "https://bank.example"
def b64u(raw: bytes) -> str:
return base64.urlsafe_b64encode(raw).rstrip(b"=").decode()
class Rejected(Exception):
pass
class Authenticator:
"""Holds one private key per RP ID; signs authenticatorData + clientData hash."""
def __init__(self, synced: bool = False) -> None:
self.keys: dict[str, ec.EllipticCurvePrivateKey] = {}
self.counter, self.synced = 0, synced
def register(self, rp_id: str) -> ec.EllipticCurvePublicKey:
self.keys[rp_id] = ec.generate_private_key(ec.SECP256R1()) # ES256
return self.keys[rp_id].public_key()
def sign(self, rp_id: str, client_data: bytes, flags: int = UP | UV) -> dict:
if not self.synced: # many synced passkeys send 0
self.counter += 1
auth_data = (hashlib.sha256(rp_id.encode()).digest() + bytes([flags])
+ struct.pack(">I", self.counter))
sig = self.keys[rp_id].sign(auth_data + hashlib.sha256(client_data).digest(),
ec.ECDSA(hashes.SHA256()))
return {"authenticatorData": auth_data, "clientDataJSON": client_data,
"signature": sig}
def browser_get(auth: Authenticator, page_origin: str, rp_id: str,
challenge: bytes, honest: bool = True) -> dict:
"""The browser, not the page, writes the origin into clientDataJSON."""
host = urlsplit(page_origin).hostname or ""
if honest and host != rp_id and not host.endswith("." + rp_id):
raise Rejected(f"browser blocks RP ID {rp_id} on {host}")
client_data = json.dumps({"type": "webauthn.get", "challenge": b64u(challenge),
"origin": page_origin}).encode()
return auth.sign(rp_id, client_data)
class RelyingParty:
def __init__(self, public_key: ec.EllipticCurvePublicKey) -> None:
self.public_key, self.stored_count = public_key, 0
self.pending: set[str] = set() # challenges issued, not yet used
def new_challenge(self) -> bytes:
challenge = os.urandom(32)
self.pending.add(b64u(challenge))
return challenge
def verify(self, a: dict, require_uv: bool = True) -> str:
c = json.loads(a["clientDataJSON"])
if c["type"] != "webauthn.get":
raise Rejected("wrong ceremony type")
if c["challenge"] not in self.pending:
raise Rejected("challenge unknown or already used")
self.pending.discard(c["challenge"]) # one use, even if checks fail
if c["origin"] != ORIGIN:
raise Rejected(f"unexpected origin {c['origin']}")
ad = a["authenticatorData"]
if ad[:32] != hashlib.sha256(RP_ID.encode()).digest():
raise Rejected("rpIdHash does not match our RP ID")
if not ad[32] & UP or (require_uv and not ad[32] & UV):
raise Rejected("user presence/verification flag missing")
try:
self.public_key.verify(a["signature"],
ad + hashlib.sha256(a["clientDataJSON"]).digest(),
ec.ECDSA(hashes.SHA256()))
except InvalidSignature:
raise Rejected("signature does not cover these bytes") from None
count = struct.unpack(">I", ad[33:37])[0]
# The spec leaves the response to the RP; this model fails the ceremony.
if (count or self.stored_count) and count <= self.stored_count:
raise Rejected(f"signCount {count} did not increase: possible clone")
self.stored_count = count
return f"ok, flags=0x{ad[32]:02x}, signCount={count}""""A genuine login, then attacks, against the teaching verifier."""
from webauthn_model import (ORIGIN, RP_ID, UP, UV, Authenticator, Rejected,
RelyingParty, browser_get)
PHISH = "https://bank-example.test" # the attacker's look-alike page
def attempt(name: str, fn) -> None:
try:
print(f"ACCEPT {name:24} {fn()}")
except Rejected as exc:
print(f"REJECT {name:24} {exc}")
key = Authenticator()
rp = RelyingParty(key.register(RP_ID))
captured = browser_get(key, ORIGIN, RP_ID, rp.new_challenge())
attempt("genuine login", lambda: rp.verify(captured))
ch = rp.new_challenge() # attacker fetched this from the RP
attempt("honest browser on phish", lambda: browser_get(key, PHISH, RP_ID, ch))
attempt("kit relays assertion",
lambda: rp.verify(browser_get(key, PHISH, RP_ID, ch, honest=False)))
attempt("replayed assertion", lambda: rp.verify(captured))
def tap_only() -> dict: # touch, but no PIN or biometric
cdata = browser_get(key, ORIGIN, RP_ID, rp.new_challenge())["clientDataJSON"]
return key.sign(RP_ID, cdata, flags=UP)
attempt("UV required, tap only", lambda: rp.verify(tap_only()))
tap = tap_only()
ad = tap["authenticatorData"]
forged = dict(tap, authenticatorData=ad[:32] + bytes([UP | UV]) + ad[33:])
attempt("UV bit set by attacker", lambda: rp.verify(forged))
synced = Authenticator(synced=True)
rp2 = RelyingParty(synced.register(RP_ID))
for n in (1, 2):
a = browser_get(synced, ORIGIN, RP_ID, rp2.new_challenge())
attempt(f"synced passkey, login {n}", lambda: rp2.verify(a))python run_checks.pyACCEPT genuine login ok, flags=0x05, signCount=1
REJECT honest browser on phish browser blocks RP ID bank.example on bank-example.test
REJECT kit relays assertion unexpected origin https://bank-example.test
REJECT replayed assertion challenge unknown or already used
REJECT UV required, tap only user presence/verification flag missing
REJECT UV bit set by attacker signature does not cover these bytes
ACCEPT synced passkey, login 1 ok, flags=0x05, signCount=0
ACCEPT synced passkey, login 2 ok, flags=0x05, signCount=0The genuine login passes every check, and the stored counter becomes 1. The honest browser refuses to sign on the look-alike host. When the kit forces a signature anyway, the RP sees the wrong origin inside signed data. The replay fails on the challenge, because each challenge is removed when it is first used. The touch-only assertion fails the UV requirement. Setting the UV bit afterwards breaks the signature, because the flags byte is part of the signed authenticatorData. The synced passkey reports 0 twice and is accepted, as the spec describes. Keys are random per run; the output does not depend on them.
06. SSO and conditional access
Single sign-on (SSO) moves authentication to one identity provider (IdP). Applications trust the IdP's signed statement about the user, sent with OpenID Connect or SAML, instead of checking passwords themselves. This is why phishing-resistant MFA is usually deployed at the IdP: one strong sign-in protects every connected application. It also makes the IdP and its session cookies valuable targets, so their sessions need short lifetimes and fast revocation. Lesson 3 builds this federation for real.
Conditional access is a policy that the IdP evaluates at each sign-in: who the user is, which application, the device's health, the network, and a risk score. The answer may be allow, block, or "allow after step-up", meaning a stronger factor such as a passkey. This is the policy decision point of NIST SP 800-207 Zero Trust Architecture applied to identity: access is decided per request from current signals, not granted because a device sits on the office network.
07. Check your understanding
08. Apply it
The skill project federates an app with passkey-based MFA. Prepare for it with the model:
- Add a check to
RelyingParty.verifythat rejectsclientDataJSONwhosetypeiswebauthn.create, and write the attempt that proves it. - Change
ORIGINto a list so the RP accepts bothhttps://bank.exampleandhttps://app.bank.example, and decide whetherrpIdHashmust change too. - Write down which MFA methods your own organisation uses today, mark each as phishable or phishing-resistant using this lesson's test (is the output bound to the origin?), and list the accounts that should move to passkeys first.
09. Review prompt
Without looking back, explain: how an AiTM proxy defeats an OTP code; why number matching reduces MFA fatigue but does not stop a relay; what clientDataJSON and authenticatorData each contain and which party writes each; which bytes the signature covers; why a synced passkey may always report a counter of 0; why syncable passkeys are not allowed at AAL3; and what conditional access adds to SSO.
References
- NIST SP 800-63B-4: Authentication and Authenticator Management
- W3C Web Authentication Level 3 (Recommendation)
- passkeys.dev: developer resources from the W3C WICG and FIDO Alliance
- OWASP Authentication Cheat Sheet
- OWASP Multifactor Authentication Cheat Sheet
- MITRE ATT&CK T1557: Adversary-in-the-Middle
- MITRE ATT&CK T1621: Multi-Factor Authentication Request Generation
- NIST SP 800-207: Zero Trust Architecture
- py_webauthn (Duo Labs)
- SimpleWebAuthn
Your progress
Reading state
Sign in to save that you finished reading this lesson.
Prove this skill
8 questions · about 6 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.