fix(auth): retire password reset links when the account's email or password changes

A reset link is a credential sent to the address the account had when it
was asked for. It stayed valid for its full hour after the account moved
to another address or got a new password, so a link sent to the old
mailbox could still set a password on the account.

Changing the email in the user's own settings, changing the password,
and an admin changing a user's email or setting a password now consume
every live reset link of that user, in the same transaction as the
change. Saving the same address, or it in another case, keeps the link,
and a link asked for afterwards works as before.
This commit is contained in:
Maurice
2026-11-26 10:17:13 +01:00
parent 96b2778c2f
commit 4f66a344ca
5 changed files with 152 additions and 4 deletions
+5 -1
View File
@@ -275,7 +275,8 @@ export class AdminService {
// An address the admin enters is one the admin vouches for, so an SSO sign-in
// may link to it again. The edit dialog sends the email on every save, so only
// a new address counts, not the unchanged one or the same one in another case.
if (email && email.toLowerCase() !== user.email.toLowerCase()) patch.email_self_asserted = 0;
const emailChanged = !!email && email.toLowerCase() !== user.email.toLowerCase();
if (emailChanged) patch.email_self_asserted = 0;
if (role) patch.role = role;
if (password) {
patch.password_hash = passwordHash!;
@@ -302,6 +303,9 @@ export class AdminService {
}
}
await this.users.applyAdminEdit(userId, patch);
// A reset link sent to the old address, or asked for before the admin set
// a password, must not reopen the account afterwards.
if (emailChanged || password) await this.auth.retirePasswordResetLinks(userId);
if (password) {
// The version bump only invalidates JWT cookies. These two stores carry