diff --git a/index.php b/index.php index 905f28d..67d10ff 100644 --- a/index.php +++ b/index.php @@ -16,6 +16,9 @@ $thumburl = Helpers::end_dir($conf['web_thumbdir']); $galleryname = $conf['gallery_name']; +// Prepare Path Traversal Check +$r_basedir=realpath($imagedir); + // Get Parameters or Set Defaults $page = $_GET['p'] ?? $conf['defpage']; $slice = $_GET['s'] ?? $conf['defslice']; @@ -36,6 +39,12 @@ if (isset($_SESSION['files']) { $files = $_SESSION['files']; } else { + $r_imagedir = realpath($imagedir.$dir); + + if ($r_imagedir === false || strcmp($r_imagedir, $r_basedir . DIRECTORY_SEPARATOR) !== 0) { + print "Path Traversal Detected!"; + exit(); + } $tmpdirs = glob(Helpers::end_dir($imagedir.$dir).'*' , GLOB_ONLYDIR); if (!empty($tmpdirs)) { foreach ($tmpdirs as $tmpdir)