Skip to content

Commit 7df8faf

Browse files
authored
[6.1] Upmerges - 2026-01-06 (#46634)
2 parents 916bbac + 8ef842d commit 7df8faf

File tree

5 files changed

+656
-575
lines changed

5 files changed

+656
-575
lines changed

libraries/src/Filter/InputFilter.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace Joomla\CMS\Filter;
1111

12+
use enshrined\svgSanitize\Sanitizer;
1213
use Joomla\CMS\String\PunycodeHelper;
1314
use Joomla\Filter\InputFilter as BaseInputFilter;
1415

@@ -492,4 +493,39 @@ protected function stripUSC($source)
492493

493494
return preg_replace('/[\xF0-\xF7].../s', "\xE2\xAF\x91", $source);
494495
}
496+
497+
/**
498+
* Internal method to strip a tag of disallowed attributes - extended to filter SVG content
499+
*
500+
* @param array $attrSet Array of attribute pairs to filter
501+
*
502+
* @return array Filtered array of attribute pairs
503+
*
504+
* @since 6.0.2
505+
*/
506+
protected function cleanAttributes(array $attrSet)
507+
{
508+
// Do the heavy lifting in the upstream library
509+
$attrSet = parent::cleanAttributes($attrSet);
510+
511+
// Decode and check base64-encoded svgs
512+
return array_map(
513+
function ($attribute) {
514+
// Check for presence of relevant tags
515+
if (!preg_match('/"data:.*svg.*;base64,(.*)"/U', $attribute, $matches)) {
516+
return $attribute;
517+
}
518+
519+
// Extract SVG
520+
$svg = base64_decode($matches[1], true);
521+
522+
// Sanitize svg
523+
$sanitizer = new Sanitizer();
524+
525+
// Replace content
526+
return str_replace($matches[1], base64_encode($sanitizer->sanitize($svg)), $attribute);
527+
},
528+
$attrSet,
529+
);
530+
}
495531
}

0 commit comments

Comments
 (0)