“同源策略”和从谷歌加载的脚本 - 一个易受攻击的解决方案?
我在SO“jQuery链接与下载”中读到了这个问题,但不知何故我不知道不明白。
如果您在 http://yourserver.com
上托管页面,但从 http://ajax.googleapis.com
加载 jQuery 库,然后使用定义的函数,会发生什么情况在 jQuery 脚本中?
在这种情况下“同源策略”不算吗?我的意思是,您可以对 http://yourserver.com
进行 AJAX 调用吗?
正在执行的 JavaScript 是否被视为来自 yourserver.com
?
我的观点是,您不知道用户从第三方服务器(对不起,谷歌)下载了什么,但在他的计算机上执行的代码仍然与他从您的服务器下载的代码一样好?
编辑:这是否意味着如果我使用我不太了解的第三方的网络统计计数器,他们可能会“注入”一些代码并调用我的网络服务,就好像他们的代码是我的一部分一样?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
网站 http://yourserver.com/ 的所有者应信任其从其他服务器引用的内容(在本例中,谷歌的)。同源策略不适用于“script”标签。
当然,外部服务器的脚本(一旦加载)可以访问整个 DOM:因此,如果外部内容受到损害,可能会出现安全漏洞。
与网络世界中的许多事情一样,这取决于信任和持续管理。
编辑:
是的。
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:
Yes.
回答编辑评论:是的。除非计数器包含在 iframe 标记中,否则它就像您网站的一部分一样,可以调用您的 Web 服务、访问您的 cookie 等。
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.
是的,该政策不适用于
标记。
如果有人能够破解 google 的脚本存储,它将影响每个域提供的每个页面,这些域使用 google.com 作为脚本的主机。
Yes, the policy doesn't apply to
<script>
tags.If someone was able to hack google's script store, it would affect every page served from every domain, that uses google.com as their host for scripts.