I was explaining the attack on a JSON REST API the other day (in real life, at work, not here), and I figured out that I do not understand part of the attack vector.
Sorry if this is quite a basic question, I'm not great with JavaScript.
A common way that this attack happens is that you have an API at, say http://myfavouritebank.com/api/account/
that returns the following on a GET request:
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: ...
{ "customer name": "Bob",
"account number": 123,
"balance" : 123.56
}
This will be returned when the user is logged in (say, using a cookie based auth). When the user is not logged in it simply returns 403.
Then, a rouge page, contains:
<script src="http://myfavouritebank.com/api/account/" />
And the rogue page will load the JSON object (given that the user is currently logged in the bank's website).
But the question is
How does the rogue page actually makes use of that object? It is just an orphan object inside the script environment, how can it be assigned to a variable for example?
In other words, I figured out that I never understood how this attack unfolds from here.
There are several great answers on how to prevent CSRF on a REAST API that explain sending the data as JSON. I am trying to understand how the rogue page is constructed to retrieve the data from such a JSON, with this information I can better explain the attack.