From b8d20dc9d531550e06fd7da7a0eafa551922e2e1 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Tue, 16 Apr 2024 15:49:58 +1200 Subject: [PATCH] [CVE-2024-32981] Disallow `data:text/html` in data attributes --- src/Forms/HTMLEditor/HTMLEditorSanitiser.php | 2 +- .../HTMLEditor/HTMLEditorSanitiserTest.php | 26 ++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/Forms/HTMLEditor/HTMLEditorSanitiser.php b/src/Forms/HTMLEditor/HTMLEditorSanitiser.php index a075d98fa..a979d1c2f 100644 --- a/src/Forms/HTMLEditor/HTMLEditorSanitiser.php +++ b/src/Forms/HTMLEditor/HTMLEditorSanitiser.php @@ -347,7 +347,7 @@ class HTMLEditorSanitiser } // Matches "javascript:" with any arbitrary linebreaks inbetween the characters. - $regex = '/^\s*' . implode('\s*', str_split('javascript:')) . '/i'; + $regex = '#^\s*(' . implode('\s*', str_split('javascript:')) . '|' . implode('\s*', str_split('data:text/html;')) . ')#i'; // Strip out javascript execution in href or src attributes. foreach (['src', 'href', 'data'] as $dangerAttribute) { if ($el->hasAttribute($dangerAttribute)) { diff --git a/tests/php/Forms/HTMLEditor/HTMLEditorSanitiserTest.php b/tests/php/Forms/HTMLEditor/HTMLEditorSanitiserTest.php index 3d5c3d5c6..ac7272dc2 100644 --- a/tests/php/Forms/HTMLEditor/HTMLEditorSanitiserTest.php +++ b/tests/php/Forms/HTMLEditor/HTMLEditorSanitiserTest.php @@ -120,7 +120,31 @@ class HTMLEditorSanitiserTest extends FunctionalTest 'object[data]', '', '', - 'Object with dangerous content in data attribute is completely removed' + 'Object with dangerous javascript content in data attribute is completely removed' + ], + [ + 'object[data]', + '', + '', + 'Object with dangerous javascript content in data attribute with quotes is completely removed' + ], + [ + 'object[data]', + '', + '', + 'Object with dangerous html content in data attribute is completely removed' + ], + [ + 'object[data]', + '