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,28 +56,23 @@ 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(resolved)) {
fs.mkdirSync(resolved, { recursive: true });
logger.info(`Download folder created: ${resolved}`);
if (!fs.existsSync(absolutePath)) {
fs.mkdirSync(absolutePath, { recursive: true });
logger.info(`Download folder created: ${absolutePath}`);
}
const real = fs.realpathSync(resolved);
const real = fs.realpathSync(absolutePath);
if (!isSafePath(resolved)) {
if (!isSafePath(real)) {
throw new Error("Path not allowed: system folders are blocked!");
}
return real;
}
catch (err) {
catch (err) {
/**
* Handles invalid filesystem paths, permissions issues, or resolution failures.
* Logs diagnostic information before propagating a sanitized error.