Repository navigation
fix(auth): preserve verified passkey when webauthn register() enrollment fails - #2639
pouyashahrdami wants to merge 1 commit into
Conversation
…ent fails The failed-enrollment cleanup in WebAuthnApi.register() searched for a webauthn factor with a matching friendly name and status !== 'unverified' — i.e. a verified factor — and unenrolled it. A registration that failed on a friendly-name conflict would therefore delete the user's existing, working passkey. Target only a stale unverified factor (a leftover from a previous incomplete attempt) so a retry can succeed, and never touch a verified factor. Add regression tests covering: a verified factor is preserved on failure, a stale unverified factor is cleaned up, and a verified factor sharing a name with a stale unverified one is left intact.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughSummary by CodeRabbit
WalkthroughThe failed WebAuthn enrollment cleanup now targets factors with Merge Risk: 🔵 Low · up to The change preserves verified passkeys and removes only stale unverified factors after failed enrollment. A bounded race remains because factor selection and deletion are separate operations, so concurrent enrollment or verification could remove the wrong factor belonging to the same account; this should remain an explicit owner follow-up. 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. Comment |
|
Hi @pouyashahrdami, thank you for contributing to Supabase! 💚 Closing this in favour of #2641, which makes the same one character fix but puts its tests in the existing Nothing wrong with your diff, it came down to test placement. The report in #2640 was yours and the trace you wrote made this quick to confirm, so credit for the fix is yours either way. Thanks again! |
Fixes #2640
Description
mfa.webauthn.register()runs a cleanup step when its internal enrollment call fails. That cleanup looked up a webauthn factor matching the requested friendly name withstatus !== 'unverified'— i.e. a verified factor — and unenrolled it:Enrollment commonly fails on a friendly-name conflict — precisely the case where a verified factor with that name already exists. So a user who retries registration with an existing name (or whose UI naively retries after a transient error) has their existing, working passkey silently deleted, while the call just returns the original enrollment error.
The sensible cleanup semantics here are the opposite: remove a stale unverified factor left behind by a previous incomplete attempt so a retry can succeed, and never touch a verified factor. This PR flips the condition to
status === 'unverified'.Type of Change
Testing
Adds
packages/core/auth-js/test/webauthn.register.test.tscovering the failed-enrollment cleanup path:All three tests fail against the previous
!== 'unverified'behavior and pass with the fix.nx lint auth-js,nx build auth-js, andprettier --checkall pass.Checklist
nx format)nx build auth-js)