Skip to content

Commit bafa8c4

Browse files
committed
Fix iframe
1 parent dc8be08 commit bafa8c4

2 files changed

Lines changed: 33 additions & 11 deletions

File tree

src/Utils/Sanitization/FormatsSanitizedValue.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,25 @@ private function sanitizer(): HtmlSanitizer
4141
{
4242
$config = (new HtmlSanitizerConfig())
4343
->allowSafeElements()
44-
->allowElement('iframe')
44+
->allowElement('iframe', [
45+
'allow',
46+
'allowfullscreen',
47+
'loading',
48+
'name',
49+
'referrerpolicy',
50+
'sandbox',
51+
'src',
52+
'srcdoc',
53+
'width',
54+
'height',
55+
'id',
56+
'title',
57+
'aria-label',
58+
'frameborder',
59+
'marginwidth',
60+
'marginheight',
61+
'scrolling',
62+
])
4563
->allowRelativeLinks()
4664
->allowRelativeMedias()
4765
->allowElement('div', ['data-encoded-content'])

tests/Unit/Form/Fields/Formatters/EditorFormatterTest.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -355,22 +355,26 @@
355355
it('sanitizes HTML content from front by default', function () {
356356
$value = <<<'HTML'
357357
This is unwanted:
358-
1_<script>alert('XSS')</script>
359-
2_<img src="xss.jpg" onload="alert('XSS')">
358+
<script>alert('XSS')</script>
359+
<img src="javascript:alert('XSS')" onload="alert('XSS')">
360+
<iframe src="javascript:alert('XSS')" onerror="alert('XSS')"></iframe>
360361
This is wanted:
361-
1_<x-embed data-key="0"></x-embed>
362-
2_<x-sharp-file data-key="0"></x-sharp-file>
363-
3_<div data-html-content="true"><script></script></div>
362+
<x-embed data-key="0"></x-embed>
363+
<x-sharp-file data-key="0"></x-sharp-file>
364+
<div data-html-content="true"><script></script></div>
365+
<iframe src="/test" allow="fullscreen" allowfullscreen width="50" height="50" frameborder="0" scrolling="false"></iframe>
364366
HTML;
365367

366368
$expected = <<<'HTML'
367369
This is unwanted:
368-
1_
369-
2_<img src="xss.jpg">
370+
371+
<img>
372+
<iframe></iframe>
370373
This is wanted:
371-
1_<x-embed></x-embed>
372-
2_<x-sharp-file file="[]"></x-sharp-file>
373-
3_<div data-html-content="true"><script></script></div>
374+
<x-embed></x-embed>
375+
<x-sharp-file file="[]"></x-sharp-file>
376+
<div data-html-content="true"><script></script></div>
377+
<iframe src="/test" allow="fullscreen" allowfullscreen width="50" height="50" frameborder="0" scrolling="false"></iframe>
374378
HTML;
375379

376380
expect(

0 commit comments

Comments
 (0)