未验证 提交 4394e907 编写于 作者: A Andrew Carpenter 提交者: Aaron Patterson

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
上级 b9f71e49
......@@ -90,7 +90,7 @@ def tag_option(key, value, escape)
else
value = escape ? ERB::Util.unwrapped_html_escape(value) : value
end
%(#{key}="#{value}")
%(#{key}="#{value.gsub(/"/, '"'.freeze)}")
end
private
......
......@@ -274,6 +274,16 @@ def test_tag_builder_honors_html_safe_with_escaped_array_class
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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册