From 7f8d018bcb92efbe7b6ef841d50843821e2bc772 Mon Sep 17 00:00:00 2001 From: MasterAcnolo <68693319+MasterAcnolo@users.noreply.github.com> Date: Fri, 14 Aug 2026 17:18:28 +0200 Subject: [PATCH] fix: false warn about DownloadPath at startup --- app/pathValidator.js | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/app/pathValidator.js b/app/pathValidator.js index e7f3f67..db39cfd 100644 --- a/app/pathValidator.js +++ b/app/pathValidator.js @@ -56,35 +56,30 @@ function validateDownloadPath(userPath) { if (!userPath) return getDefaultDownloadPath(); try { + const absolutePath = path.resolve(userPath); - /** - * Resolves filesystem symlinks to ensure canonical absolute path. - * Required to prevent path traversal or alias bypass. - */ - const resolved = fs.realpathSync(path.resolve(userPath)); + if (!fs.existsSync(absolutePath)) { + fs.mkdirSync(absolutePath, { recursive: true }); + logger.info(`Download folder created: ${absolutePath}`); + } - if (!fs.existsSync(resolved)) { - fs.mkdirSync(resolved, { recursive: true }); - logger.info(`Download folder created: ${resolved}`); + const real = fs.realpathSync(absolutePath); + + if (!isSafePath(real)) { + throw new Error("Path not allowed: system folders are blocked!"); + } + + return real; } - const real = fs.realpathSync(resolved); - - if (!isSafePath(resolved)) { - throw new Error("Path not allowed: system folders are blocked!"); + catch (err) { + /** + * Handles invalid filesystem paths, permissions issues, or resolution failures. + * Logs diagnostic information before propagating a sanitized error. + */ + logger.error(`Invalid download path: ${userPath} — ${err.message}`); + throw new Error(`Invalid or inaccessible path: ${err.message}`); } - - return real; - } - catch (err) { - - /** - * Handles invalid filesystem paths, permissions issues, or resolution failures. - * Logs diagnostic information before propagating a sanitized error. - */ - logger.error(`Invalid download path: ${userPath} — ${err.message}`); - throw new Error(`Invalid or inaccessible path: ${err.message}`); - } } module.exports = { validateDownloadPath, getDefaultDownloadPath }; \ No newline at end of file