From 1fdbe87d84c0481ec5e1c1f4a159aebae9556028 Mon Sep 17 00:00:00 2001 From: Mauricio Siu Date: Wed, 13 May 2026 00:49:32 -0600 Subject: [PATCH] feat(user): implement session cleanup on user update - Added functionality to delete old sessions when a user updates their password, ensuring that only the current session remains active. - This change enhances security by preventing unauthorized access from previous sessions after a password change. Close here https://github.com/Dokploy/dokploy/security/advisories/GHSA-rr9m-w87g-46f3 --- apps/dokploy/server/api/routers/user.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/apps/dokploy/server/api/routers/user.ts b/apps/dokploy/server/api/routers/user.ts index 538cbe7f5..fc3b29d6e 100644 --- a/apps/dokploy/server/api/routers/user.ts +++ b/apps/dokploy/server/api/routers/user.ts @@ -23,6 +23,7 @@ import { apiUpdateUser, invitation, member, + session, user, } from "@dokploy/server/db/schema"; import { @@ -32,7 +33,7 @@ import { import { hasValidLicense } from "@dokploy/server/services/proprietary/license-key"; import { TRPCError } from "@trpc/server"; import * as bcrypt from "bcrypt"; -import { and, asc, eq, gt } from "drizzle-orm"; +import { and, asc, eq, gt, ne } from "drizzle-orm"; import { z } from "zod"; import { audit } from "@/server/api/utils/audit"; import { @@ -229,6 +230,15 @@ export const userRouter = createTRPCRouter({ password: bcrypt.hashSync(input.password, 10), }) .where(eq(account.userId, ctx.user.id)); + + await db + .delete(session) + .where( + and( + eq(session.userId, ctx.user.id), + ne(session.id, ctx.session.id), + ), + ); } try {