Skip to content

Commit

Permalink
[CVE-2024-32981] Disallow data:text/html in data attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli authored and emteknetnz committed Jul 16, 2024
1 parent c13ec34 commit b8d20dc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Forms/HTMLEditor/HTMLEditorSanitiser.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ public function sanitise(HTMLValue $html)
}

// 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)) {
Expand Down
26 changes: 25 additions & 1 deletion tests/php/Forms/HTMLEditor/HTMLEditorSanitiserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,31 @@ public function testSanitisation()
'object[data]',
'<object data=javascript:alert()>',
'<object></object>',
'Object with dangerous content in data attribute is completely removed'
'Object with dangerous javascript content in data attribute is completely removed'
],
[
'object[data]',
'<object data="javascript:alert()">',
'<object></object>',
'Object with dangerous javascript content in data attribute with quotes is completely removed'
],
[
'object[data]',
'<object data="data:text/html;base64,PHNjcmlwdD5hbGVydChkb2N1bWVudC5sb2NhdGlvbik8L3NjcmlwdD4=">',
'<object></object>',
'Object with dangerous html content in data attribute is completely removed'
],
[
'object[data]',
'<object data="' . implode("\n", str_split(' DATA:TEXT/HTML;')) . 'base64,PHNjcmlwdD5hbGVydChkb2N1bWVudC5sb2NhdGlvbik8L3NjcmlwdD4=">',
'<object></object>',
'Object with split upper-case dangerous html content in data attribute is completely removed'
],
[
'object[data]',
'<object data="data:text/xml;base64,PHNjcmlwdD5hbGVydChkb2N1bWVudC5sb2NhdGlvbik8L3NjcmlwdD4=">',
'<object data="data:text/xml;base64,PHNjcmlwdD5hbGVydChkb2N1bWVudC5sb2NhdGlvbik8L3NjcmlwdD4="></object>',
'Object with safe xml content in data attribute is retained'
],
[
'img[src]',
Expand Down

0 comments on commit b8d20dc

Please sign in to comment.