CSRF and RESTful API (symfony2, php)

喜你入骨 提交于 2019-12-03 03:10:15

Remember that you only need CSRF protection when your REST client is using session based authentication, otherwise CSRF protection won't help you.

If your requests DO use session based authentication, I would include the CSRF token as a header. Something like:

CSRF-Token: dfsa0jr3n2io20a;

I'm working on this issue too. Here is my original question.

I have a theoretical solution so far, but I'm not quite sure it will work. Maybe somebody can comment.

  1. Add the CSRF TOKEN to the API response cookie readable by the JS application;
  2. Send it with the request as X-CSRF-TOKEN header value by the JS application;
  3. Verify the CSRF TOKEN on the API.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!