I read a lot around:
However, I am not yet able to understand if our endpoint ("/graphql") is protected for this type of attack or if it is necessary to protect it with solutions like this: https://github.com/expressjs/csurf.
The thing that is not clear to me is that here: https://github.com/pillarjs/understanding-csrf they say:
When you're using CSRF tokens incorrectly: ... Adding them to JSON AJAX calls As noted above, if you do not support CORS and your APIs are strictly JSON, there is absolutely no point in adding CSRF tokens to your AJAX calls.
If we restrict our endpoint to just use Content-Type: application/json
are we safe?
If we restrict our endpoint to just use Content-Type: application/json are we safe?
JSON is not immune to CSRF attacks (but requires a little extra work for the attacker) and by extension, neither would GraphQL if not properly configured. If you break it down to the requests / responses, the usual scenario of CSRF would apply here:
In this scenario, your service is vulnerable to CSRF. Ensure that CORS is configured to only allow requests from a white list of trusted domains and ensure that a CSRF token is in use. Implementing multiple protections will reduce the risk of a successful attack.
The following link goes into greater detail and you can even try it yourself: https://blog.appsecco.com/exploiting-csrf-on-json-endpoints-with-flash-and-redirects-681d4ad6b31b
This answer is also relevant: Are JSON web services vulnerable to CSRF attacks?