Self-Hosted Passkey and WebAuthn Infrastructure: FIDO2 Credential Lifecycle, Attestation, and Account Recovery
Quick Summary (TL;DR)
- What you’ll build: A self-hosted WebAuthn relying party (RP) that issues and verifies FIDO2 passkeys, with optional attestation and a recovery path that doesn’t quietly reintroduce phishing risk.
- Key decisions: Which WebAuthn library to use, whether to enforce attestation, and how to balance synced vs device-bound passkeys.
- The hard part isn’t registration—it’s the lifecycle: credential rotation, revocation, and recovery when a user loses every authenticator.
- Golden rule: Recovery must never become a weaker password-equivalent backdoor. Layer rate limits, identity checks, and monitoring around it.
Passkeys are no longer experimental. FIDO2/WebAuthn is now supported across every major browser and platform, and organizations increasingly want to run the relying party themselves—for data sovereignty, for control over attestation policy, and to keep authentication logic inside their own trust boundary. This guide walks through the architecture, deployment steps, and the operational realities of running passkey infrastructure in production.
Why Self-Host Passkeys? Benefits and Trade-offs
Managed identity providers (Auth0, Okta, WorkOS, Stytch) offer passkey support out of the box. Self-hosting trades convenience for control.
Benefits:
- Data sovereignty: Credential public keys, user handles, and attestation data never leave your infrastructure.
- Policy control: You decide attestation conveyance, acceptable authenticator types (AAGUID allowlists), and recovery flows.
- No vendor lock-in: WebAuthn is a standard—credentials port with you, not your IdP.
- Cost at scale: Per-MAU pricing on managed IdPs becomes punishing above a threshold.
Trade-offs:
- You own the crypto correctness: Signature verification, challenge generation, origin validation—bugs here are catastrophic.
- You own uptime: An RP outage means nobody can log in.
- You own compliance: FIDO Alliance certification, audit logging, and incident response are on you.
Architecture Overview: Components of a Self-Hosted WebAuthn Relying Party
A production RP is more than a single service. The diagram below shows the core components and their interactions.
flowchart TD
User([User + Authenticator]) -->|WebAuthn API| Browser[Browser / Platform]
Browser -->|HTTPS| RP[Relying Party Server]
RP -->|Read/Write| DB[(Credential Database)]
RP -->|Optional verify| Att[Attestation Service]
RP -->|Recovery triggers| Rec[Recovery Service]
Rec -->|Verify identity| IDV[Identity Verification]
Rec -->|Notify| User
RP -->|Audit events| Log[(Audit Log)]
Relying Party Server
The RP is the heart of the system. It generates challenges, validates clientDataJSON, verifies signatures against stored public keys, and enforces origin/RP ID checks. It must be stateless-friendly (challenges stored in short-lived cache) and horizontally scalable.
Credential Database
Stores, per credential: credentialId, publicKey (COSE), signCount, transports, aaguid, attestationType, createdAt, lastUsedAt, and a backupEligible/backupState flag (from the BE/BS bits). Treat public keys as sensitive-adjacent—integrity matters more than confidentiality, but tampering is a full account takeover.
Attestation Service (Optional)
Verifies attestation statements (packed, tpm, android-key, apple) against FIDO Metadata Service (MDS) roots. Often offloaded to a separate service so the hot auth path stays fast.
Recovery Service
A deliberately separate trust domain. It should not share credentials or session logic with the RP, so a compromise of one doesn’t cascade.
Step-by-Step Deployment Guide
Step 1: Choose Your WebAuthn Library
Pick a library with active maintenance and full attestation support if you need it.
| Language | Library | Attestation | Notes |
|---|---|---|---|
| Node.js | @simplewebauthn/server | Yes (basic) | Excellent DX, widely used |
| Python | py_webauthn (Duo) | Yes | Mature, well-tested |
| Go | go-webauthn/webauthn | Yes | Strong concurrency, MDS support |
| Java | Yubico/java-webauthn-server | Yes | Enterprise-grade, FIDO certified |
Step 2: Configure the Relying Party
The RP ID must be a registrable domain suffix of the origin. Configure it once and never change it—doing so invalidates every credential.
# Example RP configuration
rp:
id: "login.example.com" # or "example.com" for subdomain sharing
name: "Example Corp"
origin: "https://login.example.com"
timeout_ms: 60000
attestation: "none" # see attestation section
user_verification: "preferred" # "required" for high-assurance
resident_key: "preferred" # discoverable credentials
Step 3: Implement Registration (Credential Creation)
Server generates a challenge (stored server-side keyed to the user session), calls navigator.credentials.create(), then verifies the response: challenge match, origin match, RP ID hash, and (if required) attestation. Store the returned credential ID and public key.
Step 4: Implement Authentication (Credential Assertion)
Issue a challenge, call navigator.credentials.get(), verify the signature against the stored public key, and check the sign counter. Note: most synced passkeys report signCount = 0 and do not increment—do not treat a zero counter as an error.
Step 5: Manage the Credential Lifecycle
This is where most self-hosted deployments fail. Build for it from day one:
stateDiagram-v2
[*] --> Active: Registration
Active --> Active: Authentication
Active --> Suspended: Suspicious activity
Suspended --> Active: Manual review
Active --> Revoked: User removes device
Active --> Revoked: Device lost
Revoked --> [*]
Provide a self-service credential management UI: list credentials with metadata (device name, last used, backup-eligible), allow renaming, and allow revocation. Revocation must be immediate and must invalidate sessions issued from that credential.
FIDO2 Attestation Policies: Balancing Security and Privacy
Attestation lets the RP learn what kind of authenticator created a credential. It’s powerful but privacy-sensitive, and it can exclude legitimate users.
Attestation Types and Their Implications
- None: No authenticator identity revealed. Maximum privacy and compatibility. Default for consumer services.
- Indirect: Authenticator identity anonymized via a privacy CA. Balances policy enforcement with privacy.
- Direct: Full attestation statement with identifying certificate. Required for enterprise AAGUID allowlists.
- Enterprise: Bypasses privacy controls for managed fleets.
Choosing an Attestation Conveyance Preference
Ask: Do I need to know the authenticator model? Consumer SaaS: use none. Enterprise with managed device fleets: use direct with an AAGUID allowlist. Regulated environments (banking, government): direct plus MDS verification.
Implementing Attestation Verification
Verification means: parse the attestation statement, validate the certificate chain against trusted roots (FIDO MDS or your own CA), extract the AAGUID, and check it against policy. Fail closed for high-assurance flows; log-and-allow for consumer flows.
Synced vs Device-Bound Passkeys: Understanding the Difference
WebAuthn exposes two flags—BE (backup eligible) and BS (backup state)—that tell you whether a credential is synced.
Synced Passkeys
Backed up to a cloud keychain (iCloud Keychain, Google Password Manager, 1Password). Survive device loss. Convenient. Security depends on the cloud provider’s account security.
Device-Bound Passkeys
Tied to one authenticator (hardware security key, TPM). Cannot be exported. Higher assurance against cloud-account compromise, but device loss = credential loss.
Implications for Your Infrastructure
- Store the BE/BS flags. They inform risk scoring and recovery decisions.
- Don’t assume sign counters increment—synced passkeys typically report 0.
- Offer both. Let users register a synced passkey for convenience and a hardware key for high-value actions.
Designing Secure Account Recovery Without Weakening Phishing Resistance
The dirty secret of passkeys: recovery is the new attack surface. If recovery falls back to SMS or a password, an attacker bypasses all your phishing resistance by attacking the weakest link.
Recovery Challenges with Passkeys
- Users lose devices, wipe phones, or switch ecosystems.
- Synced passkeys reduce lockout but not eliminate it (cloud account compromise).
- Any fallback that isn’t phishing-resistant dilutes the whole system’s guarantee.
Best Practices for Recovery Flows
- Multiple credentials, not multiple factors. Encourage users to register 2+ passkeys on day one.
- Recovery codes generated at enrollment, stored offline—phishing-resistant if never entered online.
- Identity verification (document + liveness) for high-assurance accounts, gated behind cooling-off periods.
- Rate-limit and monitor every recovery attempt; alert users on initiation and completion.
- Never silently downgrade to password-only recovery.
Example Recovery Flow
sequenceDiagram
participant U as User
participant R as Recovery Service
participant IDV as Identity Verification
participant RP as Relying Party
U->>R: Request recovery
R->>U: Trigger alert + 24h cooling-off
U->>R: Submit recovery code / start IDV
R->>IDV: Verify identity
IDV-->>R: Verified
R->>RP: Issue time-bound recovery token
RP->>U: Force re-enrollment of new passkey
RP->>U: Notify all channels of change
Comparison Table: Attestation Conveyance Options
| Conveyance | Privacy | Compatibility | Use Case |
|---|---|---|---|
none | Highest | Highest | Consumer SaaS, broad audiences |
indirect | High | High | Policy enforcement with privacy |
direct | Low | Medium | Enterprise AAGUID allowlists |
enterprise | Lowest | Low | Managed device fleets |
Comparison Table: Synced vs Device-Bound Passkeys
| Property | Synced | Device-Bound |
|---|---|---|
| Survives device loss | Yes | No |
| Exportable | Via cloud provider | No |
| Sign counter | Usually 0 | Increments |
| Threat: cloud account compromise | Higher risk | Lower risk |
| User experience | Excellent | Requires spare key |
| Best for | General users | High-value / admin accounts |
Conclusion
Self-hosting passkey infrastructure is entirely achievable, but it demands discipline in three areas: cryptographic correctness in the RP, thoughtful attestation policy matched to your risk model, and—most critically—a recovery design that doesn’t quietly undo phishing resistance. Get those right, and you’ll run an authentication system that’s both more secure and more usable than the password-based status quo.
FAQ
What is the difference between a passkey and a WebAuthn credential? A passkey is a user-friendly term for a FIDO2 credential used for passwordless authentication. WebAuthn is the underlying standard defining the API for creating and using these credentials. Passkeys are typically synced across devices via cloud services, while WebAuthn credentials can be either synced or device-bound.
Do I need to verify attestation for all users?
No, attestation is optional. For consumer-facing services, none attestation is common to maximize privacy and compatibility. For high-security environments (enterprise, government), require attestation to ensure only trusted authenticators are used. Choose based on your risk model and user base.
How can I recover an account if a user loses all their passkeys? Implement a fallback that doesn’t rely solely on passwords. Options include recovery codes (printed or stored securely), email magic links combined with identity verification, or in-person verification for high-assurance accounts. Ensure recovery flows are rate-limited and monitored to prevent abuse.
Are synced passkeys less secure than device-bound passkeys? Synced passkeys offer convenience and reduce lockout risk but rely on the security of the cloud sync provider. Device-bound passkeys are tied to a single device and may be more resistant to certain threats (e.g., cloud account compromise). The choice depends on your threat model and UX priorities.
Can I self-host a WebAuthn server without a dedicated attestation service?
Yes, attestation verification is optional. You can implement a relying party without attestation by setting attestation to none. If you require attestation for policy enforcement, integrate with an attestation verification service or implement verification logic yourself.
What are the key considerations for credential lifecycle management? Securely store public keys and credential IDs, associate credentials with user accounts, handle credential updates (new device additions), revoke credentials when a device is lost or compromised, and audit credential usage. Provide a self-service UI so users can manage their own credentials.