Skip to content

feat: webauthn / passkeys as a second factor - #3236

Merged
tada5hi merged 46 commits into
masterfrom
feat/mfa-webauthn
Jul 13, 2026
Merged

tada5hi merged 46 commits into
masterfrom
feat/mfa-webauthn

Conversation

@tada5hi

@tada5hi tada5hi commented Jul 12, 2026 •

Copy link
Copy Markdown
Collaborator

Part 5/5 of the MFA family — WebAuthn / passkeys (plan 049 Stage 2). Stacked on #3235 — targets feat/mfa-email-otp.

What

Adds kind:'webauthn' as a second factor (usernameless/passkey-first login is explicitly out of scope).

  • Credential (base64url id + public key, signature counter, transports) stored as JSON in parameters; ceremony via @simplewebauthn/server (webauthn.ts).
  • RP-ID/origin = publicUrl origin. Because plan 041 made /authorize a hosted login page, every RP's login runs on that one origin — so no per-RP origin plumbing (absent publicUrl → refused, MFA_NOT_CONFIGURABLE).
  • Registration: enroll returns creation options + a cached challenge (mfaWebauthnReg, 5-min); confirm(<attestation JSON>) verifies and stores the credential. Authentication is kind-generic: challenge() surfaces request options under status.challenge.webauthn (caching the nonce); verify(<assertion JSON>) matches the assertion to its credential row, verifies against the cached challenge, and bumps the stored counter (replay defense).
  • Kit: AMfaChallengeForm gains a passkey button (@simplewebauthn/browser startAuthentication, WebAuthn preferred first); enroll picker gains a passkey option (startRegistration → confirm).
  • Deps: @simplewebauthn/{server,browser} as stateless-leaf dependencies.

Tests

Service (enroll options + cached challenge, auth-options in challenge, fail-closed without RP, malformed attestation) + kit ceremony (mocked browser lib).

Summary by CodeRabbit

  • New Features
    • Added passkey/security-key support for multi-factor authentication enrollment and sign-in.
    • Users can register passkeys and complete MFA challenges with WebAuthn.
    • Added passkey options and prompts to authentication screens.
    • Added English, German, Spanish, and French translations for passkey flows.
  • Documentation
    • Updated MFA documentation with passkey enrollment, verification, configuration, and security details.
  • Tests
    • Added coverage for passkey enrollment, challenges, verification, and configuration failures.

tada5hi added 5 commits July 12, 2026 14:50
Plan 049 stage 1 + the /token otp gate (roadmap wave 3.1):

- auth_user_authenticators: polymorphic device rows (kind totp/recovery;
  email/webauthn reserved); TOTP seeds AES-256-GCM-encrypted at rest
  (new SymmetricCipher in @authup/server-kit) under MFA_ENCRYPTION_KEY
  (fail-closed), recovery codes bcrypt-hashed, single-use, regenerated
  as a set; secret/codes select:false and stripped from every read.
- two-step enrollment (create unconfirmed -> confirm with code) on
  /users/:id/authenticators (+ @me), admin management via new
  USER_AUTHENTICATOR_* permissions (realm_admin own-scoped CUD).
- session-bound proof: auth_sessions.mfa_at (+ auth_method column for
  plan 050, coordinated into one migration pair) stamped by
  POST /authenticators/challenge or the password grant otp param; the
  OAuth2Authorization backstop throws a dedicated mfa_required error
  when a confirmed-device user authorizes without it; the password
  grant rejects password-only logins for enrolled users (otp accepts a
  totp or recovery code, classified by shape).
- per-account exponential backoff (cache-keyed, 429
  mfa_attempt_throttled), mfaEnrolled/mfaRemoved/mfaVerified/
  mfaChallengeFailed events, mfa_required authorize metric outcome,
  typed client.userAuthenticator.*, config mfaEnabled/mfaRequired/
  mfaEncryptionKey (boot-validated), i18n error catalog x4 locales,
  migrations verified via run/revert/re-run on mysql + postgres.
Plan 050 stages 1-3 (roadmap wave 3.1, second half):

- every session-creation site stamps auth_method (pwd/ext/client/robot;
  ldap reserved for the deferred stage 1b) — the federated IdP callback
  threads it through the authorization-code blob so the /token
  fallback-create inherits it, and the interactive /authorize threads
  the bearer session's method the same way.
