5
5
from bleach import clean
6
6
from bleach .html5lib_shim import Filter
7
7
from bleach .sanitizer import Cleaner
8
-
8
+ from bleach . _vendor . html5lib . constants import rcdataElements
9
9
10
10
def test_clean_idempotent ():
11
11
"""Make sure that applying the filter twice doesn't change anything."""
@@ -787,7 +787,7 @@ def test_nonexistent_namespace():
787
787
(
788
788
raw_tag ,
789
789
"<noscript><%s></noscript><img src=x onerror=alert(1) />" % raw_tag ,
790
- "<noscript><%s> </noscript><img src=x onerror=alert(1) />" % raw_tag ,
790
+ "<noscript><%s> </noscript><img src=x onerror=alert(1) />" % raw_tag ,
791
791
)
792
792
for raw_tag in _raw_tags
793
793
],
@@ -797,6 +797,29 @@ def test_noscript_rawtag_(raw_tag, data, expected):
797
797
assert clean (data , tags = ["noscript" , raw_tag ]) == expected
798
798
799
799
800
+ @pytest .mark .parametrize (
801
+ "namespace_tag, rc_data_element_tag, data, expected" ,
802
+ [
803
+ (
804
+ namespace_tag ,
805
+ rc_data_element_tag ,
806
+ "<%s><%s><img src=x onerror=alert(1)>" % (namespace_tag , rc_data_element_tag ),
807
+ "<%s><%s><img src=x onerror=alert(1)></%s></%s>" % (namespace_tag , rc_data_element_tag , rc_data_element_tag , namespace_tag ),
808
+ )
809
+ for namespace_tag in ["math" , "svg" ]
810
+ # https://dev.w3.org/html5/html-author/#rcdata-elements
811
+ # https://html.spec.whatwg.org/index.html#parsing-html-fragments
812
+ # in html5lib: 'style', 'script', 'xmp', 'iframe', 'noembed', 'noframes', and 'noscript'
813
+ for rc_data_element_tag in rcdataElements
814
+ ],
815
+ )
816
+ def test_namespace_rc_data_element_strip_false (namespace_tag , rc_data_element_tag , data , expected ):
817
+ # refs: bug 1621692 / GHSA-m6xf-fq7q-8743
818
+ #
819
+ # browsers will pull the img out of the namespace and rc data tag resulting in XSS
820
+ assert clean (data , tags = [namespace_tag , rc_data_element_tag ], strip = False ) == expected
821
+
822
+
800
823
def get_ids_and_tests ():
801
824
"""Retrieves regression tests from data/ directory
802
825
0 commit comments