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