mirror of
https://github.com/MasterAcnolo/Freedom-Loader.git
synced 2026-07-29 18:25:47 +02:00
Fix: Centralize default download path and enhance path validation logic
This commit is contained in:
@@ -12,10 +12,35 @@ function isValidUrl(url) {
|
||||
}
|
||||
|
||||
function isSafePath(folder) {
|
||||
if (!folder || folder.length < 3) return false;
|
||||
const unsafe = ["System32", "/etc", "\\Windows"];
|
||||
const resolved = path.resolve(folder);
|
||||
return !unsafe.some(u => resolved.includes(u));
|
||||
if (!folder || typeof folder !== "string") return false;
|
||||
|
||||
try {
|
||||
// Normalize path and resolve symlinks
|
||||
const resolved = path.resolve(folder).toLowerCase().replace(/\//g, "\\");
|
||||
|
||||
// Block Windows system directories (on any drive)
|
||||
const unsafePaths = [
|
||||
"\\windows\\",
|
||||
"\\system32\\",
|
||||
"\\program files\\",
|
||||
"\\program files (x86)\\",
|
||||
"\\programdata\\",
|
||||
"\\$recycle.bin\\",
|
||||
"\\system volume information\\"
|
||||
];
|
||||
|
||||
// Check if path contains any unsafe directory
|
||||
if (unsafePaths.some(unsafe => resolved.includes(unsafe))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Allow all drives (C:, D:, E:, etc.) but block system folders
|
||||
return true;
|
||||
|
||||
} catch (err) {
|
||||
// In case of path resolution error
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { isValidUrl, isSafePath };
|
||||
|
||||
Reference in New Issue
Block a user