Browse files

Escape the unit value provided to number_to_currency

Previously the unit values were trusted leading to potential XSS vulnerabilities.

Fixes: CVE-2013-6415
  • Loading branch information...
1 parent 2e3c3a8 commit b31a7a6f1ec3c74f75b4cd12386b08295287418d @NZKoz NZKoz committed with tenderlove Dec 2, 2013
View
1 actionview/lib/action_view/helpers/number_helper.rb
@@ -394,6 +394,7 @@ def delegate_number_helper_method(method, number, options)
def escape_unsafe_delimiters_and_separators(options)
options[:separator] = ERB::Util.html_escape(options[:separator]) if options[:separator] && !options[:separator].html_safe?
options[:delimiter] = ERB::Util.html_escape(options[:delimiter]) if options[:delimiter] && !options[:delimiter].html_safe?
+ options[:unit] = ERB::Util.html_escape(options[:unit]) if options[:unit] && !options[:unit].html_safe?
options
end
View
3 actionview/test/template/number_helper_test.rb
@@ -14,7 +14,8 @@ def test_number_to_currency
assert_equal nil, number_to_currency(nil)
assert_equal "$1,234,567,890.50", number_to_currency(1234567890.50)
assert_equal "$1,234,567,892", number_to_currency(1234567891.50, precision: 0)
- assert_equal "1,234,567,890.50 - Kč", number_to_currency("-1234567890.50", unit: "Kč", format: "%n %u", negative_format: "%n - %u")
+ assert_equal "1,234,567,890.50 - Kč", number_to_currency("-1234567890.50", unit: raw("Kč"), format: "%n %u", negative_format: "%n - %u")
+ assert_equal "£1,234,567,890.50", number_to_currency("1234567890.50", unit: "£")
end
def test_number_to_percentage

0 comments on commit b31a7a6

Please sign in to comment.