Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Same origin policy" and scripts loaded from google - a vulnerable solution?

I read the question here in SO "jQuery Linking vs. Download" and I somehow don't get it.

What happens if you host a page on http://yourserver.com, but load jQuery library from http://ajax.googleapis.com and then use the functions defined in jQuery script?

Does "same origin policy" not count in this case? I mean, can you make AJAX calls back to http://yourserver.com?
Is the JavaScript being executed considered as coming from yourserver.com?

My point here is, you do not know what the user has downloaded from some third party server (sorry, Google), and still the code executing on his computer is as good as the one he would download from your server?

EDIT: Does it mean _that if I use a web statistics counter from a 3rd party I don't know very well, they might "inject" some code and call into my web services as if their code was part of mine?

like image 876
naivists Avatar asked Jan 19 '10 13:01

naivists


People also ask

How do you solve the same-origin policy?

Changing Origin Occasionally, the same origin policy may block requests between subdomains on the same domain. The easiest way to solve this problem is to set document. domain from within JavaScript.

Can XSS Bypass same-origin policy?

Cross-site scripting bypasses the same-origin policy because malicious JavaScript is injected in a valid HTTP request causing the code to run in the same origin. Since malicious JavaScript comes from within the origin, the browser will trust it and cannot do anything about it.

What does the same-origin policy allow?

The same-origin policy restricts which network messages one origin can send to another. For example, the same-origin policy allows inter-origin HTTP requests with GET and POST methods but denies inter-origin PUT and DELETE requests.

Which among the following are techniques used to bypass the same-origin policy SOP )?

The best way to relax the SOP and allow cross-origin communication with XHR is using cross-origin resource sharing (CORS).


2 Answers

The owner of site http://yourserver.com/ should trust the content it references from other servers (in this case, Google's). The same origin policy doesn't apply to "script" tags.

Of course, the scripts of the foreign servers (once loaded) have access to the whole DOM: so, if the foreign content is compromised, there can be security exposures.

As with many things in the web world, it comes down to trust and continuous management.

Edit:

Does it mean _that if I use a web statistics counter from a 3rd party I don't know very well, they might "inject" some code and call into my web services as if their code was part of mine?

Yes.

like image 131
jldupont Avatar answered Sep 17 '22 04:09

jldupont


Answering the Edit comment: Yes. Unless the counter was wrapped in an iframe tag, it is as if it was a part of your web site and can call into your web services, access your cookies, etc.

like image 39
ReinstateMonica Larry Osterman Avatar answered Sep 20 '22 04:09

ReinstateMonica Larry Osterman