Skip to content
This repository
Browse code

Reflect how CSRF protection now works and refer to the Security Guide…

… for more information
  • Loading branch information...
commit c28d46a92d1ed91fe929871f5e0e4adcda46c2a7 1 parent ca36326
Joost Baaij authored August 26, 2010
54  actionpack/lib/action_controller/metal/request_forgery_protection.rb
@@ -4,45 +4,27 @@ module ActionController #:nodoc:
4 4
   class InvalidAuthenticityToken < ActionControllerError #:nodoc:
5 5
   end
6 6
 
7  
-  # Protecting controller actions from CSRF attacks by ensuring that all forms are coming from the current
8  
-  # web application, not a forged link from another site, is done by embedding a token based on a random
9  
-  # string stored in the session (which an attacker wouldn't know) in all forms and Ajax requests generated
10  
-  # by Rails and then verifying the authenticity of that token in the controller.  Only HTML/JavaScript
11  
-  # requests are checked, so this will not protect your XML API (presumably you'll have a different
12  
-  # authentication scheme there anyway).  Also, GET requests are not protected as these should be
13  
-  # idempotent anyway.
  7
+  # Controller actions are protected from Cross-Site Request Forgery (CSRF) attacks
  8
+  # by including a token in the rendered html for your application. This token is
  9
+  # stored as a random string in the session, to which an attacker does not have
  10
+  # access. When a request reaches your application, \Rails then verifies the received
  11
+  # token with the token in the session. Only HTML and javascript requests are checked,
  12
+  # so this will not protect your XML API (presumably you'll have a different
  13
+  # authentication scheme there anyway). Also, GET requests are not protected as these
  14
+  # should be idempotent.
14 15
   #
15  
-  # This is turned on with the <tt>protect_from_forgery</tt> method, which will check the token and raise an
16  
-  # ActionController::InvalidAuthenticityToken if it doesn't match what was expected. You can customize the
17  
-  # error message in production by editing public/422.html.  A call to this method in ApplicationController is
18  
-  # generated by default in post-Rails 2.0 applications.
  16
+  # CSRF protection is turned on with the <tt>protect_from_forgery</tt> method,
  17
+  # which will check the token and raise an ActionController::InvalidAuthenticityToken
  18
+  # if it doesn't match what was expected. A call to this method is generated for new
  19
+  # \Rails applications by default. You can customize the error message by editing
  20
+  # public/422.html. 
19 21
   #
20  
-  # The token parameter is named <tt>authenticity_token</tt> by default. If you are generating an HTML form
21  
-  # manually (without the use of Rails' <tt>form_for</tt>, <tt>form_tag</tt> or other helpers), you have to
22  
-  # include a hidden field named like that and set its value to what is returned by
23  
-  # <tt>form_authenticity_token</tt>.
24  
-  #
25  
-  # Request forgery protection is disabled by default in test environment. If you are upgrading from Rails
26  
-  # 1.x, add this to config/environments/test.rb:
27  
-  #
28  
-  #   # Disable request forgery protection in test environment
29  
-  #   config.action_controller.allow_forgery_protection = false
30  
-  #
31  
-  # == Learn more about CSRF (Cross-Site Request Forgery) attacks
32  
-  #
33  
-  # Here are some resources:
34  
-  # * http://isc.sans.org/diary.html?storyid=1750
35  
-  # * http://en.wikipedia.org/wiki/Cross-site_request_forgery
36  
-  #
37  
-  # Keep in mind, this is NOT a silver-bullet, plug 'n' play, warm security blanket for your rails application.
38  
-  # There are a few guidelines you should follow:
39  
-  #
40  
-  # * Keep your GET requests safe and idempotent.  More reading material:
41  
-  #   * http://www.xml.com/pub/a/2002/04/24/deviant.html
42  
-  #   * http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.1.1
43  
-  #   * Make sure the session cookies that Rails creates are non-persistent.  Check in Firefox and look
44  
-  #     for "Expires: at end of session"
  22
+  # The token parameter is named <tt>authenticity_token</tt> by default. The name and
  23
+  # value of this token must be added to every layout that renders forms by including
  24
+  # <tt>csrf_meta_tag</tt> in the html +head+.
45 25
   #
  26
+  # Learn more about CSRF attacks and securing your application in the
  27
+  # {Ruby on Rails Security Guide}[http://guides.rubyonrails.org/security.html].
46 28
   module RequestForgeryProtection
47 29
     extend ActiveSupport::Concern
48 30
 

0 notes on commit c28d46a

Please sign in to comment.
Something went wrong with that request. Please try again.