Skip to content

Commit c2a85d8

Browse files
committed
pkp#7916 revert back symfony html sanitizer and bring back html purifier
1 parent ac0e09e commit c2a85d8

File tree

4 files changed

+76
-495
lines changed

4 files changed

+76
-495
lines changed

classes/core/PKPHtmlSanitizer.php

-173
This file was deleted.

classes/core/PKPString.php

+11-8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
namespace PKP\core;
1919

20+
use HTMLPurifier;
21+
use HTMLPurifier_Config;
2022
use PKP\config\Config;
2123

2224
class PKPString
@@ -161,15 +163,16 @@ public static function stripUnsafeHtml(?string $input, string $configKey = 'allo
161163
return '';
162164
}
163165

164-
static $caches;
165-
166-
if (!isset($caches[$configKey])) {
167-
$caches[$configKey] = new \PKP\core\PKPHtmlSanitizer(
168-
Config::getVar('security', $configKey)
169-
);
166+
static $purifier;
167+
if (!isset($purifier)) {
168+
$config = HTMLPurifier_Config::createDefault();
169+
$config->set('Core.Encoding', 'utf-8');
170+
$config->set('HTML.Doctype', 'HTML 4.01 Transitional');
171+
$config->set('HTML.Allowed', Config::getVar('security', $configKey));
172+
$config->set('Cache.SerializerPath', 'cache');
173+
$purifier = new HTMLPurifier($config);
170174
}
171-
172-
return $caches[$configKey]->sanitize($input);
175+
return $purifier->purify((string) $input);
173176
}
174177

175178
/**

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"dflydev/base32-crockford": "^1.0",
88
"doctrine/dbal": "^3.5",
99
"elcobvg/laravel-opcache": "^0.5.0",
10+
"ezyang/htmlpurifier": "^4.17",
1011
"firebase/php-jwt": "6.*",
1112
"geoip2/geoip2": "~2.0",
1213
"gettext/gettext": "5.*",
@@ -25,7 +26,6 @@
2526
"smarty/smarty": "4.*",
2627
"sokil/php-isocodes": "^4.1",
2728
"sokil/php-isocodes-db-i18n": "^4.0",
28-
"symfony/html-sanitizer": "^6.2",
2929
"symfony/mailer": "^6.0",
3030
"tinymce/tinymce": "^5.7",
3131
"wikimedia/less.php": "3.*"

0 commit comments

Comments
 (0)