Skip to content

Commit f77e0f6

Browse files
Greg Gutheg-k
authored andcommitted
fix bug 1615315
1 parent 8d416c5 commit f77e0f6

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

bleach/html5lib_shim.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,12 @@ def __init__(self, tags, strip, consume_entities, **kwargs):
377377
self.consume_entities = consume_entities
378378
super(BleachHTMLParser, self).__init__(**kwargs)
379379

380-
def _parse(self, stream, innerHTML=False, container='div', scripting=False, **kwargs):
380+
def _parse(self, stream, innerHTML=False, container='div', scripting=True, **kwargs):
381+
# set scripting=True to parse <noscript> as though JS is enabled to
382+
# match the expected context in browsers
383+
#
384+
# https://html.spec.whatwg.org/multipage/scripting.html#the-noscript-element
385+
#
381386
# Override HTMLParser so we can swap out the tokenizer for our own.
382387
self.innerHTMLMode = innerHTML
383388
self.container = container

tests/test_clean.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,34 @@ def test_nonexistent_namespace():
771771
assert clean('<d {c}>') == '&lt;d {c}&gt;'
772772

773773

774+
# tags that get content passed through (i.e. parsed with parseRCDataRawtext)
775+
_raw_tags = [
776+
"title",
777+
"textarea",
778+
"script",
779+
"style",
780+
"noembed",
781+
"noframes",
782+
"iframe",
783+
"xmp",
784+
]
785+
786+
@pytest.mark.parametrize(
787+
"raw_tag, data, expected",
788+
[
789+
(
790+
raw_tag,
791+
"<noscript><%s></noscript><img src=x onerror=alert(1) />" % raw_tag,
792+
"<noscript><%s></noscript>&lt;img src=x onerror=alert(1) /&gt;" % raw_tag,
793+
)
794+
for raw_tag in _raw_tags
795+
],
796+
)
797+
def test_noscript_rawtag_(raw_tag, data, expected):
798+
# refs: bug 1615315 / GHSA-q65m-pv3f-wr5r
799+
assert clean(data, tags=["noscript", raw_tag]) == expected
800+
801+
774802
def get_ids_and_tests():
775803
"""Retrieves regression tests from data/ directory
776804

0 commit comments

Comments
 (0)