Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > it.comp.www.php > #22095

Re: Limitare filebrowser ad una directory radice

From Alessandro Pellizzari <shuriken@amiran.it>
Newsgroups it.comp.www.php
Subject Re: Limitare filebrowser ad una directory radice
Date 2018-06-14 09:38 +0100
Message-ID <foenraFsj3U1@mid.individual.net> (permalink)
References <slrnpi43pi.3kb.gbertozzi@debian.asus.home>

Show all headers | View raw


On 14/06/18 07:46, Gianfranco wrote:

>   Il problema e' come evitare che passando un parametro ad hoc si
> scavalchi la radice "./documenti", ad esempio con "Dir=./documenti/../"
> oppure "Dir=/dir-esterna/".

Use realpath() per calcolare il path effettivo a cui l'utente vuole
accedere, poi controlli che inizi con il path che hai definito, e se non
lo fa torni errore.

$pathCondiviso = "/var/www/shared/";

$pathRichiesto = realpath($pathCondiviso . $_GET['Dir']);

if (mb_substr($pathRichiesto, 0, mb_strlen($pathCondiviso)) !==
$pathCondiviso) {
  exit 'Not allowed';
}

O qualcosa del genere. Tweak a piacere.

Bye.

Back to it.comp.www.php | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Limitare filebrowser ad una directory radice Gianfranco <gbertozzi@gmail.com> - 2018-06-14 06:46 +0000
  Re: Limitare filebrowser ad una directory radice Alessandro Pellizzari <shuriken@amiran.it> - 2018-06-14 09:38 +0100
    Re: Limitare filebrowser ad una directory radice Gianfranco <gbertozzi@gmail.com> - 2018-06-14 10:37 +0000
      Re: Limitare filebrowser ad una directory radice Gianfranco <gbertozzi@gmail.com> - 2018-06-14 14:26 +0000

csiph-web