You can safely remove the warnings with the following:
skip_before_filter :verify_authenticity_token
This should go into every Rails API controller that you have, or if you have a base_controller
for all API controllers then put it there.
If you can also access your app through a web browser then do not put this line in the application_controller
as you will be creating a security vulnerability.
It is safe to remove csrf
for API calls as the particular vulnerability can only be executed through a web browser.
Update 16th December 2013
I've seen some links to this answer and some other content which suggests a clarification. An API may be vulnerable to CSRF if you use web based authentication methods to authenticate the API - e.g. sessions or cookies.
There is some good detail in Is your Web API susceptible to a CSRF exploit?.
My advice still stands for users of RestKit as user credentials are unlikely to be based on sessions or cookies but rather usernames or api keys.
If your API can be authenticated with session or cookies then you should avoid skipping : verify_authenticity_token
and you should think about moving to api key based authentication.
If your API can be authenticated with a username and password that is also used to authenticate on the web there is still a potential exploit, although it is less serious as it would require the user to type in their username and password to your site in the HTTP Auth challenge box while visiting the site with the exploit. Again, for the best security you should think about moving to api key based authentication.
It's worth noting that I don't agree that you need to add :only => [:your_method]
for additional protection, provided that you have isolated api controllers, your api is not mixed with your web responses and you are not using session or cookies. If these are in place you can safely add the skip_before_filter
into a base_controller
for your api.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…