From 43a87f538af42dd11cd72fddacbba2519d1e5c78 Mon Sep 17 00:00:00 2001 From: Josh Goodall Date: Sun, 29 Sep 2019 20:20:30 +1000 Subject: [PATCH] Match Loofah's API changes. Short term, reduces log noise due to deprecated constants. Long term, necessary just to keep up. --- lib/rails/html/sanitizer.rb | 2 +- lib/rails/html/scrubbers.rb | 8 ++++---- rails-html-sanitizer.gemspec | 2 +- test/sanitizer_test.rb | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/rails/html/sanitizer.rb b/lib/rails/html/sanitizer.rb index b35010a..5633ca1 100644 --- a/lib/rails/html/sanitizer.rb +++ b/lib/rails/html/sanitizer.rb @@ -74,7 +74,7 @@ def sanitize(html, options = {}) # # === Options # Sanitizes both html and css via the safe lists found here: - # https://github.com/flavorjones/loofah/blob/master/lib/loofah/html5/whitelist.rb + # https://github.com/flavorjones/loofah/blob/master/lib/loofah/html5/safelist.rb # # SafeListSanitizer also accepts options to configure # the safe list used when sanitizing html. diff --git a/lib/rails/html/scrubbers.rb b/lib/rails/html/scrubbers.rb index 6050235..c44d0ee 100644 --- a/lib/rails/html/scrubbers.rb +++ b/lib/rails/html/scrubbers.rb @@ -138,17 +138,17 @@ def scrub_attribute(node, attr_node) attr_node.node_name end - if Loofah::HTML5::WhiteList::ATTR_VAL_IS_URI.include?(attr_name) + if Loofah::HTML5::SafeList::ATTR_VAL_IS_URI.include?(attr_name) # this block lifted nearly verbatim from HTML5 sanitization val_unescaped = CGI.unescapeHTML(attr_node.value).gsub(Loofah::HTML5::Scrub::CONTROL_CHARACTERS,'').downcase - if val_unescaped =~ /^[a-z0-9][-+.a-z0-9]*:/ && ! Loofah::HTML5::WhiteList::ALLOWED_PROTOCOLS.include?(val_unescaped.split(Loofah::HTML5::WhiteList::PROTOCOL_SEPARATOR)[0]) + if val_unescaped =~ /^[a-z0-9][-+.a-z0-9]*:/ && ! Loofah::HTML5::SafeList::ALLOWED_PROTOCOLS.include?(val_unescaped.split(Loofah::HTML5::SafeList::PROTOCOL_SEPARATOR)[0]) attr_node.remove end end - if Loofah::HTML5::WhiteList::SVG_ATTR_VAL_ALLOWS_REF.include?(attr_name) + if Loofah::HTML5::SafeList::SVG_ATTR_VAL_ALLOWS_REF.include?(attr_name) attr_node.value = attr_node.value.gsub(/url\s*\(\s*[^#\s][^)]+?\)/m, ' ') if attr_node.value end - if Loofah::HTML5::WhiteList::SVG_ALLOW_LOCAL_HREF.include?(node.name) && attr_name == 'xlink:href' && attr_node.value =~ /^\s*[^#\s].*/m + if Loofah::HTML5::SafeList::SVG_ALLOW_LOCAL_HREF.include?(node.name) && attr_name == 'xlink:href' && attr_node.value =~ /^\s*[^#\s].*/m attr_node.remove end diff --git a/rails-html-sanitizer.gemspec b/rails-html-sanitizer.gemspec index 4edbaa7..317f38b 100644 --- a/rails-html-sanitizer.gemspec +++ b/rails-html-sanitizer.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |spec| # NOTE: There's no need to update this dependency for Loofah CVEs # in minor releases when users can simply run `bundle update loofah`. - spec.add_dependency "loofah", "~> 2.2", ">= 2.2.2" + spec.add_dependency "loofah", "~> 2.3" 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 8c579af..6d44008 100644 --- a/test/sanitizer_test.rb +++ b/test/sanitizer_test.rb @@ -181,7 +181,7 @@ def test_sanitize_image_src assert_sanitized raw, %{src="javascript:bang" foo, bar} end - tags = Loofah::HTML5::WhiteList::ALLOWED_ELEMENTS - %w(script form) + tags = Loofah::HTML5::SafeList::ALLOWED_ELEMENTS - %w(script form) tags.each do |tag_name| define_method "test_should_allow_#{tag_name}_tag" do scope_allowed_tags(tags) do