What about the millions of sites that load jQuery from a CDN and then use $.ajax() to make requests to their home domain?
What do you mean? The 3rd script served from 3rd party domain will still execute under 1st party domain in the client's browser and that's the origin that the server sees. It doesn't prevent the scripts from calling 1st party server.
Update: Given the responses, I'm starting to think I might be incorrect on this point. I'll admit, I'm working from memory here. I'll have to go back and validate this.
Lets see how this is broken when jquery is running as a first party script.
1. third party script calls $(document).on("..", function() {})
2. event executes which causes jquery to invoke a function in the third party script
3. third party script can now make a request to the 1st party origin bypassing the 'sandbox'
ok.. so maybe the browser tries to 'secure' against this attack by marking event listeners as either having a 'good' stack or a 'bad' stack. in this case when the third party script does $(document).on() it would be identified as 'bad' stack and couldn't then make the http request because the browser would see <bad stack> at the start of the event chain.but this can still be worked around:
1. third party script calls $(document).on("event", ".selector", function() {}) after 1st party script had already set a listener on document (not an abnormal thing)
2. event happens and now it is run with 'good' stack because jquery uses a shared event handler and the event handler was originally registered with 'good' stack by the first party script. (the bad script doesn't even have to use the 'live' style. i suspect jquery shares event handlers for the same element so they would just need to try to add an event handler to an element that already has a jquery event handler)
there can be no security between scripts that share the same global state.Interestingly, MDN leads the article on same-origin policy with this sentence:
The same-origin policy is a critical security mechanism that restricts how a document or script loaded from one origin can interact with a resource from another origin.
This seems to support the way that OP described how SOP works.
Anyway. This can easily be proved one way or another. `Here is an example that shows a third party script accessing a first party domain. There is no CORs as far as I can see:
https://jsfiddle.net/aopmtn46/
If you open the console you will see "STATUS 404" which is not possible if same origin on third party scripts is enforced.
It'd increase bandwidth/latency, but you can be assured that the network calls your page are making are hitting the correct 3rd parties, and even inspect to see that the payloads are "correct".
Edit: Surely, this at the very least should be the case for payment pages and banking websites.
The browser's sandbox security model already does this for us with the same origin policy.
> ... and even inspect to see that the payloads are "correct".
This is what SRI already does for us.
I'll have to concede the first point... I was thinking that you can whitelist entire URLs to be fetched as opposed to domains, but on second thought, I don't think that'd be a meaningful change.
Thanks, this has made me think a lot more on this, however :)