@@ -641,6 +641,66 @@ def test_scrubbing_svg_attr_values_that_allow_ref
641
641
assert_equal ( expected , actual )
642
642
end
643
643
644
+ def test_style_with_css_payload
645
+ input , tags = "<style>div > span { background: \" red\" ; }</style>" , [ "style" ]
646
+ expected = "<style>div > span { background: \" red\" ; }</style>"
647
+ actual = safe_list_sanitize ( input , tags : tags )
648
+
649
+ assert_equal ( expected , actual )
650
+ end
651
+
652
+ def test_combination_of_select_and_style_with_css_payload
653
+ input , tags = "<select><style>div > span { background: \" red\" ; }</style></select>" , [ "select" , "style" ]
654
+ expected = "<select><style>div > span { background: \" red\" ; }</style></select>"
655
+ actual = safe_list_sanitize ( input , tags : tags )
656
+
657
+ assert_equal ( expected , actual )
658
+ end
659
+
660
+ def test_combination_of_select_and_style_with_script_payload
661
+ input , tags = "<select><style><script>alert(1)</script></style></select>" , [ "select" , "style" ]
662
+ expected = "<select><style><script>alert(1)</script></style></select>"
663
+ actual = safe_list_sanitize ( input , tags : tags )
664
+
665
+ assert_equal ( expected , actual )
666
+ end
667
+
668
+ def test_combination_of_svg_and_style_with_script_payload
669
+ input , tags = "<svg><style><script>alert(1)</script></style></svg>" , [ "svg" , "style" ]
670
+ expected = "<svg><style><script>alert(1)</script></style></svg>"
671
+ actual = safe_list_sanitize ( input , tags : tags )
672
+
673
+ assert_equal ( expected , actual )
674
+ end
675
+
676
+ def test_combination_of_math_and_style_with_img_payload
677
+ input , tags = "<math><style><img src=x onerror=alert(1)></style></math>" , [ "math" , "style" ]
678
+ expected = "<math><style><img src=x onerror=alert(1)></style></math>"
679
+ actual = safe_list_sanitize ( input , tags : tags )
680
+
681
+ assert_equal ( expected , actual )
682
+
683
+ input , tags = "<math><style><img src=x onerror=alert(1)></style></math>" , [ "math" , "style" , "img" ]
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
+ end
689
+
690
+ def test_combination_of_svg_and_style_with_img_payload
691
+ input , tags = "<svg><style><img src=x onerror=alert(1)></style></svg>" , [ "svg" , "style" ]
692
+ expected = "<svg><style><img src=x onerror=alert(1)></style></svg>"
693
+ actual = safe_list_sanitize ( input , tags : tags )
694
+
695
+ assert_equal ( expected , actual )
696
+
697
+ input , tags = "<svg><style><img src=x onerror=alert(1)></style></svg>" , [ "svg" , "style" , "img" ]
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
+ end
703
+
644
704
protected
645
705
646
706
def xpath_sanitize ( input , options = { } )
0 commit comments