- amr/acr derive at the /token exchange from the RESOLVED session
  (deriveAmrAcr): pwd/ldap -> ['pwd'], ext -> ['ext'], + 'otp' when the
  session carries a second-factor proof (mfa_at); acr urn:authup:mfa vs
  urn:authup:pwd (urn-style, never the reserved "0"). Emitted on every
  token kind (intentional — resource servers read the method without
  parsing an id_token); NULL auth_method (pre-column session) emits none.
- acr_values accepted on /authorize (case-sensitive mount, persisted on
  the code blob) and advertised via discovery acr_values_supported;
  urn:authup:mfa acts as a step-up trigger enforced only while the user
  holds a confirmed factor (voluntary per OIDC Core 5.5.1.1 otherwise):
  session.mfa_at must be within mfaFreshnessMaxAge (default 60s, NOT the
  plan's 0 — a 0-window could never absorb the challenge round-trip and
  would loop the hosted ladder).
- session list read surface exposes mfa_at/auth_method.
…dmin tabs

Plan 049 UI (roadmap wave 3.1):

- AMfaChallengeForm (workflows/mfa) — code input posting to
  client.userAuthenticator.verifyChallenge, recovery-code fallback
  toggle, extractErrorContext failures.
- Authorize.vue ladder: after login a watch(loggedIn) fetches
  GET /authenticators/challenge; consent blocks until it resolves
  (built_in auto-consent must not fire first); required -> the
  challenge form before consent (its done = mfa_at stamped, so the
  consent POST passes the server backstop); enrollmentRequired ->
  inline AUserAuthenticatorEnroll (configure-inline). Interactive only;
  silent flows let the auto-consent hit the backstop -> interaction_required.
- AUserAuthenticatorEnroll (QR data-uri + confirm code / recovery codes
  with download) + AUserAuthenticators (list + delete + embedded enroll);
  hosted on settings security tab (@me) and an admin authenticators tab
  gated on USER_AUTHENTICATOR_READ.
- MFA_* (authupClient) + AUTHENTICATOR/MFA_SECURITY_* (authupApp) keys
  across all four locales (parity test green); kit component test.
- kind:'email' rows mark a verified mailbox as an enrolled factor
  (confirmed on create; enrollment force-loads the select:false email
  via findOneByWithEmail). The code is transient: sendChallenge
  generates a 6-digit numeric code, bcrypt-hashes it into the cache
  (mfaEmailCode:<user_id>, 10-min TTL) and mails it via a new
  MailTemplateName.MFA_EMAIL_OTP template (authupMail i18n x4);
  verify compares the cached hash + expiry and single-uses it.
- POST /authenticators/challenge/send { kind } issues the challenge
  (uniform 200 — no enrollment/status oracle; only a confirmed email
  factor triggers a mail); client.userAuthenticator.sendChallenge.
- MailModule.setup honors a pre-registered MailInjectionKey (test fake
  wins, mirroring UIHttpClient) so tests can capture mailed codes.
- kit: AMfaChallengeForm gains an email branch (send-code button ->
  code input) + kind switcher; enroll picker gains an email option.
- tests: service (enroll/send/verify/single-use/fail-closed), mail
  renderer + smoke matrix, kit challenge email flow, HTTP e2e.
- kind:'webauthn' rows store the registered credential (base64url id +
  public key, signature counter, transports) in parameters JSON. The
  ceremony rides @simplewebauthn/server (webauthn.ts); the relying-party
  context (rpId/rpName/origin) derives from publicUrl — the hosted
  /authorize origin (plan 041), so no per-RP plumbing (absent publicUrl
  -> refused).
- registration: enroll returns creation options + a cached challenge
  (mfaWebauthnReg, 5-min) and an unconfirmed row; confirm verifies the
  attestation and stores the credential. authentication is kind-generic:
  challenge() surfaces request options under status.challenge.webauthn
  (caching the nonce), verify matches the assertion to its credential
  row, verifies against the cached challenge, and bumps the stored
  counter (replay defense). second-factor only.
- kit: AMfaChallengeForm gains a passkey button (@simplewebauthn/browser
  startAuthentication, webauthn preferred first); enroll picker gains a
  passkey option (startRegistration -> confirm).
- deps: @simplewebauthn/{server,browser} as stateless-leaf dependencies.
- tests: service (enroll options + cached challenge, auth-options in
  challenge, fail-closed without rp, malformed attestation) + kit
  ceremony (mocked browser lib).
Copilot AI review requested due to automatic review settings July 12, 2026 14:19

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 12, 2026 •

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds WebAuthn/passkey MFA support across server enrollment and verification, relying-party configuration, client ceremonies, HTTP types, translations, dependencies, and unit tests.

