aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/test/template/tag_helper_test.rb
diff options
context:
space:
mode:
authorAndrew Carpenter <andrew@criticaljuncture.org>2016-07-28 16:12:21 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2016-08-11 10:47:46 -0700
commit4394e9075189ee6031944491aecd64fb269cdf54 (patch)
tree0f9a9e118875666ae5225713fef44125fc28a11d /actionview/test/template/tag_helper_test.rb
parentb9f71e49ae43c53258da95bda50325a8d0c99a52 (diff)
downloadrails-4394e9075189ee6031944491aecd64fb269cdf54.tar.gz
rails-4394e9075189ee6031944491aecd64fb269cdf54.tar.bz2
rails-4394e9075189ee6031944491aecd64fb269cdf54.zip
ensure tag/content_tag escapes " in attribute vals
Many helpers mark content as HTML-safe without escaping double quotes -- including `sanitize`. Regardless of whether or not the attribute values are HTML-escaped, we want to be sure they don't include double quotes, as that can cause XSS issues. For example: `content_tag(:div, "foo", title: sanitize('" onmouseover="alert(1);//'))` CVE-2016-6316
Diffstat (limited to 'actionview/test/template/tag_helper_test.rb')
-rw-r--r--actionview/test/template/tag_helper_test.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/actionview/test/template/tag_helper_test.rb b/actionview/test/template/tag_helper_test.rb
index 281fec7291..c7c6649657 100644
--- a/actionview/test/template/tag_helper_test.rb
+++ b/actionview/test/template/tag_helper_test.rb
@@ -274,6 +274,16 @@ class TagHelperTest < ActionView::TestCase
assert_equal '<p class="song> play&gt;"></p>', tag.p(class: [raw("song>"), "play>"])
end
+ def test_tag_does_not_honor_html_safe_double_quotes_as_attributes
+ assert_dom_equal '<p title="&quot;">content</p>',
+ content_tag('p', "content", title: '"'.html_safe)
+ end
+
+ def test_data_tag_does_not_honor_html_safe_double_quotes_as_attributes
+ assert_dom_equal '<p data-title="&quot;">content</p>',
+ content_tag('p', "content", data: { title: '"'.html_safe })
+ end
+
def test_skip_invalid_escaped_attributes
["&1;", "&#1dfa3;", "& #123;"].each do |escaped|
assert_equal %(<a href="#{escaped.gsub(/&/, '&amp;')}" />), tag("a", href: escaped)