Skip to content

Commit 2214f71

Browse files
committed
Sanitize stored HTML to prevent XSS
1 parent aed2026 commit 2214f71

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"minimum-stability": "dev",
99
"require": {
1010
"php": "^8.0.11",
11+
"ezyang/htmlpurifier": "^4.19",
1112
"aimeos/aimeos-core": "dev-master",
1213
"aimeos/ai-admin-jqadm": "dev-master",
1314
"aimeos/ai-admin-jsonadm": "dev-master",

src/Admin/JQAdm/Cms/Content/Standard.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,16 @@ protected function fromArray( \Aimeos\MShop\Cms\Item\Iface $item, array $data )
318318

319319
foreach( $data as $idx => $entry )
320320
{
321-
if( trim( $this->val( $entry, 'text.content', '' ) ) === '' ) {
321+
if( !( $content = trim( $this->val( $entry, 'text.content', '' ) ) ) ) {
322322
continue;
323323
}
324324

325+
$config = \HTMLPurifier_Config::createDefault();
326+
$config->set( 'Attr.AllowedFrameTargets', ['_blank', '_self'] );
327+
328+
$purifier = new \HTMLPurifier( $config );
329+
$entry['text.content'] = $purifier->purify( $content );
330+
325331
$id = $this->val( $entry, 'text.id', '' );
326332
$type = $this->val( $entry, 'cms.lists.type', 'default' );
327333

0 commit comments

Comments
 (0)