I am building a web service that exclusively uses JSON for its request and response content (i.e., no form encoded payloads).
Is a web service vulnerable to CSRF attack if the following are true?
Any
POSTrequest without a top-level JSON object, e.g.,{"foo":"bar"}, will be rejected with a 400. For example, aPOSTrequest with the content42would be thus rejected.Any
POSTrequest with a content-type other thanapplication/jsonwill be rejected with a 400. For example, aPOSTrequest with content-typeapplication/x-www-form-urlencodedwould be thus rejected.All GET requests will be Safe, and thus not modify any server-side data.
Clients are authenticated via a session cookie, which the web service gives them after they provide a correct username/password pair via a POST with JSON data, e.g.
{"username":"user@example.com", "password":"my password"}.
Ancillary question: Are PUT and DELETE requests ever vulnerable to CSRF? I ask because it seems that most (all?) browsers disallow these methods in HTML forms.
EDIT: Added item #4.
EDIT: Lots of good comments and answers so far, but no one has offered a specific CSRF attack to which this web service is vulnerable.