How to make sure Rails API is secured from CSRF?

后端 未结 1 391
伪装坚强ぢ
伪装坚强ぢ 2021-01-04 09:03

I\'ve been developing Rails app with REST API for access from mobile application.

It works quite well. When user logs in from mobile application, he gets auth_

相关标签:
1条回答
  • 2021-01-04 09:48

    You may see people suggest that CSRF is not an issue for API requests (there is no state to begin with, so what is there to hijack anyhow?), so some suggest the following to simply eliminate the warning:

    skip_before_filter :verify_authenticity_token, :only => [:your_method]
    

    However, there was some commentary that it is possible to commit CSRF with text/plain using various Flash and Java-based methods. I believe that was the reason for the security patch in rails a while back: http://weblog.rubyonrails.org/2011/2/8/csrf-protection-bypass-in-ruby-on-rails/

    In any event, a good solution that actually checks for an authenticity token can be found here: WARNING: Can't verify CSRF token authenticity rails

    It involves actually setting the header in your request.

    Good luck!

    0 讨论(0)
提交回复
热议问题