Package: rails / 2.3.5-1.2+squeeze8

CVE-2012-1099.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
--- a/actionpack/lib/action_view/helpers/form_options_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_options_helper.rb
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 require 'cgi'
 require 'erb'
 require 'action_view/helpers/form_helper'
@@ -568,11 +569,11 @@ module ActionView
       private
         def add_options(option_tags, options, value = nil)
           if options[:include_blank]
-            option_tags = "<option value=\"\">#{options[:include_blank] if options[:include_blank].kind_of?(String)}</option>\n" + option_tags
+            option_tags = content_tag('option', options[:include_blank].kind_of?(String) ? options[:include_blank] : nil, :value => '') + "\n" + option_tags
           end
           if value.blank? && options[:prompt]
             prompt = options[:prompt].kind_of?(String) ? options[:prompt] : I18n.translate('support.select.prompt', :default => 'Please select')
-            "<option value=\"\">#{prompt}</option>\n" + option_tags
+            option_tags = content_tag('option', prompt, :value => '') + "\n" + option_tags
           else
             option_tags
           end
--- a/actionpack/test/template/form_options_helper_test.rb
+++ b/actionpack/test/template/form_options_helper_test.rb
@@ -334,7 +334,7 @@ class FormOptionsHelperTest < ActionView
 
   def test_select_under_fields_for_with_string_and_given_prompt
     @post = Post.new
-    options = "<option value=\"abe\">abe</option><option value=\"mus\">mus</option><option value=\"hest\">hest</option>"
+    options = "<option value=\"abe\">abe</option><option value=\"mus\">mus</option><option value=\"hest\">hest</option>".html_safe
 
     fields_for :post, @post do |f|
       concat f.select(:category, options, :prompt => 'The prompt')
@@ -421,6 +421,13 @@ class FormOptionsHelperTest < ActionView
     )
   end
 
+  def test_select_escapes_options
+    assert_dom_equal(
+      '<select id="post_title" name="post[title]">&lt;script&gt;alert(1)&lt;/script&gt;</select>',
+      select('post', 'title', '<script>alert(1)</script>')
+    )
+  end
+
   def test_select_with_selected_nil
     @post = Post.new
     @post.category = "<mus>"