@@ -647,6 +647,66 @@ def test_scrubbing_svg_attr_values_that_allow_ref
647
647
assert_equal ( expected , actual )
648
648
end
649
649
650
+ def test_style_with_css_payload
651
+ input , tags = "<style>div > span { background: \" red\" ; }</style>" , [ "style" ]
652
+ expected = "<style>div > span { background: \" red\" ; }</style>"
653
+ actual = safe_list_sanitize ( input , tags : tags )
654
+
655
+ assert_equal ( expected , actual )
656
+ end
657
+
658
+ def test_combination_of_select_and_style_with_css_payload
659
+ input , tags = "<select><style>div > span { background: \" red\" ; }</style></select>" , [ "select" , "style" ]
660
+ expected = "<select><style>div > span { background: \" red\" ; }</style></select>"
661
+ actual = safe_list_sanitize ( input , tags : tags )
662
+
663
+ assert_equal ( expected , actual )
664
+ end
665
+
666
+ def test_combination_of_select_and_style_with_script_payload
667
+ input , tags = "<select><style><script>alert(1)</script></style></select>" , [ "select" , "style" ]
668
+ expected = "<select><style><script>alert(1)</script></style></select>"
669
+ actual = safe_list_sanitize ( input , tags : tags )
670
+
671
+ assert_equal ( expected , actual )
672
+ end
673
+
674
+ def test_combination_of_svg_and_style_with_script_payload
675
+ input , tags = "<svg><style><script>alert(1)</script></style></svg>" , [ "svg" , "style" ]
676
+ expected = "<svg><style><script>alert(1)</script></style></svg>"
677
+ actual = safe_list_sanitize ( input , tags : tags )
678
+
679
+ assert_equal ( expected , actual )
680
+ end
681
+
682
+ def test_combination_of_math_and_style_with_img_payload
683
+ input , tags = "<math><style><img src=x onerror=alert(1)></style></math>" , [ "math" , "style" ]
684
+ expected = "<math><style><img src=x onerror=alert(1)></style></math>"
685
+ actual = safe_list_sanitize ( input , tags : tags )
686
+
687
+ assert_equal ( expected , actual )
688
+
689
+ input , tags = "<math><style><img src=x onerror=alert(1)></style></math>" , [ "math" , "style" , "img" ]
690
+ expected = "<math><style><img src=x onerror=alert(1)></style></math>"
691
+ actual = safe_list_sanitize ( input , tags : tags )
692
+
693
+ assert_equal ( expected , actual )
694
+ end
695
+
696
+ def test_combination_of_svg_and_style_with_img_payload
697
+ input , tags = "<svg><style><img src=x onerror=alert(1)></style></svg>" , [ "svg" , "style" ]
698
+ expected = "<svg><style><img src=x onerror=alert(1)></style></svg>"
699
+ actual = safe_list_sanitize ( input , tags : tags )
700
+
701
+ assert_equal ( expected , actual )
702
+
703
+ input , tags = "<svg><style><img src=x onerror=alert(1)></style></svg>" , [ "svg" , "style" , "img" ]
704
+ expected = "<svg><style><img src=x onerror=alert(1)></style></svg>"
705
+ actual = safe_list_sanitize ( input , tags : tags )
706
+
707
+ assert_equal ( expected , actual )
708
+ end
709
+
650
710
protected
651
711
652
712
def xpath_sanitize ( input , options = { } )
0 commit comments