Skip to content

Commit 68ccf7e

Browse files
committed
revert 45a5c10
to prepare for a better fix
1 parent bb6dfcb commit 68ccf7e

File tree

2 files changed

+1
-41
lines changed

2 files changed

+1
-41
lines changed

lib/rails/html/sanitizer.rb

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -141,25 +141,8 @@ def sanitize_css(style_string)
141141

142142
private
143143

144-
def loofah_using_html5?
145-
# future-proofing, see https://github.com/flavorjones/loofah/pull/239
146-
Loofah.respond_to?(:html5_mode?) && Loofah.html5_mode?
147-
end
148-
149-
def remove_safelist_tag_combinations(tags)
150-
if !loofah_using_html5? && tags.include?("select") && tags.include?("style")
151-
warn("WARNING: #{self.class}: removing 'style' from safelist, should not be combined with 'select'")
152-
tags.delete("style")
153-
end
154-
tags
155-
end
156-
157144
def allowed_tags(options)
158-
if options[:tags]
159-
remove_safelist_tag_combinations(options[:tags])
160-
else
161-
self.class.allowed_tags
162-
end
145+
options[:tags] || self.class.allowed_tags
163146
end
164147

165148
def allowed_attributes(options)

test/sanitizer_test.rb

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -587,25 +587,6 @@ def test_exclude_node_type_comment
587587
assert_equal("<div>text</div><b>text</b>", safe_list_sanitize("<div>text</div><!-- comment --><b>text</b>"))
588588
end
589589

590-
def test_disallow_the_dangerous_safelist_combination_of_select_and_style
591-
input = "<select><style><script>alert(1)</script></style></select>"
592-
tags = ["select", "style"]
593-
warning = /WARNING: Rails::Html::SafeListSanitizer: removing 'style' from safelist/
594-
sanitized = nil
595-
invocation = Proc.new { sanitized = safe_list_sanitize(input, tags: tags) }
596-
597-
if html5_mode?
598-
# if Loofah is using an HTML5 parser,
599-
# then "style" should be removed by the parser as an invalid child of "select"
600-
assert_silent(&invocation)
601-
else
602-
# if Loofah is using an HTML4 parser,
603-
# then SafeListSanitizer should remove "style" from the safelist
604-
assert_output(nil, warning, &invocation)
605-
end
606-
refute_includes(sanitized, "style")
607-
end
608-
609590
%w[text/plain text/css image/png image/gif image/jpeg].each do |mediatype|
610591
define_method "test_mediatype_#{mediatype}_allowed" do
611592
input = %Q(<img src="data:#{mediatype};base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4=">)
@@ -733,8 +714,4 @@ def libxml_2_9_14_recovery_lt_bang?
733714
# then reverted in 2.10.0, see https://gitlab.gnome.org/GNOME/libxml2/-/issues/380
734715
Nokogiri.method(:uses_libxml?).arity == -1 && Nokogiri.uses_libxml?("= 2.9.14")
735716
end
736-
737-
def html5_mode?
738-
::Loofah.respond_to?(:html5_mode?) && ::Loofah.html5_mode?
739-
end
740717
end

0 commit comments

Comments
 (0)