Excuse my terrible French :|
On devrait être sûr que le fichier existe vraiment, et qu’un hacker ne peut pas télécharger une page comme .htaccess ou config.inc.php simplement par changer un parametre.
Voilà quelque chose qui marche ici (0.9.6 / LAMP):
unset($fn);
unset($url);
unset($folder);
if($_GET['f']) {
$fn = trim($_GET['f']);
$fn = str_replace("/", "", $fn);
$fn = str_replace("http", "", $fn);
$fn = str_replace("..", "", $fn);
$fn = str_replace(".htaccess", "", $fn);
$fn = str_replace("passw", "", $fn);
$fn = str_replace(".php", "", $fn);
$fn = str_replace(".ini", "", $fn);
$fn = str_replace(".inc", "", $fn);
$folder = 'assets/files/';
$url = MODX_BASE_PATH . "$folder$fn";
if(file_exists($url)) {
header("Accept-Ranges: bytes");
header("Cache-control: private");
header("Pragma: no-cache");
header("Expires: 0");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=$fn");
header("Content-Transfer-Encoding: binary");
$x = file_get_contents($url);
echo $x;
exit();
}
}
tu mets ça dans un snippet, disons dans un doc avec id 100.
Ce doc n’a aucun template ("blank") et aucun text autre que le snippet call: [!download!]
un link sera donc comme ça: index.php?id=100&f=document.pdf