fix: skip currentPassword check for federated users on change-password

This commit is contained in:
Jannis Braun
2026-03-23 00:48:02 +01:00
parent a888828941
commit 41caf5f90c
+12 -7
View File
@@ -72,13 +72,18 @@ export async function userRoutes(app: FastifyInstance): Promise<void> {
return reply.code(404).send({ error: 'User not found', statusCode: 404 }); return reply.code(404).send({ error: 'User not found', statusCode: 404 });
} }
// All users must provide current password (federated users have a local password hash) // Federated users (replicas on this instance) don't need currentPassword
if (!currentPassword || typeof currentPassword !== 'string') { // their home instance already verified the password change, and JWT auth
return reply.code(400).send({ error: 'Current password is required', statusCode: 400 }); // proves identity. The homeInstance field comes from the DB, not the request.
} if (!user.homeInstance) {
const valid = await verifyPassword(currentPassword, user.passwordHash); // Local users must provide current password
if (!valid) { if (!currentPassword || typeof currentPassword !== 'string') {
return reply.code(403).send({ error: 'Incorrect password', statusCode: 403 }); return reply.code(400).send({ error: 'Current password is required', statusCode: 400 });
}
const valid = await verifyPassword(currentPassword, user.passwordHash);
if (!valid) {
return reply.code(403).send({ error: 'Incorrect password', statusCode: 403 });
}
} }
const newHash = await hashPassword(newPassword); const newHash = await hashPassword(newPassword);