diff options
author | Georg Ehrke <dev@georgswebsite.de> | 2012-04-26 17:55:00 +0200 |
---|---|---|
committer | Georg Ehrke <dev@georgswebsite.de> | 2012-04-26 17:55:00 +0200 |
commit | 40f95ffdf3edf9ab45c15bd5b9018d7f4d92baa9 (patch) | |
tree | af8aeba6f15770a2d07e9489dfc9490572b0d2e6 /lib | |
parent | 0249a72caba9f1a4eeaf51f382a74fe61b66c284 (diff) | |
download | nextcloud-server-40f95ffdf3edf9ab45c15bd5b9018d7f4d92baa9.tar.gz nextcloud-server-40f95ffdf3edf9ab45c15bd5b9018d7f4d92baa9.zip |
fix security check for the path of the requested file
Diffstat (limited to 'lib')
-rw-r--r-- | lib/base.php | 14 | ||||
-rwxr-xr-x | lib/helper.php | 19 |
2 files changed, 29 insertions, 4 deletions
diff --git a/lib/base.php b/lib/base.php index bb6dc3d8d70..74693641f6e 100644 --- a/lib/base.php +++ b/lib/base.php @@ -276,7 +276,7 @@ class OC{ } public static function loadapp(){ - if(file_exists(OC::$APPSROOT . '/apps/' . OC::$REQUESTEDAPP)){ + if(file_exists(OC::$APPSROOT . '/apps/' . OC::$REQUESTEDAPP . '/index.php')){ require_once(OC::$APPSROOT . '/apps/' . OC::$REQUESTEDAPP . '/index.php'); }else{ trigger_error('The requested App was not found.', E_USER_ERROR);//load default app instead? @@ -414,7 +414,7 @@ class OC{ register_shutdown_function(array('OC_Helper','cleanTmp')); self::$REQUESTEDAPP = (isset($_GET['app'])?strip_tags($_GET['app']):'files'); - self::$REQUESTEDFILE = $_GET['getfile']; + self::$REQUESTEDFILE = (isset($_GET['getfile'])?$_GET['getfile']:null); if(substr_count(self::$REQUESTEDFILE, '?') != 0){ $file = substr(self::$REQUESTEDFILE, 0, strpos(self::$REQUESTEDFILE, '?')); $param = substr(self::$REQUESTEDFILE, strpos(self::$REQUESTEDFILE, '?') + 1); @@ -423,7 +423,15 @@ class OC{ self::$REQUESTEDFILE = $file; $_GET['getfile'] = $file; } - self::$REQUESTEDFILE = (isset($_GET['getfile'])?(OC_Helper::issubdirectory(OC::$APPSROOT . '/' . self::$REQUESTEDAPP . '/' . self::$REQUESTEDFILE, OC::$APPSROOT . '/' . self::$REQUESTEDAPP)?self::$REQUESTEDFILE:null):null); + if(!is_null(self::$REQUESTEDFILE)){ + $subdir = OC::$APPSROOT . '/' . self::$REQUESTEDAPP . '/' . self::$REQUESTEDFILE; + $parent = OC::$APPSROOT . '/' . self::$REQUESTEDAPP; + if(!OC_Helper::issubdirectory($subdir, $parent)){ + self::$REQUESTEDFILE = null; + //header('HTTP/1.0 404 Not Found'); + exit; + } + } } } diff --git a/lib/helper.php b/lib/helper.php index a89aa4d37fc..1d9862bf8b1 100755 --- a/lib/helper.php +++ b/lib/helper.php @@ -560,6 +560,23 @@ class OC_Helper { * @return bool */ public static function issubdirectory($sub, $parent){ - return (substr(realpath($sub), 0, strlen(realpath($parent))) == realpath($parent))?true:false; + if($sub == null || $sub == '' || $parent == null || $parent == ''){ + return false; + } + $realpath_sub = realpath($sub); + $realpath_parent = realpath($parent); + if(($realpath_sub == false && substr_count($realpath_sub, './') != 0) || ($realpath_parent == false && substr_count($realpath_parent, './') != 0)){ //it checks for both ./ and ../ + return false; + } + if($realpath_sub && $realpath_sub != '' && $realpath_parent && $realpath_parent != ''){ + if(substr($sub, 0, strlen($parent)) == $parent){ + return true; + } + }else{ + if(substr($realpath_sub, 0, strlen($realpath_parent)) == $realpath_parent){ + return true; + } + } + return false; } } |