Comments
-
Greg Hurrell
Status changed:
- From: New
- To: Open
-
Greg Hurrell
Ok, I've fixed this issue in the application layout. Will be up for the next deployment (and seeing as we get a new
public
folder for every deployment all the old cached pages with tokens embedded in them will become inaccessible).For now the only other thing I can do is be very careful about cached pages with forms on them. As far as I can tell right now, the search form is the only culprit for now.
-
Greg Hurrell
Status changed:
- From: Open
- To: Closed
-
Greg Hurrell
I think the way to handle comment forms on page-cached pages will be to have a "Comment" button which retrieves the comment form via AJAX, or when gracefully degrading will instead take the user to a new (not-cached) page (comments#new or some such).
-
anonymous
Hi Wincent
I would agree there is some strong correlation between page caching and static pages with forms on them using Rails helpers.
I inadvertently faced the InvalidAuthenticityToken problem when I introduced page caching into the welcome page of my app. And my app has 2 forms on the welcome page - 1 for login, 1 for signup. With just the few lines of caching code, my app suddenly broke. Commenting out the protect_from_forgery line got it working. With protect_from_forgery, I had to remove page caching and I also had to manually delete the cached 'index' page in the public folder.
I was wondering - what if protect_from_forgery is not commented in application_controller.rb while simultaneously declaring a protect_from_forgery filter with :except => [:new_user, :login] - basically the two actions hit by forms pertaining to signing in and login.
Would this work ? Is there a flaw I do not see deeper down in the code or controller/view interactions ?
Looking forward to any input on this.
Rajive
-
Greg Hurrell
I don't know if it would work but it certainly might seeing as many other such controller-level declarations are overridable in subclasses.
As I commented above, the solution I went with was to hand-code the form rather than use a Rails form helper such as
form_for
or similar. This was the easiest/cleanest approach because we were just talking about a search form which is "idempotent" so doesn't really require request from forgery protection anyway.I'm using Haml, so the form looks something like this (but you could do the same in ERB or any other templating markup):
%form{:id => 'search', :action => search_index_path, :method => 'post'} =text_field_tag :query, params[:query], :size => 20, :id => :search_box
Add a comment
Comments are now closed for this issue.