@@ -1096,6 +1096,46 @@ def test_should_sanitize_across_newlines
10961096 assert_equal "" , sanitize_css ( raw )
10971097 end
10981098
1099+ def test_should_prune_mglyph
1100+ # https://hackerone.com/reports/2519936
1101+ input = "<math><mtext><table><mglyph><style><img src=: onerror=alert(1)>"
1102+ tags = %w( math mtext table mglyph style )
1103+
1104+ actual = nil
1105+ assert_output ( nil , /WARNING: 'mglyph' tags cannot be allowed by the PermitScrubber/ ) do
1106+ actual = safe_list_sanitize ( input , tags : tags )
1107+ end
1108+
1109+ acceptable_results = [
1110+ # libxml2
1111+ "<math><mtext><table><style><img src=: onerror=alert(1)></style></table></mtext></math>" ,
1112+ # libgumbo
1113+ "<math><mtext><style><img src=: onerror=alert(1)></style><table></table></mtext></math>" ,
1114+ ]
1115+
1116+ assert_includes ( acceptable_results , actual )
1117+ end
1118+
1119+ def test_should_prune_malignmark
1120+ # https://hackerone.com/reports/2519936
1121+ input = "<math><mtext><table><malignmark><style><img src=: onerror=alert(1)>"
1122+ tags = %w( math mtext table malignmark style )
1123+
1124+ actual = nil
1125+ assert_output ( nil , /WARNING: 'malignmark' tags cannot be allowed by the PermitScrubber/ ) do
1126+ actual = safe_list_sanitize ( input , tags : tags )
1127+ end
1128+
1129+ acceptable_results = [
1130+ # libxml2
1131+ "<math><mtext><table><style><img src=: onerror=alert(1)></style></table></mtext></math>" ,
1132+ # libgumbo
1133+ "<math><mtext><style><img src=: onerror=alert(1)></style><table></table></mtext></math>" ,
1134+ ]
1135+
1136+ assert_includes ( acceptable_results , actual )
1137+ end
1138+
10991139 protected
11001140 def safe_list_sanitize ( input , options = { } )
11011141 module_under_test ::SafeListSanitizer . new . sanitize ( input , options )
@@ -1175,5 +1215,37 @@ def test_should_not_be_vulnerable_to_ns_confusion_2519941
11751215
11761216 assert_nil ( xss )
11771217 end
1218+
1219+ def test_should_not_be_vulnerable_to_mglyph_namespace_confusion
1220+ # https://hackerone.com/reports/2519936
1221+ input = "<math><mtext><table><mglyph><style><img src=: onerror=alert(1)>"
1222+ tags = %w( math mtext table mglyph style )
1223+
1224+ result = nil
1225+ assert_output ( nil , /WARNING/ ) do
1226+ result = safe_list_sanitize ( input , tags : tags )
1227+ end
1228+
1229+ browser = Nokogiri ::HTML5 ::Document . parse ( result )
1230+ xss = browser . at_xpath ( "//img/@onerror" )
1231+
1232+ assert_nil ( xss )
1233+ end
1234+
1235+ def test_should_not_be_vulnerable_to_malignmark_namespace_confusion
1236+ # https://hackerone.com/reports/2519936
1237+ input = "<math><mtext><table><malignmark><style><img src=: onerror=alert(1)>"
1238+ tags = %w( math mtext table malignmark style )
1239+
1240+ result = nil
1241+ assert_output ( nil , /WARNING/ ) do
1242+ result = safe_list_sanitize ( input , tags : tags )
1243+ end
1244+
1245+ browser = Nokogiri ::HTML5 ::Document . parse ( result )
1246+ xss = browser . at_xpath ( "//img/@onerror" )
1247+
1248+ assert_nil ( xss )
1249+ end
11781250 end if loofah_html5_support?
11791251end
0 commit comments