Skip to content

Commit 996cde7

Browse files
Greg Gutheg-k
Greg Guthe
authored andcommitted
fix bug 1615315
1 parent 2f210e0 commit 996cde7

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

bleach/html5lib_shim.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,12 @@ def __init__(self, tags, strip, consume_entities, **kwargs):
376376
self.consume_entities = consume_entities
377377
super(BleachHTMLParser, self).__init__(**kwargs)
378378

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

tests/test_clean.py

+28
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,34 @@ def test_nonexistent_namespace():
769769
assert clean('<d {c}>') == '&lt;d {c}&gt;'
770770

771771

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

0 commit comments

Comments
 (0)