I am creating a web service that exclusively uses JSON for its request and response content (i.e. without encoded payload).
Is the web service vulnerable to a CSRF attack if the following is true:
Any POST request without a top-level JSON object, for example, {"foo":"bar"} , will be rejected from 400. For example, a POST request with content 42 will be rejected in this way.
Any POST request with a content type other than application/json will be rejected from 400. For example, a POST request with a content type application/x-www-form-urlencoded will be rejected in this way.
All GET requests will be safe and thus will not modify server data.
Clients are authenticated through session cookies that the web service provides them after they provide the correct username / password pair via POST with JSON data, for example. {"username":"user@example.com", "password":"my password"} .
Auxiliary question: are PUT and DELETE requests always vulnerable to CSRF? I ask because it seems that most (all?) Browsers prohibit these methods in HTML forms.
EDIT: Added item # 4.
EDIT: A lot of good comments and answers so far, but no one has offered a specific CSRF attack for which this web service is vulnerable.
djsmith Jun 13 2018-12-12T00: 00Z
source share