File tree 2 files changed +32
-3
lines changed
src/Symfony/Component/HtmlSanitizer
2 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -237,16 +237,21 @@ public function provideSanitizeBody()
237
237
],
238
238
[
239
239
'<BODY BACKGROUND="javascript:alert( \'XSS \')"> ' ,
240
- '<body / > ' ,
240
+ '<body></body > ' ,
241
241
],
242
242
[
243
243
'<BGSOUND SRC="javascript:alert( \'XSS \');"> ' ,
244
- '<bgsound / > ' ,
244
+ '<bgsound></bgsound > ' ,
245
245
],
246
246
[
247
247
'<BR SIZE="&{alert( \'XSS \')}"> ' ,
248
248
'<br size="&{alert('XSS')}" /> ' ,
249
249
],
250
+ [
251
+ '<BR></br> ' ,
252
+ '<br /><br /> ' ,
253
+ ],
254
+
250
255
[
251
256
'<OBJECT TYPE="text/x-scriptlet" DATA="http://xss.rocks/scriptlet.html"></OBJECT> ' ,
252
257
'' ,
@@ -445,6 +450,11 @@ public function provideSanitizeBody()
445
450
'<i>Lorem ipsum</i> ' ,
446
451
'<i>Lorem ipsum</i> ' ,
447
452
],
453
+ [
454
+ '<i></i> ' ,
455
+ '<i></i> ' ,
456
+ ],
457
+
448
458
[
449
459
'<li>Lorem ipsum</li> ' ,
450
460
'<li>Lorem ipsum</li> ' ,
Original file line number Diff line number Diff line change 20
20
*/
21
21
final class Node implements NodeInterface
22
22
{
23
+ // HTML5 elements which are self-closing
24
+ private const VOID_ELEMENTS = [
25
+ 'area ' => true ,
26
+ 'base ' => true ,
27
+ 'br ' => true ,
28
+ 'col ' => true ,
29
+ 'embed ' => true ,
30
+ 'hr ' => true ,
31
+ 'img ' => true ,
32
+ 'input ' => true ,
33
+ 'keygen ' => true ,
34
+ 'link ' => true ,
35
+ 'meta ' => true ,
36
+ 'param ' => true ,
37
+ 'source ' => true ,
38
+ 'track ' => true ,
39
+ 'wbr ' => true ,
40
+ ];
41
+
23
42
private NodeInterface $ parent ;
24
43
private string $ tagName ;
25
44
private array $ attributes = [];
@@ -56,7 +75,7 @@ public function addChild(NodeInterface $node): void
56
75
57
76
public function render (): string
58
77
{
59
- if (! $ this ->children ) {
78
+ if (isset ( self :: VOID_ELEMENTS [ $ this ->tagName ]) ) {
60
79
return '< ' .$ this ->tagName .$ this ->renderAttributes ().' /> ' ;
61
80
}
62
81
You can’t perform that action at this time.
0 commit comments