Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/phpFastCache/Util/OpenBaseDir.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
namespace phpFastCache\Util;
define('PHP_OPEN_BASEDIR', @ini_get("open_basedir"));

class OpenBaseDir {
public static $stores = array();
public static function checkBaseDir($path) {
if(!is_null(PHP_OPEN_BASEDIR) && PHP_OPEN_BASEDIR != "") {
/*
* ONLY check ONE time if System Have Open Base Dir
* Else, always return TRUE for system without OPenBaseDir
*/
$index = md5($path);
if (!isset(self::$stores[$index])) {
// never check before, then check it 1 one time for the src dir only
$list = explode(":", PHP_OPEN_BASEDIR);
foreach ($list as $allowed_path) {
$tmp = explode($allowed_path, $path, 2);
if ($tmp[0] != $path) {
// echo "<br>".$tmp[0]." = ".$path." BY {$allowed_path}";
self::$stores[$index] = true;
return true;
}

}
} else {
return self::$stores[$index];
}
return false;
}
return true;
}
}
7 changes: 4 additions & 3 deletions src/phpFastCache/phpFastCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@
*/

use phpFastCache\CacheManager;
use phpFastCache\Util\OpenBaseDir;
define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));

require_once __DIR__."/Util/OpenBaseDir.php";
/**
* Register Autoload
*/
spl_autoload_register(function ($entity) {
// Explode is faster than substr & strstr also more control
$module = explode('\\',$entity,2);
if ($module[0] !== 'phpFastCache') {
if ($module[0] !== 'phpFastCache'
|| !OpenBaseDir::checkBaseDir(__DIR__)) {
/**
* Not a part of phpFastCache file
* then we return here.
Expand All @@ -30,7 +32,6 @@
}

$entity = str_replace('\\', '/', $module[1]);

$path = __DIR__ . '/' . $entity . '.' . PHP_EXT;
if (is_readable($path)) {
require_once $path;
Expand Down