Skip to content

Commit 1fdbe87

Browse files
committed
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
1 parent 67278d8 commit 1fdbe87

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

  • apps/dokploy/server/api/routers

apps/dokploy/server/api/routers/user.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
apiUpdateUser,
2424
invitation,
2525
member,
26+
session,
2627
user,
2728
} from "@dokploy/server/db/schema";
2829
import {
@@ -32,7 +33,7 @@ import {
3233
import { hasValidLicense } from "@dokploy/server/services/proprietary/license-key";
3334
import { TRPCError } from "@trpc/server";
3435
import * as bcrypt from "bcrypt";
35-
import { and, asc, eq, gt } from "drizzle-orm";
36+
import { and, asc, eq, gt, ne } from "drizzle-orm";
3637
import { z } from "zod";
3738
import { audit } from "@/server/api/utils/audit";
3839
import {
@@ -229,6 +230,15 @@ export const userRouter = createTRPCRouter({
229230
password: bcrypt.hashSync(input.password, 10),
230231
})
231232
.where(eq(account.userId, ctx.user.id));
233+
234+
await db
235+
.delete(session)
236+
.where(
237+
and(
238+
eq(session.userId, ctx.user.id),
239+
ne(session.id, ctx.session.id),
240+
),
241+
);
232242
}
233243

234244
try {

0 commit comments

Comments
 (0)