fix(identity): update last_sign_in_at on subsequent external sign-ins (fixes #2563) - #2714
fix(identity): update last_sign_in_at on subsequent external sign-ins (fixes #2563)#2714deepshekhardas wants to merge 2 commits into
Conversation
|
|
||
| now := time.Now() | ||
| identity.IdentityData = identityData | ||
| identity.LastSignInAt = &now |
There was a problem hiding this comment.
⚪ Severity: LOW
An external IdP response can drive an existing, unconfirmed identity through this branch. When unverified provider email sign-ins are disallowed, the surrounding flow returns CommitWithError, which commits changes despite issuing no token; this new assignment therefore lets rejected attempts advance last_sign_in_at and poison the identity’s sign-in/audit signal.
Helpful? Add 👍 / 👎
💡 Fix Suggestion
Suggestion: The fix requires changes at two separate locations in createAccountFromExternalIdentity:
-
In the
AccountExistscase (around lines 370–375): Remove theidentity.LastSignInAt = &nowassignment (line 372) and drop"last_sign_in_at"from theUpdateOnlycall so onlyidentity_datais eagerly persisted — the call should becometx.UpdateOnly(identity, "identity_data"). This prevents the timestamp from being written to the database in the same transaction that can be committed viaCommitWithError. -
In the confirmed-user success path (the
elsebranch around line 440): After the audit log entry, add the deferredlast_sign_in_atupdate that was removed above:
now := time.Now()
identity.LastSignInAt = &now
if terr = tx.UpdateOnly(identity, "last_sign_in_at"); terr != nil {
return 0, nil, terr
}This ensures last_sign_in_at is only persisted when the sign-in actually succeeds (i.e., a token will be issued), rather than being committed eagerly for rejected attempts.
fix(identity): update last_sign_in_at on subsequent external sign-ins (fixes #2563)
createAccountFromExternalIdentityalready listedlast_sign_in_atinthe
UpdateOnlycall for theAccountExistspath, but never assignedthe current time to
identity.LastSignInAtfirst — so the columnsilently kept its creation-time value. The docs describe
last_sign_in_atas "the timestamp that the identity was last used tosign in", but it froze at identity creation.
Set
identity.LastSignInAt = &nowbefore the update so subsequentsign-ins via the identity refresh the timestamp.