Steps to reproduce:
- Start with any rails app which some kind of form and uses protect_from_forgery
- Clear your cookies
- In your browser hit the form with a single GET
- POST the form
(This works only when the single GET is cookie-less and when the POST happens from the form returned by that GET)
The result:
ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken):
/vendor/rails/actionpack/lib/action_controller/request_forgery_protection.rb:73:in `verify_authenticity_token'
...
It appears to me, that this is related to the fact that Session ID is different
between that first GET request when I didn't have any cookies and that second POST request:
Processing LabsController#new (for 127.0.0.1 at 2007-11-08 11:37:41) [GET]
Session ID: 9c79096681ef943799a2d663f2511891
Parameters: {"action"=>"new", "controller"=>"labs"}
...
Processing LabsController#create (for 127.0.0.1 at 2007-11-08 11:37:44) [POST]
Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%0ASGFzaHsABjoKQHVzZWR7AA%3D%3D--fdeb33a5c5e160863b4921ba4c06dad38348abb6
Parameters: {"lab"=>{"name"=>""}, "authenticity_token"=>"808cb7f2bf7b1afe00d67de669e8663eb83586e5", "action"=>"create", "controller"=>"labs"}
...
I'm assuming this authenticity check failed because my Session ID changed, so why did my Session ID change?