Skip to content

Commit 5b0bbcc

Browse files
committed
Merge branch '7.3' into 7.4
* 7.3: [FrameworkBundle] Remove extra argument from ContainerBuilder::willBeAvailable call fix ext-redis 6.2.0 compatibility [CssSelector] Fix incorrect return type for Token::getType() [Validator] Fix call to undefined getParser() in YamlValidator [ObjectMapper] Update Map attribute PHPDoc to match TransformCallableInterface signature [HtmlSanitizer] Remove `srcdoc` from allowed attributes
2 parents c55905f + 3855e82 commit 5b0bbcc

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

Reference/W3CReference.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ final class W3CReference
368368
'span' => true,
369369
'spellcheck' => true,
370370
'src' => true,
371-
'srcdoc' => true,
371+
// 'srcdoc' => false, // XSS vector if not properly sandboxed, should be enabled explicitly with ->allowAttribute('srcdoc', 'iframe')->forceAttribute('iframe', 'sandbox', '')
372372
'srclang' => true,
373373
'srcset' => true,
374374
'standby' => true,

Tests/Fixtures/baseline-attribute-allow-list.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@
182182
"span",
183183
"spellcheck",
184184
"src",
185-
"srcdoc",
186185
"srclang",
187186
"srcset",
188187
"standby",

Tests/HtmlSanitizerAllTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,23 @@ public static function provideSanitizeHtml(): iterable
610610
];
611611
}
612612

613+
public function testIFrameDefaultsAreSafe()
614+
{
615+
$sanitizer = new HtmlSanitizer((new HtmlSanitizerConfig())
616+
->allowElement('iframe', '*')
617+
);
618+
$input = '<iframe src="javascript:alert()" onload="alert()" srcdoc="<script>alert()</script>">XSS</iframe>';
619+
$this->assertSame('<iframe>XSS</iframe>', $sanitizer->sanitize($input));
620+
621+
$sanitizer = new HtmlSanitizer((new HtmlSanitizerConfig())
622+
->allowElement('iframe', '*')
623+
->allowAttribute('srcdoc', 'iframe')
624+
->forceAttribute('iframe', 'sandbox', '')
625+
);
626+
$input = '<iframe src="javascript:alert()" onload="alert()" srcdoc="<script>alert()</script>">XSS-prevented by sandbox</iframe>';
627+
$this->assertSame('<iframe srcdoc="&lt;script&gt;alert()&lt;/script&gt;" sandbox>XSS-prevented by sandbox</iframe>', $sanitizer->sanitize($input));
628+
}
629+
613630
public function testUnlimitedLength()
614631
{
615632
$sanitizer = new HtmlSanitizer((new HtmlSanitizerConfig())->withMaxInputLength(-1));

Tests/HtmlSanitizerConfigTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function testAllowElementStandardAttributes()
109109
$config = new HtmlSanitizerConfig();
110110
$config = $config->allowElement('div', '*');
111111
$this->assertSame(['div'], array_keys($config->getAllowedElements()));
112-
$this->assertCount(211, $config->getAllowedElements()['div']);
112+
$this->assertCount(210, $config->getAllowedElements()['div']);
113113
$this->assertSame([], $config->getBlockedElements());
114114
}
115115

0 commit comments

Comments
 (0)