I am developing a RESTful API using php / symfony2.
Symfony2 comes with CSRF protection out of the box, and it works great when using normal form data (it passes the CSRF token to the form and, when it is sent back, expects the same token that is built into the form).
However, this solution is not suitable for the purpose if you are developing a RESTful API where my interaction between the backend interface is pure JSON. Because of this, I disabled CSRF.
I know that the CSRF token is not safe, so I'm wondering what is the best way to have CSRF with the RESTful API.
One idea is to have a specific URL, for example. / api / generate / csrf, which can be called by the interface, and then add the token to the json request. It doesnβt sound like anyone can generate the safest way, like a token.
What is the best way to approach the CSRF issue when developing a RESTful API.
Cheers, Richard
source share