Details
Minimal, immediate fix in the Blog controller — apply to both new and edit:
// modules/Blog/Controllers/Blog.php (Blog::new, ~line 123 and Blog::edit, ~line 201)
use Modules\Backend\Validation\CustomRules;
...
$this->commonModel->create('blog_langs', [
'blog_id' => $insertID,
'lang' => $lanCode,
'title' => trim(strip_tags($lanData['title'])),
'seflink' => trim(strip_tags($lanData['seflink'])),
'content' => CustomRules::sanitizeHtml((string)($lanData['content'] ?? '')),
'seo' => !empty($seoData) ? $seoData : '',
]);
Apply the identical change to modules/Pages/Controllers/Pages.php (the previous Pages Stored XSS fix relied on html_purify and is therefore still vulnerable).
- Fix the cache key bug so
getClean()actually works as a defense-in-depth backstop:
// modules/Backend/Validation/CustomRules.php
public function html_purify(?string &$str = null, ?string &$error = null): bool
{
if (empty(trim((string)$str))) return true;
if (!class_exists('\HTMLPurifier')) { $error = lang('Backend.htmlPurifierNotFound'); return false; }
$original = (string)$str;
$clean = self::sanitizeHtml($original);
self::$cleanCache[md5($original)] = $clean; // key on ORIGINAL, before reassignment
$str = $clean; // best-effort; CI4 will drop this
return true;
}
- Document explicitly in
CustomRulesthathtml_purifyis *not* a sanitizer — it returnstrueunconditionally on any HTMLPurifier-installed environment — and that callers MUST useCustomRules::sanitizeHtml(...)(orCustomRules::getClean($original)after the cache fix) on$_POSTdata before storage.
- Defense in depth: escape
$infos->contentat output where feasible (e.g.,app/Views/templates/default/blog/post.php:51), or pipe the stored value throughCustomRules::sanitizeHtml()on read for templates that are expected to render rich HTML — guaranteeing safety even if a future caller forgets the sanitizer.