Changes

WebAuthn MFA

Layer / File(s) Summary
WebAuthn contracts and helpers
.agents/architecture.md, apps/server-core/src/core/entities/user-authenticator/*, apps/server-core/src/app/modules/http/modules/controller.ts, apps/server-core/package.json
Defines stored credential parameters, relying-party configuration, cache constants, WebAuthn option builders, response verification helpers, and startup configuration derived from publicUrl.
Enrollment and confirmation
apps/server-core/src/core/entities/user-authenticator/service.ts, apps/server-core/test/unit/core/entities/user-authenticator/service.spec.ts, packages/client-web-kit/src/components/entities/user-authenticator/AUserAuthenticatorEnroll.vue, packages/core-http-kit/src/domains/entities/user-authenticator/types.ts, packages/i18n/src/*/client.ts, packages/i18n/src/constants.ts
Creates unconfirmed WebAuthn authenticators, caches registration challenges, confirms attestation responses, persists credentials, and exposes the passkey enrollment flow in the client.
Challenge and passkey verification
apps/server-core/src/core/entities/user-authenticator/service.ts, packages/client-web-kit/src/components/workflows/*, packages/client-web-kit/test/unit/components/workflows/mfa-challenge.spec.ts, packages/client-web-kit/package.json
Returns authentication options, verifies assertions, updates signature counters, and connects browser passkey authentication to the MFA challenge UI and API.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

  • authup/authup#3232: Extends the same user authenticator enrollment, confirmation, challenge, and verification infrastructure.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding WebAuthn/passkeys as a second-factor MFA method.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/mfa-webauthn

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Jul 12, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

authup

npm i https://pkg.pr.new/authup@3236

@authup/client-web

npm i https://pkg.pr.new/@authup/client-web@3236

@authup/server-core

npm i https://pkg.pr.new/@authup/server-core@3236

@authup/access

npm i https://pkg.pr.new/@authup/access@3236

@authup/client-web-kit

npm i https://pkg.pr.new/@authup/client-web-kit@3236

@authup/client-web-kit-theme

npm i https://pkg.pr.new/@authup/client-web-kit-theme@3236

@authup/client-web-nuxt

npm i https://pkg.pr.new/@authup/client-web-nuxt@3236

@authup/client-web-theme

npm i https://pkg.pr.new/@authup/client-web-theme@3236

@authup/core-http-kit

npm i https://pkg.pr.new/@authup/core-http-kit@3236

@authup/core-kit

npm i https://pkg.pr.new/@authup/core-kit@3236

@authup/core-realtime-kit

npm i https://pkg.pr.new/@authup/core-realtime-kit@3236

@authup/errors

npm i https://pkg.pr.new/@authup/errors@3236

@authup/i18n

npm i https://pkg.pr.new/@authup/i18n@3236

@authup/kit

npm i https://pkg.pr.new/@authup/kit@3236

@authup/server-adapter-kit

npm i https://pkg.pr.new/@authup/server-adapter-kit@3236

@authup/server-adapter-node

npm i https://pkg.pr.new/@authup/server-adapter-node@3236

@authup/server-adapter-socket-io

npm i https://pkg.pr.new/@authup/server-adapter-socket-io@3236

@authup/server-adapter-web

npm i https://pkg.pr.new/@authup/server-adapter-web@3236

@authup/server-kit

npm i https://pkg.pr.new/@authup/server-kit@3236

@authup/server-test-kit

npm i https://pkg.pr.new/@authup/server-test-kit@3236

@authup/specs

npm i https://pkg.pr.new/@authup/specs@3236

commit: f593c35

tada5hi added 15 commits July 12, 2026 16:51
…ery atomicity

- validate mfaEncryptionKey decodes to exactly 32 bytes at config time
  (normalize) instead of only truthiness — a wrong-length/whitespace key
  now fails loud at boot, not asynchronously at first encrypt/decrypt.
- SymmetricCipher validates the key length synchronously in the
  constructor, so a bad key throws at construction (DI mount) rather than
  leaving an unobserved promise rejection.
- resolveUserId throws BadRequestError when a non-user identity uses
  @me/@self, instead of letting the literal token match zero rows.
- enrollRecovery reuses the existing recovery row via a single atomic
  save instead of delete-then-insert, so a mid-op failure can never
  leave the user with no codes.
- verify-path concurrency/replay hardening (TOTP step reuse, recovery
  race, attempt-counter atomicity, session-stamp atomicity) tracked in #3237.

Refs #3232
Folds the schema-dependent hardening from #3237 into the still-unreleased
auth_user_authenticators migration so no future migration is needed:

- add a @VersionColumn (`version`) to the authenticator row (folded into
  1783856507391-Default.ts, both dialects; run/revert/re-run verified on
  mysql + postgres). The verify path now consumes a factor exactly once
  under concurrency — a racing second save fails the version check, which
  the repository adapter translates to EntityConflictError and the service
  treats as a failed attempt (fixes recovery-code race, CR #602).
- persist the last accepted TOTP step and reject any step <= it, closing
  the in-window replay window (RFC 6238 §5.2, CR #604). Tracked only on the
  login-verify path (not confirm), so a first login in the confirmation
  window still works.

The two schema-FREE items from #3237 (attempt-counter atomicity via an
ICache atomic-increment; cross-aggregate session-stamp) stay open there —
deferring them needs no migration.

Refs #3232 #3237
The anti-replay step tracking rejects reusing one TOTP code for two
successful verifications; the e2e now generates the password-grant otp
from the previous ±1-window step so it stays behind the later challenge
code. Refs #3232 #3237
@tada5hi tada5hi changed the title feat: webauthn / passkeys as a second factor (plan 049 stage 2) feat: webauthn / passkeys as a second factor Jul 12, 2026
tada5hi added 5 commits July 12, 2026 18:09
Replace the @VersionColumn optimistic-lock guard on the MFA verify path
with a per-user cache lock so a single factor (TOTP step / recovery code)
is consumed exactly once under concurrency, without a schema column.

Add ICache.add — atomic set-if-absent (Redis `SET … NX`, memory
single-tick check-set) — as the lock primitive. Acquisition fails open so
a cache outage cannot break MFA login; the TOTP step-counter and recovery
`used_at` flags remain the correctness backstop. A held lock means another
verify is mid-flight, so the request bails without penalty rather than
risk a double-consume.

Drop the version column from the entity, the core-kit domain type, and the
still-unreleased 1783856507391 migration (both dialects).
# Conflicts:
#	apps/server-core/src/core/entities/user-authenticator/service.ts
# Conflicts:
#	apps/server-core/src/core/entities/user-authenticator/service.ts
tada5hi added 6 commits July 12, 2026 21:08
- AUserAuthenticatorEnroll: add a Close action to the recovery-codes view so
  the user can return to the kind picker after generating codes (it previously
  stuck there — recovery enroll never reset the view, unlike the TOTP path).
- AUserAuthenticators: confirm before deleting an authenticator via
  useAlertDialog — removing a factor is irreversible and weakens the account's
  security posture (matches the other destructive kit actions).
- Authorize: retry the MFA challenge lookup once before failing open, so a
  transient blip does not permanently disable the client-side gate for the
  render lifecycle (the server /authorize backstop stays authoritative).
- i18n(de): AUTHENTICATOR -> 'Authentifikatoren' (plural device noun, matching
  en/fr/es) instead of 'Authentifizierung' (the process).
# Conflicts:
#	packages/client-web-kit/src/components/entities/user-authenticator/AUserAuthenticatorEnroll.vue
#	packages/client-web-kit/src/components/workflows/mfa/AMfaChallengeForm.vue
#	packages/client-web-kit/test/unit/components/workflows/mfa-challenge.spec.ts
#	packages/i18n/src/catalogs/de/client.ts
#	packages/i18n/src/catalogs/en/client.ts
#	packages/i18n/src/catalogs/es/client.ts
#	packages/i18n/src/catalogs/fr/client.ts
#	packages/i18n/src/constants.ts
@tada5hi

tada5hi commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
✅ Action performed

Full review finished.


Your plan includes PR reviews subject to rate limits. More reviews will be available in 31 minutes.

tada5hi added 2 commits July 13, 2026 12:20
- enrollEmail: update the existing email marker row in place instead of
  remove-then-create, so a failed save can never leave the user with no email
  factor (the row carries no secret/codes — an in-place update is equivalent).
- verify: EMAIL has no persisted anti-replay backstop (its single-use rides on
  the verify lock + cache drop), so it must NOT ride the lock's fail-open path.
  acquireVerifyLock now reports acquired | busy | unavailable; EMAIL fails
  closed when the lock is unavailable (cache down), while TOTP/recovery keep
  proceeding on their persisted backstops. Only release a lock we actually hold.
- sendChallenge: add a per-user send cooldown (atomic set-if-absent, fails open
  on cache error) so an authenticated caller cannot spray unlimited OTP mails;
  a resend within the window throws MfaThrottledError (429).
- AMfaChallengeForm: emit the original exception through `failed` (was a string)
  so consumers can inspect status/context, matching AUserAuthenticatorEnroll;
  add a resend action to the email verification form (a delayed/expired code
  otherwise dead-ends the flow — the server cooldown backs it).
# Conflicts:
#	apps/server-core/src/core/entities/user-authenticator/constants.ts
#	apps/server-core/src/core/entities/user-authenticator/service.ts
@tada5hi

tada5hi commented Jul 13, 2026 •

Copy link
Copy Markdown
Collaborator Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
✅ Action performed

Full review finished.


Your plan includes PR reviews subject to rate limits. More reviews will be available in 10 minutes.

Base automatically changed from feat/mfa-email-otp to master July 13, 2026 10:33
# Conflicts:
#	.agents/architecture.md
#	apps/server-core/src/core/entities/user-authenticator/constants.ts
#	apps/server-core/src/core/entities/user-authenticator/service.ts
#	apps/server-core/test/unit/core/entities/user-authenticator/service.spec.ts
#	packages/client-web-kit/src/components/entities/user-authenticator/AUserAuthenticatorEnroll.vue
#	packages/client-web-kit/src/components/workflows/mfa/AMfaChallengeForm.vue
#	packages/client-web-kit/test/unit/components/workflows/mfa-challenge.spec.ts
#	packages/i18n/src/catalogs/de/client.ts
#	packages/i18n/src/catalogs/en/client.ts
#	packages/i18n/src/catalogs/es/client.ts
#	packages/i18n/src/catalogs/fr/client.ts
#	packages/i18n/src/constants.ts
@tada5hi

tada5hi commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
✅ Action performed

Full review finished.


Your plan includes PR reviews subject to rate limits. More reviews will be available in 2 minutes.

@tada5hi

tada5hi commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
✅ Action performed

Full review finished.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (2)
packages/client-web-kit/src/components/workflows/mfa/AMfaChallengeForm.vue (1)

149-178: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use the WebAuthn options type instead of as never. startAuthentication takes { optionsJSON }, and optionsJSON is PublicKeyCredentialRequestOptionsJSON, so the current cast throws away type safety. Cast to the exported WebAuthn type (or type challenge.webauthn more precisely) instead.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/client-web-kit/src/components/workflows/mfa/AMfaChallengeForm.vue`
around lines 149 - 178, The authenticateWithPasskey function currently casts
WebAuthn options to never, discarding type safety. Type optionsJSON as the
exported PublicKeyCredentialRequestOptionsJSON type (or type challenge.webauthn
precisely) and pass it to startAuthentication without the never cast.
apps/server-core/src/app/modules/http/modules/controller.ts (1)

773-789: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Reuse the exported webauthn option type instead of retyping it inline.

The local webauthn variable re-declares the same shape as UserAuthenticatorServiceOptions['webauthn'] (types.ts). Importing it avoids the two definitions drifting apart later.

♻️ Proposed refactor
-        let issuer : string | undefined;
-        let webauthn : {
-            rpId: string, 
-            rpName: string, 
-            origin: string 
-        } | undefined;
+        let issuer : string | undefined;
+        let webauthn : UserAuthenticatorServiceOptions['webauthn'];
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/server-core/src/app/modules/http/modules/controller.ts` around lines 773
- 789, Replace the inline type annotation on the local webauthn variable in the
controller with the exported UserAuthenticatorServiceOptions['webauthn'] type
from types.ts, importing the required type as needed. Preserve the existing URL
parsing and assignment behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/server-core/src/core/entities/user-authenticator/service.ts`:
- Around line 530-561: Update confirmWebauthn to apply the same brute-force
throttling lifecycle as the TOTP branch in confirm: call assertNotThrottled
before verifyWebauthnRegistration, bumpAttempts when verification fails or
throws, and resetAttempts after successful verification. Reuse the existing
throttle symbols and preserve the current credential-invalid behavior.
- Around line 270-311: Update enrollWebauthn to create and save the
authenticator entity before caching the challenge, then key the registration
cache with entity.id instead of user.id. Update confirmWebauthn to look up and
remove the cached challenge using entity.id, preserving the existing
verification flow while isolating concurrent ceremonies per enrollment.

In
`@packages/client-web-kit/src/components/entities/user-authenticator/AUserAuthenticatorEnroll.vue`:
- Around line 99-110: Update the WEBAUTHN branch in AUserAuthenticatorEnroll to
require response.webauthn before calling startRegistration, throwing a clear
error when it is absent instead of using an empty-object fallback. Replace the
as never cast with a type-safe assertion or correct response typing compatible
with PublicKeyCredentialCreationOptionsJSON, then preserve the existing
confirmation and done-event flow.

In `@packages/client-web-kit/src/components/workflows/mfa/AMfaChallengeForm.vue`:
- Around line 210-226: Update the WebAuthn VCButton in the isWebauthn branch to
also be disabled when props.challenge?.webauthn is absent, while preserving the
existing busy-state behavior. Keep authenticateWithPasskey unchanged and ensure
the unavailable-options state presents a disabled button.

---

Nitpick comments:
In `@apps/server-core/src/app/modules/http/modules/controller.ts`:
- Around line 773-789: Replace the inline type annotation on the local webauthn
variable in the controller with the exported
UserAuthenticatorServiceOptions['webauthn'] type from types.ts, importing the
required type as needed. Preserve the existing URL parsing and assignment
behavior.

In `@packages/client-web-kit/src/components/workflows/mfa/AMfaChallengeForm.vue`:
- Around line 149-178: The authenticateWithPasskey function currently casts
WebAuthn options to never, discarding type safety. Type optionsJSON as the
exported PublicKeyCredentialRequestOptionsJSON type (or type challenge.webauthn
precisely) and pass it to startAuthentication without the never cast.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 97a26b07-57d0-4b21-8239-5c12c7dcc8fb

📥 Commits

Reviewing files that changed from the base of the PR and between 23fe82f and 84027f3.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (20)
  • .agents/architecture.md
  • apps/server-core/package.json
  • apps/server-core/src/app/modules/http/modules/controller.ts
  • apps/server-core/src/core/entities/user-authenticator/constants.ts
  • apps/server-core/src/core/entities/user-authenticator/index.ts
  • apps/server-core/src/core/entities/user-authenticator/service.ts
  • apps/server-core/src/core/entities/user-authenticator/types.ts
  • apps/server-core/src/core/entities/user-authenticator/webauthn.ts
  • apps/server-core/test/unit/core/entities/user-authenticator/service.spec.ts
  • packages/client-web-kit/package.json
  • packages/client-web-kit/src/components/entities/user-authenticator/AUserAuthenticatorEnroll.vue
  • packages/client-web-kit/src/components/workflows/authorize/Authorize.vue
  • packages/client-web-kit/src/components/workflows/mfa/AMfaChallengeForm.vue
  • packages/client-web-kit/test/unit/components/workflows/mfa-challenge.spec.ts
  • packages/core-http-kit/src/domains/entities/user-authenticator/types.ts
  • packages/i18n/src/catalogs/de/client.ts
  • packages/i18n/src/catalogs/en/client.ts
  • packages/i18n/src/catalogs/es/client.ts
  • packages/i18n/src/catalogs/fr/client.ts
  • packages/i18n/src/constants.ts

@tada5hi

tada5hi commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai pause

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
✅ Action performed

Reviews paused.

- enrollWebauthn/confirmWebauthn: key the registration challenge by the new
  row id instead of the user id, so overlapping enrollment ceremonies (a
  second tab, a retry after a cancelled prompt) no longer overwrite each
  other's challenge and make the first confirmation fail spuriously. The row
  is created before the challenge is cached.
- confirmWebauthn: apply the same brute-force throttle lifecycle as the TOTP
  confirm branch (assertNotThrottled / bumpAttempts on a credential-invalid /
  resetAttempts on success) — the attestation verify is a real crypto call
  and must not be retryable without backoff.
- AUserAuthenticatorEnroll: require the server's WebAuthn registration options
  before startRegistration (clear error instead of an empty-object fallback
  that fails obscurely in the browser), and replace the `as never` cast with a
  documented assertion to PublicKeyCredentialCreationOptionsJSON.
- AMfaChallengeForm: disable the passkey button when the challenge carries no
  webauthn options, so it can't present a dead button (the user switches
  factors instead).

Tests: per-enrollment challenge keying + concurrent-ceremony isolation, and
the webauthn confirm throttle. Also corrects two pre-existing webauthn cache
assertions that passed vacuously (toBeDefined on a null miss / wrong key
separator — buildCacheKey uses `#p#`, not `:`).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants