Skip to content

Commit 32a7936

Browse files
committed
fixup! Reintroduce the old sanitizer testsuite from html5lib-tests
1 parent ed2cd9f commit 32a7936

File tree

2 files changed

+30
-29
lines changed

2 files changed

+30
-29
lines changed

html5lib/tests/sanitizer-testdata/tests1.dat

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
{
2121
"name": "background_attribute",
2222
"input": "<div background=\"javascript:alert('XSS')\"></div>",
23-
"output": "<div/>"
23+
"output": "<div></div>"
2424
},
2525

2626
{
2727
"name": "bgsound",
2828
"input": "<bgsound src=\"javascript:alert('XSS');\" />",
29-
"output": "&lt;bgsound src=\"javascript:alert('XSS');\"/&gt;"
29+
"output": "&lt;bgsound src=\"javascript:alert('XSS');\"&gt;&lt;/bgsound&gt;"
3030
},
3131

3232
{
@@ -44,13 +44,13 @@
4444
{
4545
"name": "double_open_angle_brackets",
4646
"input": "<img src=http://ha.ckers.org/scriptlet.html <",
47-
"output": "<img src='http://ha.ckers.org/scriptlet.html'>"
47+
"output": ""
4848
},
4949

5050
{
5151
"name": "double_open_angle_brackets_2",
5252
"input": "<script src=http://ha.ckers.org/scriptlet.html <",
53-
"output": "&lt;script src=\"http://ha.ckers.org/scriptlet.html\" &lt;=\"\"&gt;"
53+
"output": ""
5454
},
5555

5656
{
@@ -80,13 +80,13 @@
8080
{
8181
"name": "link_stylesheets",
8282
"input": "<link rel=\"stylesheet\" href=\"javascript:alert('XSS');\" />",
83-
"output": "&lt;link rel=\"stylesheet\" href=\"javascript:alert('XSS');\"/&gt;"
83+
"output": "&lt;link href=\"javascript:alert('XSS');\" rel=\"stylesheet\"&gt;"
8484
},
8585

8686
{
8787
"name": "link_stylesheets_2",
8888
"input": "<link rel=\"stylesheet\" href=\"http://ha.ckers.org/xss.css\" />",
89-
"output": "&lt;link rel=\"stylesheet\" href=\"http://ha.ckers.org/xss.css\"/&gt;"
89+
"output": "&lt;link href=\"http://ha.ckers.org/xss.css\" rel=\"stylesheet\"&gt;"
9090
},
9191

9292
{
@@ -98,13 +98,13 @@
9898
{
9999
"name": "no_closing_script_tags",
100100
"input": "<script src=http://ha.ckers.org/xss.js?<b>",
101-
"output": "&lt;script src=\"http://ha.ckers.org/xss.js?&amp;lt;b\"&gt;"
101+
"output": "&lt;script src=\"http://ha.ckers.org/xss.js?&amp;lt;b\"&gt;&lt;/script&gt;"
102102
},
103103

104104
{
105105
"name": "non_alpha_non_digit",
106106
"input": "<script/XSS src=\"http://ha.ckers.org/xss.js\"></script>",
107-
"output": "&lt;script XSS=\"\" src=\"http://ha.ckers.org/xss.js\"&gt;&lt;/script&gt;"
107+
"output": "&lt;script src=\"http://ha.ckers.org/xss.js\" xss=\"\"&gt;&lt;/script&gt;"
108108
},
109109

110110
{
@@ -134,7 +134,7 @@
134134
{
135135
"name": "platypus",
136136
"input": "<a href=\"http://www.ragingplatypus.com/\" style=\"display:block; position:absolute; left:0; top:0; width:100%; height:100%; z-index:1; background-color:black; background-image:url(http://www.ragingplatypus.com/i/cam-full.jpg); background-x:center; background-y:center; background-repeat:repeat;\">never trust your upstream platypus</a>",
137-
"output": "<a href='http://www.ragingplatypus.com/' style='display: block; width: 100%; height: 100%; background-color: black; background-x: center; background-y: center;'>never trust your upstream platypus</a>"
137+
"output": "<a style='display: block; width: 100%; height: 100%; background-color: black; background-x: center; background-y: center;' href='http://www.ragingplatypus.com/'>never trust your upstream platypus</a>"
138138
},
139139

140140
{
@@ -290,13 +290,13 @@
290290
{
291291
"name": "should_sanitize_half_open_scripts",
292292
"input": "<img src=\"javascript:alert('XSS')\"",
293-
"output": "<img/>"
293+
"output": ""
294294
},
295295

296296
{
297297
"name": "should_sanitize_invalid_script_tag",
298298
"input": "<script/XSS SRC=\"http://ha.ckers.org/xss.js\"></script>",
299-
"output": "&lt;script XSS=\"\" SRC=\"http://ha.ckers.org/xss.js\"&gt;&lt;/script&gt;"
299+
"output": "&lt;script src=\"http://ha.ckers.org/xss.js\" xss=\"\"&gt;&lt;/script&gt;"
300300
},
301301

302302
{
@@ -308,7 +308,7 @@
308308
{
309309
"name": "should_sanitize_script_tag_with_multiple_open_brackets_2",
310310
"input": "<iframe src=http://ha.ckers.org/scriptlet.html\n<",
311-
"output": "&lt;iframe src=\"http://ha.ckers.org/scriptlet.html\" &lt;=\"\"&gt;"
311+
"output": ""
312312
},
313313

314314
{
@@ -320,7 +320,7 @@
320320
{
321321
"name": "should_sanitize_unclosed_script",
322322
"input": "<script src=http://ha.ckers.org/xss.js?<b>",
323-
"output": "&lt;script src=\"http://ha.ckers.org/xss.js?&amp;lt;b\"&gt;"
323+
"output": "&lt;script src=\"http://ha.ckers.org/xss.js?&amp;lt;b\"&gt;&lt;/script&gt;"
324324
},
325325

326326
{
@@ -367,67 +367,67 @@
367367

368368
{
369369
"name": "uri_refs_in_svg_attributes",
370-
"input": "<rect fill='url(#foo)' />",
371-
"output": "<rect fill='url(#foo)'/>"
370+
"input": "<svg><rect fill='url(#foo)' />",
371+
"output": "<svg><rect fill='url(#foo)'></rect></svg>"
372372
},
373373

374374
{
375375
"name": "absolute_uri_refs_in_svg_attributes",
376-
"input": "<rect fill='url(http://bad.com/) #fff' />",
377-
"output": "<rect fill=' #fff'/>"
376+
"input": "<svg><rect fill='url(http://bad.com/) #fff' />",
377+
"output": "<svg><rect fill=' #fff'></rect></svg>"
378378
},
379379

380380
{
381381
"name": "uri_ref_with_space_in svg_attribute",
382-
"input": "<rect fill='url(\n#foo)' />",
383-
"output": "<rect fill='url(\n#foo)'/>"
382+
"input": "<svg><rect fill='url(\n#foo)' />",
383+
"output": "<svg><rect fill='url(\n#foo)'></rect></svg>"
384384
},
385385

386386
{
387387
"name": "absolute_uri_ref_with_space_in svg_attribute",
388-
"input": "<rect fill=\"url(\nhttp://bad.com/)\" />",
389-
"output": "<rect fill=' '/>"
388+
"input": "<svg><rect fill=\"url(\nhttp://bad.com/)\" />",
389+
"output": "<svg><rect fill=' '></rect></svg>"
390390
},
391391

392392
{
393393
"name": "allow_html5_image_tag",
394394
"input": "<image src='foo' />",
395-
"output": "&lt;image src=\"foo\"/&gt;"
395+
"output": "<img src='foo'/>"
396396
},
397397

398398
{
399399
"name": "style_attr_end_with_nothing",
400400
"input": "<div style=\"color: blue\" />",
401-
"output": "<div style='color: blue;'/>"
401+
"output": "<div style='color: blue;'></div>"
402402
},
403403

404404
{
405405
"name": "style_attr_end_with_space",
406406
"input": "<div style=\"color: blue \" />",
407-
"output": "<div style='color: blue ;'/>"
407+
"output": "<div style='color: blue ;'></div>"
408408
},
409409

410410
{
411411
"name": "style_attr_end_with_semicolon",
412412
"input": "<div style=\"color: blue;\" />",
413-
"output": "<div style='color: blue;'/>"
413+
"output": "<div style='color: blue;'></div>"
414414
},
415415

416416
{
417417
"name": "style_attr_end_with_semicolon_space",
418418
"input": "<div style=\"color: blue; \" />",
419-
"output": "<div style='color: blue;'/>"
419+
"output": "<div style='color: blue;'></div>"
420420
},
421421

422422
{
423423
"name": "attributes_with_embedded_quotes",
424424
"input": "<img src=doesntexist.jpg\"'onerror=\"alert(1) />",
425-
"output": "<img src='doesntexist.jpg&quot;&apos;onerror=&quot;alert(1)'/>"
425+
"output": "<img src='doesntexist.jpg\"&#39;onerror=\"alert(1)'/>"
426426
},
427427

428428
{
429429
"name": "attributes_with_embedded_quotes_II",
430430
"input": "<img src=notthere.jpg\"\"onerror=\"alert(2) />",
431-
"output": "<img src='notthere.jpg&quot;&quot;onerror=&quot;alert(2)'/>"
431+
"output": "<img src='notthere.jpg\"\"onerror=\"alert(2)'/>"
432432
}
433433
]

html5lib/tests/sanitizer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ def runtest(self):
3333
use_trailing_solidus=True,
3434
space_before_trailing_solidus=False,
3535
quote_attr_values=True,
36-
quote_char="'")
36+
quote_char="'",
37+
alphabeticalize_attributes=True)
3738
errorMsg = "\n".join(["\n\nInput:", input,
3839
"\nExpected:", expected,
3940
"\nReceived:", serialized])

0 commit comments

Comments
 (0)