public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Change the request forgery protection to go by Content-Type instead of 
request.format so that you can't bypass it by POSTing to "#{request.uri}.xml" 
[#73 state:resolved]
rick (author)
Tue May 06 00:42:24 -0700 2008
commit  0697d17d121fcf9f46b5dd2dd1034dffa19ebdf2
tree    fae506c6f6ef3ec7b3fb05601bb61128903fd114
parent  04f52219f11944e50555dc59917c73c99581dac0
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *SVN*
0
 
0
+* Change the request forgery protection to go by Content-Type instead of request.format so that you can't bypass it by POSTing to "#{request.uri}.xml" [rick]
0
+
0
 * Fixed that TextHelper#text_field would corrypt when raw HTML was used as the value (mchenryc, Kevin Glowacz) [#80]
0
 
0
 * Added ActionController::TestCase#rescue_action_in_public! to control whether the action under test should use the regular rescue_action path instead of simply raising the exception inline (great for error testing) [DHH]
...
99
100
101
102
 
103
104
105
...
99
100
101
 
102
103
104
105
0
@@ -99,7 +99,7 @@ module ActionController #:nodoc:
0
       end
0
     
0
       def verifiable_request_format?
0
-        request.format.html? || request.format.js?
0
+        request.content_type.nil? || request.content_type.html?
0
       end
0
     
0
       # Sets the token value for the current session.  Pass a <tt>:secret</tt> option
...
93
94
95
96
 
97
98
99
100
 
101
102
103
104
 
105
106
107
108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
110
111
...
134
135
136
 
137
138
139
140
141
 
142
143
144
145
146
 
147
148
149
...
93
94
95
 
96
97
98
99
 
100
101
102
103
 
104
105
106
107
 
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
...
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
0
@@ -93,19 +93,37 @@ module RequestForgeryProtectionTests
0
     post :unsafe
0
     assert_response :success
0
   end
0
-  
0
+
0
   def test_should_not_allow_post_without_token
0
     assert_raises(ActionController::InvalidAuthenticityToken) { post :index }
0
   end
0
-  
0
+
0
   def test_should_not_allow_put_without_token
0
     assert_raises(ActionController::InvalidAuthenticityToken) { put :index }
0
   end
0
-  
0
+
0
   def test_should_not_allow_delete_without_token
0
     assert_raises(ActionController::InvalidAuthenticityToken) { delete :index }
0
   end
0
-  
0
+
0
+  def test_should_not_allow_api_formatted_post_without_token
0
+    assert_raises(ActionController::InvalidAuthenticityToken) do 
0
+      post :index, :format => 'xml'
0
+    end
0
+  end
0
+
0
+  def test_should_not_allow_put_without_token
0
+    assert_raises(ActionController::InvalidAuthenticityToken) do
0
+      put :index, :format => 'xml'
0
+    end
0
+  end
0
+
0
+  def test_should_not_allow_delete_without_token
0
+    assert_raises(ActionController::InvalidAuthenticityToken) do
0
+      delete :index, :format => 'xml'
0
+    end
0
+  end
0
+
0
   def test_should_not_allow_xhr_post_without_token
0
     assert_raises(ActionController::InvalidAuthenticityToken) { xhr :post, :index }
0
   end
0
@@ -134,16 +152,19 @@ module RequestForgeryProtectionTests
0
   end
0
   
0
   def test_should_allow_post_with_xml
0
+    @request.env['CONTENT_TYPE'] = Mime::XML.to_s
0
     post :index, :format => 'xml'
0
     assert_response :success
0
   end
0
   
0
   def test_should_allow_put_with_xml
0
+    @request.env['CONTENT_TYPE'] = Mime::XML.to_s
0
     put :index, :format => 'xml'
0
     assert_response :success
0
   end
0
   
0
   def test_should_allow_delete_with_xml
0
+    @request.env['CONTENT_TYPE'] = Mime::XML.to_s
0
     delete :index, :format => 'xml'
0
     assert_response :success
0
   end

Comments