Hello,
I've recently upgraded from Rails 1.2 to 2.2. When I did this, swfupload broke because 2.2 no longer allows sending session data in query or form parameters - cookies only!
This of course is an issue, because swfupload cannot access the browser's cookies, and therefore will be denied access to the Rails app.
Here's the simplest solution to the problem I could come up with.
1. Create a custom session store. This sounds harder than it is. You just subclass CGI::Session::CookieStore and overrde one method - read_cookie.
2. In the overridden read_cookie method, attempt to use the real cookie if we can. If the real cookie isn't present, see if there is one in the form parameters. If so, use it.
3. That's it.
Here's a link to the custom session store, kookie_store.rb:
Drop this file in you lib directory.
Then, in environment.rb, in the Initializer section, set:
config.action_controller.session_store = :kookie_store
Also, throw a "require "webrick"" in environment.rb or where ever you put your requires (you can put this at the top of kookie_store.rb if you're not sure).
All of the standard disclaimers, e.g. this could open a gaping security hole in your app, apply.
Enjoy!
February 1, 2009 - 12:22am
Thanks for the info.
As for security any issues: It is as trivial to change the value of a cookie as it is to pass a POST parameter so this should not really affect your application's security. But the same disclaimers apply
April 15, 2009 - 4:22am
With rails 2.3.2 you can use rack middleware to force session_id in query url for flash objects, this is a nice example to do this:
http://github.com/lardawge/swfupload-rails-authentication/tree/master
In this way you can continue to use the protect_from_forgery things.
September 16, 2009 - 11:34pm
Hi there,
thanks for sharing this hack. I use Rails 2.2.1. It works fine locally with Webrick. Unfortunately, on my staging server, it fails: the stdinput is empty!
I've posted on the Phusion Passenger list: http://groups.google.com/group/phusion-passenger/browse_thread/thread/7e...
But if anybody has a suggestion for me to debug, please let me know.
Cheers