Skip to content
Snippets Groups Projects
Commit c88fced8 authored by Prasad's avatar Prasad
Browse files

Enhanced checkFileAccessIn implementation with relpaths

parent 4acf7314
No related branches found
No related tags found
No related merge requests found
...@@ -121,20 +121,39 @@ class Vtiger_Utils { ...@@ -121,20 +121,39 @@ class Vtiger_Utils {
$realfilepath = str_replace('\\', '/', $realfilepath); $realfilepath = str_replace('\\', '/', $realfilepath);
$rootdirpath = str_replace('\\', '/', $rootdirpath); $rootdirpath = str_replace('\\', '/', $rootdirpath);
if(stripos($realfilepath, $rootdirpath) !== 0) { /** Assume not matching. */
if($dieOnFail) { $ok = false;
$a = debug_backtrace();
$backtrace = 'Traced on '.date('Y-m-d H:i:s')."\n"; if(stripos($realfilepath, $rootdirpath) === 0) {
$backtrace .= "FileAccess - \n"; /** Safe path. */
foreach ($a as $b) { if (is_null($relpaths) || empty($relpaths)) {
$backtrace .= $b['file'] . '::' . $b['function'] . '::' . $b['line'] . '<br>'.PHP_EOL; /** No specific path to check. */
} $ok = true;
Vtiger_Utils::writeLogFile('fileMissing.log', $backtrace); } else if (is_array($relpaths)) {
die('Sorry! Attempt to access restricted file.'); /* Check relfilepath against accepted ones. */
} $relfilepath = str_replace(rtrim($rootdirpath, "/"). "/", "", $realfilepath);
return false; foreach ($relpaths as $relpathok) {
if (strpos($relfilepath, $relpathok) === 0) {
/** found a match - break early. */
$ok = true;
break;
}
}
}
} }
return true;
if (!$ok && $dieOnFail) {
$a = debug_backtrace();
$backtrace = 'Traced on '.date('Y-m-d H:i:s')."\n";
$backtrace .= "FileAccess - \n";
foreach ($a as $b) {
$backtrace .= $b['file'] . '::' . $b['function'] . '::' . $b['line'] . '<br>'.PHP_EOL;
}
Vtiger_Utils::writeLogFile('fileMissing.log', $backtrace);
die('Sorry! Attempt to access restricted file.');
}
return $ok;
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment