mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
* fix(cognito): serialize attribute verification updates * fix(cognito): serialize AdminDeleteUser against the same per-user lock hectorvent's review: the per-user lock introduced here covered five verification-related operations, but AdminDeleteUser removed the whole user record without acquiring it. A verification finishing after a concurrent admin deletion could resurrect the just-deleted user, since its locked path re-fetches, mutates, and writes back the record with no way to know the record had been deleted out from under it. Wraps AdminDeleteUser in the same lock stripe, following the existing resolve-then-lock-then-mutate pattern used by the other admin paths. Adds a regression test mirroring the PR's existing latch-based style, covering a verification that finishes after a concurrent admin user deletion. * fix(cognito): serialize every user-record mutation on the per-user lock hectorvent's review: the per-user lock introduced here covered only the verification-related operations (plus AdminDeleteUser, added separately). Storage is a plain whole-object get/put/delete with no version or CAS primitive, so any two of the remaining ~19 methods that read, mutate, and write back a user record could still race each other, or race one of the locked operations, and silently lose an update. Wraps every remaining user-mutating path in the same per-user lock stripe, following the existing resolve-then-lock-then-mutate pattern: AdminCreateUser, the internal migrated-user creation path, AdminSetUserPassword, AdminEnableUser, AdminDisableUser, AdminResetUserPassword, AdminLinkProviderForUser (nested inside its existing identityLinkLock, which serializes a pool-wide uniqueness check that a single user's lock can't), AdminAddUserToGroup, AdminRemoveUserFromGroup, DeleteGroup and DeleteUserPool (each user locked individually inside the loop, one at a time, never more than one stripe held at once), SignUp, ConfirmSignUp, AdminConfirmSignUp, ChangePassword, AdminSetUserMFAPreference, and SetUserMFAPreference. AdminCreateUser and SignUp lock on the requested username/alias rather than a resolved canonical id, since an alias pool has no canonical id until creation succeeds; locking the requested value is what actually prevents two concurrent requests for the same identifier from both passing the existence check and creating duplicates. ConfirmForgotPassword and self-service DeleteUserAttributes needed no changes: both fully delegate their mutation to an already-locked method (AdminSetUserPassword, AdminDeleteUserAttributes respectively) rather than writing the user record themselves. Also replaced a pre-existing `var` in ConfirmSignUp (now moved into its locked helper) with the concrete DeliveryTarget type per AGENTS.md. --------- Co-authored-by: Priamo Germosen <6233424+pgermosen@users.noreply.github.com>