fix: false warn about DownloadPath at startup

This commit is contained in:
MasterAcnolo
2026-08-14 17:18:28 +02:00
parent 6c517255e3
commit 7f8d018bcb

View File

@@ -56,35 +56,30 @@ function validateDownloadPath(userPath) {
if (!userPath) return getDefaultDownloadPath(); if (!userPath) return getDefaultDownloadPath();
try { try {
const absolutePath = path.resolve(userPath);
/** if (!fs.existsSync(absolutePath)) {
* Resolves filesystem symlinks to ensure canonical absolute path. fs.mkdirSync(absolutePath, { recursive: true });
* Required to prevent path traversal or alias bypass. logger.info(`Download folder created: ${absolutePath}`);
*/ }
const resolved = fs.realpathSync(path.resolve(userPath));
if (!fs.existsSync(resolved)) { const real = fs.realpathSync(absolutePath);
fs.mkdirSync(resolved, { recursive: true });
logger.info(`Download folder created: ${resolved}`); if (!isSafePath(real)) {
throw new Error("Path not allowed: system folders are blocked!");
}
return real;
} }
const real = fs.realpathSync(resolved); catch (err) {
/**
if (!isSafePath(resolved)) { * Handles invalid filesystem paths, permissions issues, or resolution failures.
throw new Error("Path not allowed: system folders are blocked!"); * 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 }; module.exports = { validateDownloadPath, getDefaultDownloadPath };