From 301be1abd956859e8e34925eaebf1a852f62cd9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 21 Mar 2018 15:23:56 -0400 Subject: [PATCH] Make sure we address CVE-2018-8048 Even that the issue was fixed on loofah we have our own logic to scrub attributes so when the whitelist serializer is used the issue was still present. --- lib/rails/html/scrubbers.rb | 2 ++ rails-html-sanitizer.gemspec | 2 +- test/sanitizer_test.rb | 46 +++++++++++++++++++++++++++++++++++++------- 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/lib/rails/html/scrubbers.rb b/lib/rails/html/scrubbers.rb index 1e6f887..3695bb2 100644 --- a/lib/rails/html/scrubbers.rb +++ b/lib/rails/html/scrubbers.rb @@ -152,6 +152,8 @@ module Rails end node.remove_attribute(attr_node.name) if attr_name == 'src' && attr_node.value !~ /[^[:space:]]/ + + Loofah::HTML5::Scrub.force_correct_attribute_escaping! node end end diff --git a/rails-html-sanitizer.gemspec b/rails-html-sanitizer.gemspec index a600053..cb7a5fb 100644 --- a/rails-html-sanitizer.gemspec +++ b/rails-html-sanitizer.gemspec @@ -17,7 +17,7 @@ Gem::Specification.new do |spec| spec.test_files = Dir["test/**/*"] spec.require_paths = ["lib"] - spec.add_dependency "loofah", "~> 2.0" + spec.add_dependency "loofah", "~> 2.2", ">= 2.2.2" spec.add_development_dependency "bundler", "~> 1.3" spec.add_development_dependency "rake" diff --git a/test/sanitizer_test.rb b/test/sanitizer_test.rb index f72b702..552603c 100644 --- a/test/sanitizer_test.rb +++ b/test/sanitizer_test.rb @@ -58,11 +58,11 @@ class SanitizersTest < Minitest::Test end def test_strip_invalid_html - assert_equal "", full_sanitize("<<") + assert_equal "<<", full_sanitize("<<") end def test_strip_tags_with_sentence @@ -123,7 +123,7 @@ class SanitizersTest < Minitest::Test end def test_strip_links_with_tags_in_tags - expected = "a href='hello'>all day long/a>" + expected = "<a href='hello'>all day long</a>" input = "<a href='hello'>all day long</a>" assert_equal expected, link_sanitize(input) end @@ -360,7 +360,7 @@ class SanitizersTest < Minitest::Test end def test_should_sanitize_script_tag_with_multiple_open_brackets - assert_sanitized %(<), "alert(\"XSS\");//" + assert_sanitized %(<), "<alert(\"XSS\");//<" assert_sanitized %(