fix(server): refuse a password reset of the caller's own account

A reset revokes every token of the account, so resetting oneself ended the
admin session before the temporary password could be read. Own passwords
change through /auth/password.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-06 20:57:17 +00:00
1 parent 8885ee23eb
commit b0fedf2caf
1 file changed
+2
+2
View File
@@ -119,6 +119,8 @@ public static class UserEndpoints
private static async Task<IResult> ResetPasswordAsync(HttpContext context, Caller caller, Guid id, ResetPasswordRequest? request, TitanoDatabase db, AuditLog audit) private static async Task<IResult> ResetPasswordAsync(HttpContext context, Caller caller, Guid id, ResetPasswordRequest? request, TitanoDatabase db, AuditLog audit)
{ {
var ct = context.RequestAborted; var ct = context.RequestAborted;
// A reset ends every session of the account, the caller's too, before the temporary password could be read.
if (id == caller.Id) return ApiErrors.Conflict(context, "self");
if (await db.Users.GetAsync(id, ct) is not { } user) return ApiErrors.NotFound(context, "user"); if (await db.Users.GetAsync(id, ct) is not { } user) return ApiErrors.NotFound(context, "user");
var password = string.IsNullOrEmpty(request?.Password) ? TemporaryPassword.Generate() : request.Password; var password = string.IsNullOrEmpty(request?.Password) ? TemporaryPassword.Generate() : request.Password;
if (!PasswordHasher.IsAcceptable(password)) return WeakPassword(context); if (!PasswordHasher.IsAcceptable(password)) return WeakPassword(context);