Fix: Centralize default download path and enhance path validation logic

This commit is contained in:
MasterAcnolo
2026-02-17 23:29:31 +01:00
parent 45e0840fea
commit 32c9a66a35
6 changed files with 94 additions and 40 deletions

View File

@@ -1,16 +1,20 @@
const path = require("path");
const fs = require("fs");
const os = require("os");
const { app } = require("electron");
const config = require("../../config");
const { logger } = require("../logger.js");
// Centralisation de tous les chemins de ressources
// Centralized resource paths
const resourcesPath = config.localMode
? path.join(__dirname, "../../ressources")
: process.resourcesPath;
// Chemins des binaires
// Default download folder (centralized)
const defaultDownloadFolder = path.join(os.homedir(), "Downloads", "Freedom Loader");
// Binary paths
let userYtDlp;
let ffmpegPath;
let denoPath;
@@ -32,14 +36,14 @@ if (config.localMode) {
}
// Chemins des icônes de notification
// Notification icon paths
const iconPaths = {
confirm: path.join(resourcesPath, "confirm-icon.png"),
error: path.join(resourcesPath, "error.png"),
app: path.join(resourcesPath, "app-icon.ico")
};
// Chemins des binaires pour vérification
// Binary paths for verification
const binaryPaths = {
ytDlp: path.join(resourcesPath, "binaries", "yt-dlp.exe"),
ffmpeg: path.join(resourcesPath, "binaries", "ffmpeg.exe"),
@@ -51,4 +55,4 @@ if (!userYtDlp){ logger.error("Missing YT-DLP")}
if (!ffmpegPath){ logger.error("Missing FFMPEG")}
if (!denoPath){ logger.error("Missing DENO")}
module.exports = { userYtDlp, ffmpegPath, denoPath, iconPaths, binaryPaths, resourcesPath };
module.exports = { userYtDlp, ffmpegPath, denoPath, iconPaths, binaryPaths, resourcesPath, defaultDownloadFolder };

View File

@@ -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 };