javascript - 动态脚本标签的安全问题

标签 javascript security json

flickr blog post讨论了他们对人员选择器自动完成的最新改进背后的想法。

他们必须克服的一个问题是如何在客户端解析和处理如此多的数据(即您的所有联系人)。他们尝试通过 AJAX 获取 XML 和 JSON,但发现速度太慢。然后他们就通过动态生成的脚本标签(带有回调函数)加载数据说了这句话:

JSON and Dynamic Script Tags: Fast but Insecure

Working with the theory that large string manipulation was the problem with the last approach, we switched from using Ajax to instead fetching the data using a dynamically generated script tag. This means that the contact data was never treated as string, and was instead executed as soon as it was downloaded, just like any other JavaScript file. The difference in performance was shocking: 89ms to parse 10,000 contacts (a reduction of 3 orders of magnitude), while the smallest case of 172 contacts only took 6ms. The parse time per contact actually decreased the larger the list became. This approach looked perfect, except for one thing: in order for this JSON to be executed, we had to wrap it in a callback method. Since it’s executable code, any website in the world could use the same approach to download a Flickr member’s contact list. This was a deal breaker. (emphasis mine)

有人可以在这里深入探讨确切的安全风险吗(可能有示例漏洞利用)?通过脚本标记中的“src”属性加载给定文件与通过 AJAX 调用加载该文件有何不同?

最佳答案

这是一个很好的问题,这种类型的漏洞曾经被用来从 gmail 中窃取联系人列表。

每当浏览器从域中获取数据时,它都会发送网站设置的任何 cookie 数据。然后可以使用此 cookie 数据对用户进行身份验证,并获取任何特定的用户数据。

例如,当您加载新的 stackoverflow.com 页面时,您的浏览器会将您的 cookie 数据发送到 stackoverflow.com。 Stackoverflow 使用该数据来确定您是谁,并为您显示适当的数据。

对于从域加载的任何其他内容(包括 CSS 和 Javascript 文件)也是如此。

Flickr 面临的安全漏洞是任何网站都可以嵌入这个托管在 Flickr 服务器上的 javascript 文件。然后,您的 Flickr cookie 数据将作为请求的一部分发送(因为 javascript 托管在 flickr.com 上),Flickr 将生成包含敏感数据的 javascript 文档。然后,恶意站点将能够访问已加载的数据。

这是用来窃取谷歌联系人的漏洞,这可能比我上面的解释更清楚: http://blogs.zdnet.com/Google/?p=434

关于javascript - 动态脚本标签的安全问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/691276/

相关文章:

C# Json.Net 使用不同的 "key"参数反序列化 Json

javascript - Inversify.js - Reflect.hasOwnMetadata 不是函数

javascript - jQuery:尝试将选项附加到选择标签

php - 与盐渍 SHA512 相比,盐渍 SHA1 有多不安全

html - 我可以在 Twig 中自定义 html|raw 吗

javascript - 我可以保护原生 JavaScript 函数吗

javascript - 难以使用全局变量和 $.getScript

javascript - attachEvent/addEventListener 到 Window onload/load - 首选方式

c# - 无法解析 JSON 文件,Progam.cs asp.net core 中出错

json - Poison.Encoder 如何重命名渲染 JSON 中的属性?