@@ -1026,6 +1026,46 @@ def test_should_sanitize_across_newlines
1026
1026
assert_equal "" , sanitize_css ( raw )
1027
1027
end
1028
1028
1029
+ def test_should_prune_mglyph
1030
+ # https://hackerone.com/reports/2519936
1031
+ input = "<math><mtext><table><mglyph><style><img src=: onerror=alert(1)>"
1032
+ tags = %w( math mtext table mglyph style )
1033
+
1034
+ actual = nil
1035
+ assert_output ( nil , /WARNING: 'mglyph' tags cannot be allowed by the PermitScrubber/ ) do
1036
+ actual = safe_list_sanitize ( input , tags : tags )
1037
+ end
1038
+
1039
+ acceptable_results = [
1040
+ # libxml2
1041
+ "<math><mtext><table><style><img src=: onerror=alert(1)></style></table></mtext></math>" ,
1042
+ # libgumbo
1043
+ "<math><mtext><style><img src=: onerror=alert(1)></style><table></table></mtext></math>" ,
1044
+ ]
1045
+
1046
+ assert_includes ( acceptable_results , actual )
1047
+ end
1048
+
1049
+ def test_should_prune_malignmark
1050
+ # https://hackerone.com/reports/2519936
1051
+ input = "<math><mtext><table><malignmark><style><img src=: onerror=alert(1)>"
1052
+ tags = %w( math mtext table malignmark style )
1053
+
1054
+ actual = nil
1055
+ assert_output ( nil , /WARNING: 'malignmark' tags cannot be allowed by the PermitScrubber/ ) do
1056
+ actual = safe_list_sanitize ( input , tags : tags )
1057
+ end
1058
+
1059
+ acceptable_results = [
1060
+ # libxml2
1061
+ "<math><mtext><table><style><img src=: onerror=alert(1)></style></table></mtext></math>" ,
1062
+ # libgumbo
1063
+ "<math><mtext><style><img src=: onerror=alert(1)></style><table></table></mtext></math>" ,
1064
+ ]
1065
+
1066
+ assert_includes ( acceptable_results , actual )
1067
+ end
1068
+
1029
1069
protected
1030
1070
def safe_list_sanitize ( input , options = { } )
1031
1071
module_under_test ::SafeListSanitizer . new . sanitize ( input , options )
@@ -1075,5 +1115,37 @@ class HTML4SafeListSanitizerTest < Minitest::Test
1075
1115
class HTML5SafeListSanitizerTest < Minitest ::Test
1076
1116
@module_under_test = Rails ::HTML5
1077
1117
include SafeListSanitizerTest
1118
+
1119
+ def test_should_not_be_vulnerable_to_mglyph_namespace_confusion
1120
+ # https://hackerone.com/reports/2519936
1121
+ input = "<math><mtext><table><mglyph><style><img src=: onerror=alert(1)>"
1122
+ tags = %w( math mtext table mglyph style )
1123
+
1124
+ result = nil
1125
+ assert_output ( nil , /WARNING/ ) do
1126
+ result = safe_list_sanitize ( input , tags : tags )
1127
+ end
1128
+
1129
+ browser = Nokogiri ::HTML5 ::Document . parse ( result )
1130
+ xss = browser . at_xpath ( "//img/@onerror" )
1131
+
1132
+ assert_nil ( xss )
1133
+ end
1134
+
1135
+ def test_should_not_be_vulnerable_to_malignmark_namespace_confusion
1136
+ # https://hackerone.com/reports/2519936
1137
+ input = "<math><mtext><table><malignmark><style><img src=: onerror=alert(1)>"
1138
+ tags = %w( math mtext table malignmark style )
1139
+
1140
+ result = nil
1141
+ assert_output ( nil , /WARNING/ ) do
1142
+ result = safe_list_sanitize ( input , tags : tags )
1143
+ end
1144
+
1145
+ browser = Nokogiri ::HTML5 ::Document . parse ( result )
1146
+ xss = browser . at_xpath ( "//img/@onerror" )
1147
+
1148
+ assert_nil ( xss )
1149
+ end
1078
1150
end if loofah_html5_support?
1079
1151
end
0 commit comments