My approach has always been to turn of CSRF for API routes - if you don't want people being able to POST/PUT/DELETE, then authentication would be a good idea. Why does turning CSRF off for these routes not sound right to you?
--
Pat
> --
> You received this message because you are subscribed to the Google Groups "Ruby or Rails Oceania" group.
> To post to this group, send email to rails-...@googlegroups.com.
> To unsubscribe from this group, send email to rails-oceani...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rails-oceania?hl=en.
>
--
Pat
CSRF protection is not required for API calls because you will likely never consume it using a browser, and more over never create a session, each API call should reauthenticate from a token or header etc. before processing anything.
Regards,
Ivan Vanderbyl
Sent from my iPhone
If you're using session-based authentication, you should always enable CSRF protection.
If you disable CSRF protection, you should also disable session-based authentication.
-- Paul
> I've just added this to my application controller and it seems to be
> working ok for what I need now though.
>
> before_filter(:except => [:index, :show]) do |controller|
> protect_from_forgery unless controller.request.format.xml?
> end
This could leave you open to CSRF attacks that have ".xml" appended to the target URL.
It's certainly a big improvement on no protection at all, though.
-- Paul
So if the request is to be authenticated with a token/some form of API authentication, disable session and disable forgery protection, otherwise require it.
— Ivan
--
Pat