mirror of
https://github.com/MasterAcnolo/Freedom-Loader.git
synced 2026-09-27 20:11:15 +02:00
fix: false warn about DownloadPath at startup
This commit is contained in:
@@ -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 };
|
||||||
Reference in New Issue
Block a user