Rails 4 skipping protect_from_forgery for API actions

后端 未结 2 906
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-31 08:46

I\'ve been implementing a Rails 4 application with an API. I want to be able to call the API from mobile phones and the webapp itself. I came across this note while researching

2条回答
  •  情书的邮戳
    2021-01-31 09:26

    An attacker could CURL at your controllers all they like, but if your API requires authentication, they wont get anywhere.

    Making the API consumers send a CSRF is not really what CSRF does. To do this you'd need to implement a type of knocking mechanism where your client hits an authorization endpoint first to get the code (aka CSRF) and then submit it in the POST. this sucks for mobile clients because it uses their bandwidth, power, and is laggy.

    And anyway, is it actually forgery (i.e. the F in CSRF) if its an authorized client hitting your controller after all?

提交回复
热议问题