I have some trouble understanding the same-origin policy and the different ways to "workaround" it.
It is clear that the same-origin policy exists as a security measure, so one script that comes from a server/domain has no access to data coming from another server/domain.
It is also clear that sometimes, it is useful to be able to break this rule, so for example a mashup application accesses information from different servers in order to build up the results wanted. And one of the ways to do this is CORS.
1) If I'm not wrong, CORS allows the target server to say to the browser "it is ok for you to take data/code from myself" by adding some headers in the response. But, if this is correct, this means that a malicious server could just add this header and the browser would allow the retrieval of any data or code, potentially harmful, coming from that server.
2) On the other side, we have JSONP, allowing us to retrieve arbitrary code or data from a server without CORS enabled, thus avoiding the main goal of the SOP. So again, a malicious server able to manage JSONP is able to inject data or code even with the SOP hardwired in the browser.
So my questions are:
Is the second argumentation correct? Is it the decision of the server whether the browser must accept the contents?
Is the second argumentation correct? It is, again, not in the browser's decision whether to accept or not data?
Does not JSONP render the SOP useless?
Thanks for enlightening me!!