From 854c26a2a30cbba2cb9b734662aaf41876a42556 Mon Sep 17 00:00:00 2001 From: Kenji ITO Date: Thu, 23 Nov 2017 20:41:43 +0900 Subject: [PATCH] Added another security check to cached files --- system/classes/Cache/FileSystem.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/system/classes/Cache/FileSystem.php b/system/classes/Cache/FileSystem.php index bb6f61d61..3031c5967 100644 --- a/system/classes/Cache/FileSystem.php +++ b/system/classes/Cache/FileSystem.php @@ -11,6 +11,8 @@ */ class FileSystem implements CacheInterface { + const SECURITY_HEADER = "\n"; + /** * @var string */ @@ -120,6 +122,8 @@ public function get($key, $defaultValue = null) return $defaultValue; } + // Remove security header + $temp = str_replace(self::SECURITY_HEADER, '', $temp); $data = @unserialize($temp); if ($data === false) { @@ -157,8 +161,9 @@ public function set($key, $data, $ttl = 0) 'ttl' => (int) $ttl, 'hash' => $this->getHash($data), ); + $serialized = self::SECURITY_HEADER . serialize($item); - return (@file_put_contents($fileName, serialize($item)) !== false); + return (@file_put_contents($fileName, $serialized) !== false); } /**