Repository navigation
feat: add support for passkeys as a second factor for authentication - #682
Conversation
- Implemented passkey registration and login flows in the MFA service. - Created new DTOs for passkey-related requests and responses. - Added HTTP handlers for passkey options and verification endpoints. - Updated the MFA handler to manage passkey enrollment and deletion. - Introduced a new in-memory store for managing passkeys during tests. - Added database migration for user_passkeys table to store passkey credentials. - Enhanced error handling for passkey-related operations. - Updated route coverage tests to include new passkey endpoints.
There was a problem hiding this comment.
ℹ️ No critical issues — minor suggestions only. I traced the authorization paths and found no way for a password-holding attacker without a passkey to complete a passkey login, add a passkey to a protected account, or otherwise bypass the second factor.
Reviewed changes — Full passkey second-factor feature: the backend WebAuthn ceremonies, storage, routing and config; the web challenge/setup/management UI; and the new e2e specs.
- Backend passkey service —
mfadomdomain types andmfasvcregister/login/verify ceremonies, with Redis single-use ceremony state keyedreg:/login:/verify:. - Login integration —
Loginnow returnsmfa_methods;BeginPasskeyLogin/CompletePasskeyLoginare bound to the challenge JWT'sjti;CheckLogin/Methodstreat a passkey as a second factor. - Pre-login setup — password-authenticated
/auth/mfa/setup/passkey/{options,finish}, gated bySetupRequiredand refused once any factor exists. - Management —
/users/me/passkeyslist/register/verify/delete; deletion requires a passkey assertion. - Storage & config — migration
000078_add_user_passkeys; relying party derived fromPUBLIC_URLwith optionalPASSKEY_RP_ID. - Web UI — passkey option in
MfaChallengePanel, redesignedMfaLoginSetup, newPasskeysCard, API helpers, i18n across nine locales. - Tests — Go service/handler/route tests, Vitest tests, and Chromium virtual-authenticator e2e specs (e2e not run per the PR).
ℹ️ Silent second-factor downgrade if passkeys become unavailable
hasPasskeys returns false whenever the relying party is unconfigured (wa == nil). For a non-privileged account whose only factor was a passkey, CheckLogin then sees totpOn=false, passkeyOn=false, skips the privileged && RequireMFA branch, and returns nil, so /auth/login issues a full session on the password alone. The code comment anticipates the fallback, but its reasoning ("policy then demands enrollment of a method that works") only holds for privileged roles: an ordinary user who enrolled a passkey is silently downgraded to password-only whenever PUBLIC_URL is unset — for instance after an operator acts on the "changing the host or RP ID" guidance. Worth deciding explicitly whether that is the intended outcome for non-privileged accounts, or whether such accounts should be pushed to re-enroll rather than losing the factor.
Technical details
# Silent 2FA downgrade for non-privileged passkey-only accounts
## Affected sites
- `services/api/internal/service/mfa/passkey.go:102-108` — `hasPasskeys` returns `false` unconditionally when `s.wa == nil` (RP unavailable), without distinguishing "user has no passkeys" from "passkeys are turned off".
- `services/api/internal/service/mfa/mfa_service.go:85-96` — `CheckLogin`: with `totpOn=false` and `passkeyOn=false`, the non-privileged path falls through to `return nil`; only `privileged && policy.RequireMFA` returns `ErrSetupRequired`.
- `services/api/internal/bootstrap/app.go:255-263` — passkeys are disabled whenever `RelyingPartyFromURL` fails (e.g. `PUBLIC_URL` unset).
## Required outcome
- Decide the policy for an account that has registered passkeys but currently has no usable path (passkeys off, no TOTP): silently allow password-only, or treat it as "factor required but unavailable" and fail closed / force enrollment.
- If the fallback is intended, correct the `hasPasskeys` comment, which currently implies policy protects all such accounts.
## Open questions for the human
- Is passing the relying party into the store so `hasPasskeys` can distinguish "no credentials" from "passkeys disabled" desirable, or is a startup-time guard (refuse to boot / log loudly when passkeys are disabled but `user_passkeys` is non-empty) the better lever?deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — re-review of the commit since the prior pullfrog review (b2154cb → 44e72759); the delta addresses all three prior findings and adds regression tests.
- Failed closed when the relying party is unavailable —
hasPasskeysnow gates on the installed passkey store instead of WebAuthn, so an account that registered a passkey keeps owing a second factor whenPUBLIC_URLgoes missing;WithPasskeyStoreinstalls the store even while WebAuthn stays off. - Requested user verification on enrollment —
AuthenticatorSelection.UserVerificationis set toVerificationPreferred, covering both creation and assertion options. - Reset the add-passkey dialog on open —
AddPasskeyDialogclears name, error and mutation in an effect keyed onopen, replacing the reset path thatonOpenChange(true)never reached. - Added regression tests — Go tests for the fail-closed path and the
userVerificationpreference, and a Vitest case for the dialog reset.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
The autofill consumer reads autofill_enabled when it processes a task, not when the task is created. The test disabled autofill, created a task, then re-enabled autofill straight away, so a slow consumer could see "enabled" and call Jev, failing "Jev must not be called while autofill is disabled". Keep autofill off for the rest of the test and use a task in a second project (autofill on) as a barrier: once it is filled, the disabled project's earlier task has already gone through the same stream. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — re-review of the commit since the prior pullfrog review (44e72759 → c4d21963); a test-only race fix with no production surface.
- De-raced the Jev autofill-disabled e2e test —
TestE2EJev_AutofillRespectsProjectSettingsno longer re-enables autofill right after creating the disabled task; it keeps autofill off and uses a task in a second project as a same-stream barrier (mirroring the existingTestE2EJev_UnconfiguredProjectNeverCallsJevpattern), so a slow consumer can no longer read"enabled"and call Jev.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
…improved error handling
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — re-review of the commits since the prior pullfrog review (c4d21963 → 2b0daf20); a backend hardening pass with tests and no web changes.
- Added a
HasPasskeysstore method —hasPasskeysnow runs anEXISTSquery instead of loading every passkey, so one unparseable row can no longer make the second-factor check error. - Mapped duplicate credential inserts to
PASSKEY_INVALID—AddPasskeytranslates the Postgres23505violation of thecredential_iduniqueness constraint intoErrPasskeyInvalid(400) rather than surfacing it as a 500. - Guarded the sign-counter write —
UpdatePasskeyCredentialnow skips the update when the incoming sign counter sits behind the stored one, so two concurrent sign-ins cannot roll the stored counter back. - Skipped unreadable credential records —
loadUserlogs and skips an undecodable credential instead of failing the whole ceremony, so one corrupt row no longer blocks sign-in. - Required user verification to remove a passkey —
BeginPasskeyVerificationnow issuesWithUserVerification(VerificationRequired); login continues to useVerificationPreferred. - Added regression tests — Go tests for the removal UV requirement and the corrupt-sibling-record skip.
- Documented the Redis
GETDELrequirement indeploy/README.md.
I verified the load-bearing library contracts directly against go-webauthn v0.18.2: Authenticator.SignCount carries json:"signCount,omitempty" under Credential.Authenticator (json:"authenticator"), so the new SQL guard's JSON path resolves correctly, and UpdateCounter sets CloneWarning (already rejected by verifyAssertion) before any regression could reach the update. go build ./..., the mfa, postgres, and HTTP test packages all pass.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — re-review of the commit since the prior pullfrog review (2b0daf20 → 51df10e1); a title/localization pass with no server changes.
- Localized the challenge-panel heading —
MfaChallengePanelnow selectslogin.mfa.titleBoth,title, ortitlePasskeyfrom the account's available methods, matching the existing subtitle ternary instead of always showing the generic title. - Added the two new strings to all nine locales —
login.mfa.titleBothandlogin.mfa.titlePasskeyare present and parse cleanly inen,es,fr,ja,ko,pt-BR,ru,vi, andzh-CN.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

