Invalidate sessions on password change and reset
Session validity was decoupled from credential rotation: changing a password (logged-in flow) or completing a forgot-password reset left every existing iam_sessions row valid until its idle TTL. A user who saw their account compromised on another device had no way to actually evict that device by rotating the password. Inside the same DB transaction as the password update, expire the identity's other active sessions: - ChangePassword keeps the caller's current session and revokes every other session for the identity, so the user is not logged out of the browser they just used. - ResetPassword has no caller session (the user is anonymous, authenticated only by a stateless token) and revokes all of the identity's active sessions. The session middleware already rejects rows with expire_reason set, so revoked sessions are kicked out on the next request without any middleware change. Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
@@ -318,10 +318,12 @@ func (r *mutationResolver) VerifyEmail(ctx context.Context, input types.VerifyEm
|
||||
// ChangePassword is the resolver for the changePassword field.
|
||||
func (r *mutationResolver) ChangePassword(ctx context.Context, input types.ChangePasswordInput) (*types.ChangePasswordPayload, error) {
|
||||
identity := authn.IdentityFromContext(ctx)
|
||||
session := authn.SessionFromContext(ctx)
|
||||
|
||||
err := r.iam.AccountService.ChangePassword(
|
||||
ctx,
|
||||
identity.ID,
|
||||
session.ID,
|
||||
&iam.ChangePasswordRequest{
|
||||
CurrentPassword: input.CurrentPassword,
|
||||
NewPassword: input.NewPassword,
|
||||
|
||||
Reference in New Issue
Block a user