CSRF validation needed or not when using RESTful API?

后端 未结 1 1197
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-22 03:36

The following is written on the of the page of FOSRestBundle:

\"CSRF validation

When building a single application that should handle forms both via HTML for

相关标签:
1条回答
  • 2020-12-22 04:03

    CSRF token validation is not actually used for implementing RESTful Web Services, because it violates the initial principles of REST (REST is stateless, there is no client context, being saved on the server side). Instead one can check the Referer Header (it does not require a per-user state) and maybe some combination of custom header field and GET parameter. If your API is not public, then you should use an API-key based authentication or OAuth.

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