Skip to content

Commit f3ba1a8

Browse files
committed
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. Fix CVE-2018-3741.
1 parent 7aea595 commit f3ba1a8

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

lib/rails/html/scrubbers.rb

+2
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ def scrub_attribute(node, attr_node)
153153
end
154154

155155
node.remove_attribute(attr_node.name) if attr_name == 'src' && attr_node.value !~ /[^[:space:]]/
156+
157+
Loofah::HTML5::Scrub.force_correct_attribute_escaping! node
156158
end
157159
end
158160

rails-html-sanitizer.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
1717
spec.test_files = Dir["test/**/*"]
1818
spec.require_paths = ["lib"]
1919

20-
spec.add_dependency "loofah", "~> 2.0"
20+
spec.add_dependency "loofah", "~> 2.2", ">= 2.2.2"
2121

2222
spec.add_development_dependency "bundler", "~> 1.3"
2323
spec.add_development_dependency "rake"

test/sanitizer_test.rb

+34-2
Original file line numberDiff line numberDiff line change
@@ -385,13 +385,13 @@ def test_should_sanitize_attributes
385385

386386
def test_should_sanitize_illegal_style_properties
387387
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;)
388-
expected = %(display: block; width: 100%; height: 100%; background-color: black; background-x: center; background-y: center;)
388+
expected = %(display:block;width:100%;height:100%;background-color:black;background-x:center;background-y:center;)
389389
assert_equal expected, sanitize_css(raw)
390390
end
391391

392392
def test_should_sanitize_with_trailing_space
393393
raw = "display:block; "
394-
expected = "display: block;"
394+
expected = "display:block;"
395395
assert_equal expected, sanitize_css(raw)
396396
end
397397

@@ -484,6 +484,38 @@ def test_allow_data_attribute_if_requested
484484
assert_equal %(<a data-foo="foo">foo</a>), white_list_sanitize(text, attributes: ['data-foo'])
485485
end
486486

487+
def test_uri_escaping_of_href_attr_in_a_tag_in_white_list_sanitizer
488+
html = %{<a href='examp<!--" unsafeattr=foo()>-->le.com'>test</a>}
489+
490+
text = white_list_sanitize(html)
491+
492+
assert_equal %{<a href="examp<!--%22%20unsafeattr=foo()>-->le.com">test</a>}, text
493+
end
494+
495+
def test_uri_escaping_of_src_attr_in_a_tag_in_white_list_sanitizer
496+
html = %{<a src='examp<!--" unsafeattr=foo()>-->le.com'>test</a>}
497+
498+
text = white_list_sanitize(html)
499+
500+
assert_equal %{<a src="examp<!--%22%20unsafeattr=foo()>-->le.com">test</a>}, text
501+
end
502+
503+
def test_uri_escaping_of_name_attr_in_a_tag_in_white_list_sanitizer
504+
html = %{<a name='examp<!--" unsafeattr=foo()>-->le.com'>test</a>}
505+
506+
text = white_list_sanitize(html)
507+
508+
assert_equal %{<a name="examp<!--%22%20unsafeattr=foo()>-->le.com">test</a>}, text
509+
end
510+
511+
def test_uri_escaping_of_name_action_in_a_tag_in_white_list_sanitizer
512+
html = %{<a action='examp<!--" unsafeattr=foo()>-->le.com'>test</a>}
513+
514+
text = white_list_sanitize(html, attributes: ['action'])
515+
516+
assert_equal %{<a action="examp<!--%22%20unsafeattr=foo()>-->le.com">test</a>}, text
517+
end
518+
487519
protected
488520

489521
def xpath_sanitize(input, options = {})

0 commit comments

Comments
 (0)