From 8b19fca9927cdec07cc9dd09bdcf2496a5ae69b3 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Wed, 25 Jan 2017 08:30:19 -0600 Subject: [PATCH 1/3] sanitize the image path before processing --- web/views/file.php | 56 --------------------------------------------- web/views/image.php | 31 ++++++++++++------------- 2 files changed, 15 insertions(+), 72 deletions(-) delete mode 100644 web/views/file.php diff --git a/web/views/file.php b/web/views/file.php deleted file mode 100644 index 9b49ff059d..0000000000 --- a/web/views/file.php +++ /dev/null @@ -1,56 +0,0 @@ - diff --git a/web/views/image.php b/web/views/image.php index a7aacb6d20..df454d792f 100644 --- a/web/views/image.php +++ b/web/views/image.php @@ -78,24 +78,23 @@ function imagescale($image, $new_width, $new_height = -1, $mode = 0) } else { $errorText = "No image path"; } -} -else -{ - $path = ZM_DIR_EVENTS . '/' . $_REQUEST['path']; - if ( !empty($user['MonitorIds']) ) - { - $imageOk = false; - $pathMonId = substr( $path, 0, strspn( $path, "1234567890" ) ); - foreach ( preg_split( '/["\'\s]*,["\'\s]*/', $user['MonitorIds'] ) as $monId ) - { - if ( $pathMonId == $monId ) - { - $imageOk = true; - break; +} else { + $path = realpath(ZM_DIR_EVENTS . '/' . $_REQUEST['path']); + if(strpos($path, ZM_DIR_EVENTS) == 0 && strpos($path, ZM_DIR_EVENTS) === true) { + if ( !empty($user['MonitorIds']) ) { + $imageOk = false; + $pathMonId = substr( $path, 0, strspn( $path, "1234567890" ) ); + foreach ( preg_split( '/["\'\s]*,["\'\s]*/', $user['MonitorIds'] ) as $monId ) { + if ( $pathMonId == $monId ) { + $imageOk = true; + break; + } } + if ( !$imageOk ) + $errorText = "No image permissions"; } - if ( !$imageOk ) - $errorText = "No image permissions"; + } else { + $errorText = "Invalid image path"; } } From 6189d2670cb397e99f4f35bf1f0c0258a579a8ed Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Wed, 25 Jan 2017 09:05:34 -0600 Subject: [PATCH 2/3] ZM_DIR_EVENTS can be, and often is, a symlink --- web/views/image.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/web/views/image.php b/web/views/image.php index df454d792f..bb9335353e 100644 --- a/web/views/image.php +++ b/web/views/image.php @@ -79,8 +79,10 @@ function imagescale($image, $new_width, $new_height = -1, $mode = 0) $errorText = "No image path"; } } else { - $path = realpath(ZM_DIR_EVENTS . '/' . $_REQUEST['path']); - if(strpos($path, ZM_DIR_EVENTS) == 0 && strpos($path, ZM_DIR_EVENTS) === true) { + $dir_events = realpath(ZM_DIR_EVENTS); + $path = realpath($dir_events . '/' . $_REQUEST['path']); + + if(strpos($path, $dir_events) == 0) { if ( !empty($user['MonitorIds']) ) { $imageOk = false; $pathMonId = substr( $path, 0, strspn( $path, "1234567890" ) ); From dbd73690b28973f1893886af5c7b99d470932678 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Wed, 25 Jan 2017 09:26:07 -0600 Subject: [PATCH 3/3] use !== false rather than === true --- web/views/image.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/web/views/image.php b/web/views/image.php index bb9335353e..82f0ed046b 100644 --- a/web/views/image.php +++ b/web/views/image.php @@ -81,8 +81,9 @@ function imagescale($image, $new_width, $new_height = -1, $mode = 0) } else { $dir_events = realpath(ZM_DIR_EVENTS); $path = realpath($dir_events . '/' . $_REQUEST['path']); + $pos = strpos($path, $dir_events); - if(strpos($path, $dir_events) == 0) { + if($pos == 0 && $pos !== false) { if ( !empty($user['MonitorIds']) ) { $imageOk = false; $pathMonId = substr( $path, 0, strspn( $path, "1234567890" ) );