Browse Source

move function improve to disable ../ in from and to directory

master
filesite 2 years ago
parent
commit
dad269b6e2
  1. 6
      controller/ApiController.php

6
controller/ApiController.php

@ -53,7 +53,7 @@ Class ApiController extends Controller { @@ -53,7 +53,7 @@ Class ApiController extends Controller {
$realpath = preg_replace('/\/$/', '', $realpath);
$arr = explode('/', $realpath);
if (count($arr) < 2) {return '/';}
if (count($arr) < 2 || empty($arr[0])) {return '/';}
array_pop($arr);
return implode('/', $arr);
@ -61,7 +61,7 @@ Class ApiController extends Controller { @@ -61,7 +61,7 @@ Class ApiController extends Controller {
//判断父目录是否合法
protected function isParentDirectoryValid($parentDir) {
if (empty($parentDir) || strpos($parentDir, '../') !== false) {
if (empty($parentDir) || strpos($parentDir, '..') !== false) {
return false;
}else if ($realpath == '/') {
return true;
@ -286,7 +286,7 @@ Class ApiController extends Controller { @@ -286,7 +286,7 @@ Class ApiController extends Controller {
return $this->renderJson(compact('code', 'msg', 'err', 'data'), $this->httpStatus['notAllowed']);
}
$fromFile = str_replace("{$fromParent}/", '', $fromDir);
$fromFile = $this->basename($fromDir);
$toDir = preg_match('/\/$/', $toDir) ? "{$toDir}{$fromFile}" : "{$toDir}/{$fromFile}";
}

Loading…
Cancel
Save