Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the 'src' attribute allowed to link to scripts from external domains, and XmlHtppRequests not?

I have read several answers on StackOverflow regarding same-origin policy, but I don't seem to graps the essential part.

In all tags that use the src attribute, like <script> and <img>, you are allowed to use external resources (from another domain).

Why is this allowed, but with a XMLHttpRequest (e.g. AJAX calls) it is not. I do not seem to graps why the latter is more dangerous.

I mean, you could also have malicious code in an external source like: <script src="http://example.com/malicious_script.js"></script>

like image 304
Paul Verschoor Avatar asked Nov 21 '25 04:11

Paul Verschoor


1 Answers

The same-origin policy aims to protect the remote server's data from an unknown client, not to protect the client from malicious code from the server. <script> tags do not allow the client to make requests other than GETs or to obtain data that is not explicitly exposed by the server in a valid JavaScript file.

like image 81
Alexandre Vicente Avatar answered Nov 22 '25 18:11

Alexandre Vicente



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!