Skip to content

Commit cd18b0e

Browse files
committed
test: Nokogiri's HTML5 "foreign style serialization" issue
https://hackerone.com/reports/2503220
1 parent 5104ca9 commit cd18b0e

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

test/sanitizer_test.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,34 @@ def test_combination_of_svg_and_style_with_img_payload_2
976976
assert_includes(acceptable_results, actual)
977977
end
978978

979+
def test_combination_of_svg_and_style_with_escaped_img_payload
980+
# https://hackerone.com/reports/2503220
981+
input, tags = "<svg><style>&lt;img src onerror=alert(1)>", ["svg", "style"]
982+
actual = safe_list_sanitize(input, tags: tags)
983+
acceptable_results = [
984+
# libxml2
985+
"<svg><style>&amp;lt;img src onerror=alert(1)&gt;</style></svg>",
986+
# libgumbo
987+
"<svg><style>&lt;img src onerror=alert(1)&gt;</style></svg>",
988+
]
989+
990+
assert_includes(acceptable_results, actual)
991+
end
992+
993+
def test_combination_of_math_and_style_with_escaped_img_payload
994+
# https://hackerone.com/reports/2503220
995+
input, tags = "<math><style>&lt;img src onerror=alert(1)>", ["math", "style"]
996+
actual = safe_list_sanitize(input, tags: tags)
997+
acceptable_results = [
998+
# libxml2
999+
"<math><style>&amp;lt;img src onerror=alert(1)&gt;</style></math>",
1000+
# libgumbo
1001+
"<math><style>&lt;img src onerror=alert(1)&gt;</style></math>",
1002+
]
1003+
1004+
assert_includes(acceptable_results, actual)
1005+
end
1006+
9791007
def test_should_sanitize_illegal_style_properties
9801008
raw = %(display:block; position:absolute; left:0; top:0; width:100%; height:100%; z-index:1; background-color:black; background-image:url(http://www.ragingplatypus.com/i/cam-full.jpg); background-x:center; background-y:center; background-repeat:repeat;)
9811009
expected = %(display:block;width:100%;height:100%;background-color:black;background-x:center;background-y:center;)
@@ -1075,5 +1103,15 @@ class HTML4SafeListSanitizerTest < Minitest::Test
10751103
class HTML5SafeListSanitizerTest < Minitest::Test
10761104
@module_under_test = Rails::HTML5
10771105
include SafeListSanitizerTest
1106+
1107+
def test_should_not_be_vulnerable_to_nokogiri_foreign_style_serialization_bug
1108+
# https://hackerone.com/reports/2503220
1109+
input = "<svg><style>&lt;img src onerror=alert(1)>"
1110+
result = Rails::HTML5::SafeListSanitizer.new.sanitize(input, tags: ["svg", "style"])
1111+
browser = Nokogiri::HTML5::Document.parse(result)
1112+
xss = browser.at_xpath("//img/@onerror")
1113+
1114+
assert_nil(xss)
1115+
end
10781116
end if loofah_html5_support?
10791117
end

0 commit comments

Comments
 (0)