Skip to content

Commit 5c0c4c8

Browse files
committed
Fix DisallowedRawHtml bypass via newline/tab in tag names
1 parent f6e7443 commit 5c0c4c8

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

src/Extension/DisallowedRawHtml/DisallowedRawHtmlRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function render(Node $node, ChildNodeRendererInterface $childRenderer): ?
4545
return $rendered;
4646
}
4747

48-
$regex = \sprintf('/<(\/?(?:%s)[ \/>])/i', \implode('|', \array_map('preg_quote', $tags)));
48+
$regex = \sprintf('/<(\/?(?:%s)[\s\/>])/i', \implode('|', \array_map('preg_quote', $tags)));
4949

5050
// Match these types of tags: <title> </title> <title x="sdf"> <title/> <title />
5151
return \preg_replace($regex, '&lt;$1', $rendered);

tests/unit/Extension/DisallowedRawHtml/DisallowedRawHtmlRendererTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static function dataProviderForTestWithDefaultSettings(): iterable
7272
yield ['<plaintext>', '&lt;plaintext>'];
7373

7474
// Newline/whitespace bypass attempts (security fix)
75-
yield ["<script >", "&lt;script >"];
75+
yield ['<script >', '&lt;script >'];
7676
yield ["<script\n>", "&lt;script\n>"];
7777
yield ["<script\t>", "&lt;script\t>"];
7878
yield ["<script\r\n>", "&lt;script\r\n>"];
@@ -118,7 +118,7 @@ public static function dataProviderForTestWithCustomSettings(): iterable
118118
yield ['<strong />', '&lt;strong />'];
119119

120120
// Newline bypass with custom config
121-
yield ["<strong >", "&lt;strong >"];
121+
yield ['<strong >', '&lt;strong >'];
122122
yield ["<strong\n>", "&lt;strong\n>"];
123123
yield ["<strong\t>", "&lt;strong\t>"];
124124

0 commit comments

Comments
 (0)