From e5b748052375eeb678052d903cd1d0978f97d522 Mon Sep 17 00:00:00 2001 From: Hamza ALMALI <33629178+hamzaalmali@users.noreply.github.com> Date: Tue, 15 Oct 2024 19:59:00 +0300 Subject: [PATCH] Path.join Added platform independent and more secure file path using path.join --- src/controller/miscController.ts | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/controller/miscController.ts b/src/controller/miscController.ts index ea8e51aa58..799245d87e 100644 --- a/src/controller/miscController.ts +++ b/src/controller/miscController.ts @@ -16,7 +16,7 @@ import { Request, Response } from 'express'; import fs from 'fs'; - +import path from 'path'; import { logger } from '..'; import config from '../config'; import { backupSessions, restoreSessions } from '../util/manageSession'; @@ -160,15 +160,23 @@ export async function clearSessionData(req: Request, res: Response) { delete clientsArray[req.params.session]; await req.client.logout(); } - const path = config.customUserDataDir + session; - const pathToken = __dirname + `../../../tokens/${session}.data.json`; - if (fs.existsSync(path)) { - await fs.promises.rm(path, { + const userDataPath = path.join(config.customUserDataDir, session); + const tokenFilePath = path.join(__dirname, '../../tokens', `${session}.data.json`); + if (fs.existsSync(userDataPath)) { + await fs.promises.rm(userDataPath, { recursive: true, + maxRetries: 5, + force: true, + retryDelay: 1000, }); } - if (fs.existsSync(pathToken)) { - await fs.promises.rm(pathToken); + if (fs.existsSync(tokenFilePath)) { + await fs.promises.rm(tokenFilePath, { + recursive: true, + maxRetries: 5, + force: true, + retryDelay: 1000, + }); } return res.status(200).json({ success: true }); } catch (error: any) {