Skip to content

Commit

Permalink
Merge pull request from GHSA-hrgx-p36p-89q4
Browse files Browse the repository at this point in the history
Crypt/decrypt smarty cache in DB
  • Loading branch information
atomiix authored Jul 25, 2022
2 parents dc8dc1f + f342765 commit b6d96e7
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions classes/Smarty/SmartyCacheResourceMysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
*/
class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom
{
/** @var PhpEncryption */
private $phpEncryption;

public function __construct()
{
$this->phpEncryption = new PhpEncryption(_NEW_COOKIE_KEY_);
}

/**
* fetch cached content and its modification time from data source.
*
Expand All @@ -39,7 +47,7 @@ protected function fetch($id, $name, $cache_id, $compile_id, &$content, &$mtime)
{
$row = Db::getInstance()->getRow('SELECT modified, content FROM ' . _DB_PREFIX_ . 'smarty_cache WHERE id_smarty_cache = "' . pSQL($id, true) . '"');
if ($row) {
$content = $row['content'];
$content = $this->phpEncryption->decrypt($row['content']);
$mtime = strtotime($row['modified']);
} else {
$content = null;
Expand Down Expand Up @@ -87,7 +95,7 @@ protected function save($id, $name, $cache_id, $compile_id, $exp_time, $content)
"' . pSQL($id, true) . '",
"' . pSQL(sha1($name)) . '",
"' . pSQL($cache_id, true) . '",
"' . pSQL($content, true) . '"
"' . $this->phpEncryption->encrypt($content) . '"
)');

return (bool) Db::getInstance()->Affected_Rows();
Expand Down

0 comments on commit b6d96e7

Please # to comment.