@@ -739,6 +739,53 @@ def test_namespace_rc_data_element_strip_false(
739
739
)
740
740
741
741
742
+ @pytest .mark .parametrize (
743
+ "namespace_tag, end_tag, data, expected" ,
744
+ [
745
+ (
746
+ "math" ,
747
+ "p" ,
748
+ "<math></p><style><!--</style><img src/onerror=alert(1)>" ,
749
+ "<math><p></p><style><!--</style><img src/onerror=alert(1)>--></style></math>" ,
750
+ ),
751
+ (
752
+ "math" ,
753
+ "br" ,
754
+ "<math></br><style><!--</style><img src/onerror=alert(1)>" ,
755
+ "<math><br><style><!--</style><img src/onerror=alert(1)>--></style></math>" ,
756
+ ),
757
+ (
758
+ "svg" ,
759
+ "p" ,
760
+ "<svg></p><style><!--</style><img src/onerror=alert(1)>" ,
761
+ "<svg><p></p><style><!--</style><img src/onerror=alert(1)>--></style></svg>" ,
762
+ ),
763
+ (
764
+ "svg" ,
765
+ "br" ,
766
+ "<svg></br><style><!--</style><img src/onerror=alert(1)>" ,
767
+ "<svg><br><style><!--</style><img src/onerror=alert(1)>--></style></svg>" ,
768
+ ),
769
+ ],
770
+ )
771
+ def test_html_comments_escaped (namespace_tag , end_tag , data , expected ):
772
+ # refs: bug 1689399 / GHSA-vv2x-vrpj-qqpq
773
+ #
774
+ # p and br can be just an end tag (e.g. </p> == <p></p>)
775
+ #
776
+ # In browsers:
777
+ #
778
+ # * img and other tags break out of the svg or math namespace (e.g. <svg><img></svg> == <svg><img></svg>)
779
+ # * style does not (e.g. <svg><style></svg> == <svg><style></style></svg>)
780
+ # * the breaking tag ejects trailing elements (e.g. <svg><img><style></style></svg> == <svg></svg><img><style></style>)
781
+ #
782
+ # the ejected elements can trigger XSS
783
+ assert (
784
+ clean (data , tags = [namespace_tag , end_tag , "style" ], strip_comments = False )
785
+ == expected
786
+ )
787
+
788
+
742
789
def get_ids_and_tests ():
743
790
"""Retrieves regression tests from data/ directory
744
791
0 commit comments