Summary
Adds WebAuthn passkeys as a second sign-in factor alongside TOTP. A user can register any number of passkeys; after the password, either a passkey or a TOTP/recovery code completes the sign-in. A passkey also satisfies the "require MFA" policy. Passkeys are not a passwordless login: the password is still the first step.
Behaviour
Sign-in
POST /auth/loginnow returnsmfa_methods(totp,passkey) with the MFA challenge. The challenge page offers "Use a passkey" above the code form, or the passkey alone for an account with no authenticator app.POST /auth/mfa/passkey/optionsand/verifyfinish a challenge with a passkey, mirroring/auth/mfa/verify. The challenge stays single-use, and the IP allow-lists still apply.Managing passkeys (Account → Security → Passkeys)
POST /users/me/passkeys/verify/options, thenDELETEwith the assertion), the same bar as turning TOTP off with a code. Any of the account's passkeys can approve, including the one being removed.When policy requires MFA
POST /auth/mfa/setup/passkey/optionsand/finishlet such an account register a passkey before it can sign in. They are refused for accounts policy does not oblige, and for accounts that already have any second factor, so a stolen password cannot add a passkey to a protected account.Implementation notes
github.com/go-webauthn/webauthn; the web app uses@simplewebauthn/browser.go mod tidyalso bumped a few indirect packages (testify,x/crypto,x/sync,x/sys,x/text).000078_add_user_passkeys.sql:user_passkeysholds the credential id, name, and the JSON credential record. The public key is not a secret, so passkeys work withoutENCRYPTION_KEY.GETDEL, 5 min TTL), so the finish request can reach a different API instance.PASSKEY_INVALID(400) andPASSKEY_LIMIT(409), notAUTH_MFA_INVALID_CODE(401), because a 401 on a signed-in session makes the web client refresh its tokens and retry. At most 20 passkeys per account.mfaOpenRoutes(self-service or credential exchange, like the existing MFA routes); no new permissions.Configuration
PUBLIC_URL: the host is the RP ID and its origin the only accepted origin. They are off whenPUBLIC_URLis unset (the card is hidden,mfa_methodsnever listspasskey, and accounts keep using TOTP).PASSKEY_RP_IDoverrides the RP ID (for example a parent domain to share across subdomains); documented indeploy/README.md. Changing the host or RP ID invalidates every registered passkey.localhost, and the page's host must matchPUBLIC_URL. On plain-HTTP non-localhost hosts the card says passkeys are unsupported.Testing
go test ./...passes. New service tests run real register / sign-in / removal ceremonies against the library using a small software authenticator (ES256,noneattestation), covering replay, a foreign key, a wrong ceremony, the IP allow-list, the policy interplay, and reset. Handler, auth-service and route-coverage tests are extended.tsc -b, Biome and Vitest pass, including new tests for the challenge panel, the setup flow, and the passkeys card.passkeys.feature/passkeys.spec.tsuse Chromium's virtual authenticator, andmfa.spec.tsis updated for the new setup screen. These were typechecked and linted but not run.Not verified
🤖 Generated with Claude Code