Skip to content

Commit 43a87f5

Browse files
committed
Match Loofah's API changes.
Short term, reduces log noise due to deprecated constants. Long term, necessary just to keep up.
1 parent b8ea80d commit 43a87f5

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

lib/rails/html/sanitizer.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def sanitize(html, options = {})
7474
#
7575
# === Options
7676
# Sanitizes both html and css via the safe lists found here:
77-
# https://github.com/flavorjones/loofah/blob/master/lib/loofah/html5/whitelist.rb
77+
# https://github.com/flavorjones/loofah/blob/master/lib/loofah/html5/safelist.rb
7878
#
7979
# SafeListSanitizer also accepts options to configure
8080
# the safe list used when sanitizing html.

lib/rails/html/scrubbers.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,17 @@ def scrub_attribute(node, attr_node)
138138
attr_node.node_name
139139
end
140140

141-
if Loofah::HTML5::WhiteList::ATTR_VAL_IS_URI.include?(attr_name)
141+
if Loofah::HTML5::SafeList::ATTR_VAL_IS_URI.include?(attr_name)
142142
# this block lifted nearly verbatim from HTML5 sanitization
143143
val_unescaped = CGI.unescapeHTML(attr_node.value).gsub(Loofah::HTML5::Scrub::CONTROL_CHARACTERS,'').downcase
144-
if val_unescaped =~ /^[a-z0-9][-+.a-z0-9]*:/ && ! Loofah::HTML5::WhiteList::ALLOWED_PROTOCOLS.include?(val_unescaped.split(Loofah::HTML5::WhiteList::PROTOCOL_SEPARATOR)[0])
144+
if val_unescaped =~ /^[a-z0-9][-+.a-z0-9]*:/ && ! Loofah::HTML5::SafeList::ALLOWED_PROTOCOLS.include?(val_unescaped.split(Loofah::HTML5::SafeList::PROTOCOL_SEPARATOR)[0])
145145
attr_node.remove
146146
end
147147
end
148-
if Loofah::HTML5::WhiteList::SVG_ATTR_VAL_ALLOWS_REF.include?(attr_name)
148+
if Loofah::HTML5::SafeList::SVG_ATTR_VAL_ALLOWS_REF.include?(attr_name)
149149
attr_node.value = attr_node.value.gsub(/url\s*\(\s*[^#\s][^)]+?\)/m, ' ') if attr_node.value
150150
end
151-
if Loofah::HTML5::WhiteList::SVG_ALLOW_LOCAL_HREF.include?(node.name) && attr_name == 'xlink:href' && attr_node.value =~ /^\s*[^#\s].*/m
151+
if Loofah::HTML5::SafeList::SVG_ALLOW_LOCAL_HREF.include?(node.name) && attr_name == 'xlink:href' && attr_node.value =~ /^\s*[^#\s].*/m
152152
attr_node.remove
153153
end
154154

rails-html-sanitizer.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
1919

2020
# NOTE: There's no need to update this dependency for Loofah CVEs
2121
# in minor releases when users can simply run `bundle update loofah`.
22-
spec.add_dependency "loofah", "~> 2.2", ">= 2.2.2"
22+
spec.add_dependency "loofah", "~> 2.3"
2323

2424
spec.add_development_dependency "bundler", ">= 1.3"
2525
spec.add_development_dependency "rake"

test/sanitizer_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def test_sanitize_image_src
181181
assert_sanitized raw, %{src="javascript:bang" <img width="5">foo</img>, <span>bar</span>}
182182
end
183183

184-
tags = Loofah::HTML5::WhiteList::ALLOWED_ELEMENTS - %w(script form)
184+
tags = Loofah::HTML5::SafeList::ALLOWED_ELEMENTS - %w(script form)
185185
tags.each do |tag_name|
186186
define_method "test_should_allow_#{tag_name}_tag" do
187187
scope_allowed_tags(tags) do

0 commit comments

Comments
 (0)