Skip to content

Commit a2017ff

Browse files
committed
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.
1 parent 9646339 commit a2017ff

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

app/Util/ConfiguredHtmlPurifier.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@ class ConfiguredHtmlPurifier
2222

2323
public function __construct()
2424
{
25+
// This is done by the web-server at run-time, with the existing
26+
// storage/framework/cache folder to ensure we're using a server-writable folder.
27+
$cachePath = storage_path('framework/cache/purifier');
28+
$this->createCacheFolderIfNeeded($cachePath);
29+
2530
$config = HTMLPurifier_HTML5Config::createDefault();
26-
$this->setConfig($config);
31+
$this->setConfig($config, $cachePath);
2732
$this->resetCacheIfNeeded($config);
2833

2934
$htmlDef = $config->getDefinition('HTML', true, true);
@@ -34,6 +39,13 @@ public function __construct()
3439
$this->purifier = new HTMLPurifier($config);
3540
}
3641

42+
protected function createCacheFolderIfNeeded(string $cachePath): void
43+
{
44+
if (!file_exists($cachePath)) {
45+
mkdir($cachePath, 0777, true);
46+
}
47+
}
48+
3749
protected function resetCacheIfNeeded(HTMLPurifier_Config $config): void
3850
{
3951
if (self::$cachedChecked) {
@@ -53,9 +65,9 @@ protected function resetCacheIfNeeded(HTMLPurifier_Config $config): void
5365
self::$cachedChecked = true;
5466
}
5567

56-
protected function setConfig(HTMLPurifier_Config $config): void
68+
protected function setConfig(HTMLPurifier_Config $config, string $cachePath): void
5769
{
58-
$config->set('Cache.SerializerPath', storage_path('framework/purifier'));
70+
$config->set('Cache.SerializerPath', $cachePath);
5971
$config->set('Core.AllowHostnameUnderscore', true);
6072
$config->set('CSS.AllowTricky', true);
6173
$config->set('HTML.SafeIframe', true);

storage/framework/purifier/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)