From a2017ffa559d96669f207863ca202d2e50363622 Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Tue, 17 Feb 2026 18:22:13 +0000 Subject: [PATCH] Caching: Altered purifier cache folder to be server-created Moved from a static folder to a dynamically created folder in the framework/cache directory, to increase the chance that it's created with server-writable permissions. This is due to an issue where users had permission issues, since adding a new folder means it's created by the git user and often non-web-writable. --- app/Util/ConfiguredHtmlPurifier.php | 18 +++++++++++++++--- storage/framework/purifier/.gitignore | 2 -- 2 files changed, 15 insertions(+), 5 deletions(-) delete mode 100644 storage/framework/purifier/.gitignore diff --git a/app/Util/ConfiguredHtmlPurifier.php b/app/Util/ConfiguredHtmlPurifier.php index 014b2a3bf..87580da8b 100644 --- a/app/Util/ConfiguredHtmlPurifier.php +++ b/app/Util/ConfiguredHtmlPurifier.php @@ -22,8 +22,13 @@ class ConfiguredHtmlPurifier public function __construct() { + // This is done by the web-server at run-time, with the existing + // storage/framework/cache folder to ensure we're using a server-writable folder. + $cachePath = storage_path('framework/cache/purifier'); + $this->createCacheFolderIfNeeded($cachePath); + $config = HTMLPurifier_HTML5Config::createDefault(); - $this->setConfig($config); + $this->setConfig($config, $cachePath); $this->resetCacheIfNeeded($config); $htmlDef = $config->getDefinition('HTML', true, true); @@ -34,6 +39,13 @@ class ConfiguredHtmlPurifier $this->purifier = new HTMLPurifier($config); } + protected function createCacheFolderIfNeeded(string $cachePath): void + { + if (!file_exists($cachePath)) { + mkdir($cachePath, 0777, true); + } + } + protected function resetCacheIfNeeded(HTMLPurifier_Config $config): void { if (self::$cachedChecked) { @@ -53,9 +65,9 @@ class ConfiguredHtmlPurifier self::$cachedChecked = true; } - protected function setConfig(HTMLPurifier_Config $config): void + protected function setConfig(HTMLPurifier_Config $config, string $cachePath): void { - $config->set('Cache.SerializerPath', storage_path('framework/purifier')); + $config->set('Cache.SerializerPath', $cachePath); $config->set('Core.AllowHostnameUnderscore', true); $config->set('CSS.AllowTricky', true); $config->set('HTML.SafeIframe', true); diff --git a/storage/framework/purifier/.gitignore b/storage/framework/purifier/.gitignore deleted file mode 100644 index c96a04f00..000000000 --- a/storage/framework/purifier/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore \ No newline at end of file