“防XSS保护”通过添加)]}'在ajax响应之前

发布于 2024-11-20 00:24:18 字数 104 浏览 2 评论 0原文

Google plus 在第一行返回带有 )]}' 的 ajax 请求。我听说这是针对 XSS 的防护。有没有任何例子,如果没有这种保护,任何人可以做什么以及如何处理?

Google plus returns ajax requests with )]}' on first line. I heard it is protection against XSS. Are there any examples what and how could anyone do with this without that protection ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦在夏天 2024-11-27 00:24:18

这是我对这里发生的事情的最佳猜测。

首先,google json 格式的其他方面并不是非常有效的 json。因此,除了任何保护目的之外,他们可能会使用此特定字符串来表示文件的其余部分采用 google-json 格式,需要进行相应的解释。

使用此约定还意味着数据馈送不会通过来自脚本标记的调用来执行,也不会通过直接从 eval() 解释 JavaScript 来执行。这确保前端开发人员通过解析器传递内容,这将阻止任何植入的代码执行。

因此,为了回答您的问题,这可以防止两种看似合理的攻击,一种是通过脚本标签进行跨站点攻击,但更有趣的是站点内攻击。这两种攻击都假设:

  1. 用户数据的转义方式存在错误,并且
  2. 其利用方式允许攻击者将代码注入其中一个数据源。

举一个简单的例子,假设用户弄清楚了如何获取像 example 这样的字符串

["example"] 

,并将其更改为 "];alert('example');

[""];alert('example');"]

现在,如果当如果数据显示在另一个用户的提要中,攻击者可以在用户的​​浏览器中执行任意代码,因为它位于站点内,因此 cookie 会被发送到服务器,并且攻击者可以自动执行诸如从用户帐户中共享帖子或向其他人发送消息之类的操作

。谷歌场景,这些攻击不会起作用由于多种原因,前 5 个字符会在攻击代码运行之前导致 JavaScript 错误,此外,由于开发人员被迫解析代码而不是意外地通过 eval 运行代码,因此这种做法无论如何都会阻止代码执行。 。

Here's my best guess as to what's happening here.

First off, there are other aspects of the google json format that aren't quite valid json. So, in addition to any protection purposes, they may be using this specific string to signal that the rest of the file is in google-json format and needs to be interpreted accordingly.

Using this convention also means that the data feed wont execute from a call from a script tag, nor by interpreting the javascript directly from an eval(). This ensures front end developers are passing the content through a parser, which will keep any implanted code from executing.

So to answer your question, there are two plausible attacks that this prevents, one cross-site through a script tag, but the more interesting on is within-site. Both attacks assume that:

  1. a bug exists in how user data is escaped and
  2. it is exploited in a way that allows an attacker to inject code into one of the data feeds.

As a simple example, lets say a user figured out how to take a string like example

["example"] 

and changed it to "];alert('example');

[""];alert('example');"]

Now if when that data shows up in another user's feed, the attacker can execute arbitrary code in the user's browser. Since it's within site, cookies are being sent to the server and the attacker could automate things like sharing posts or messaging people from the user's account.

In the Google scenario, these attacks won't work for a number of reasons. The first 5 characters will cause a javascript error before the attack code is run. Plus, since developers are forced to parse the code instead of accidentally running it through an eval, this practice will prevent code from being executed anyway.

阳光下慵懒的猫 2024-11-27 00:24:18

正如其他人所说,这是针对跨站脚本包含 (XSSI) 的保护,

我们在 Gruyere 上对此进行了解释作为:

第三,您应该确保该脚本不可执行。这
执行此操作的标准方法是将一些不可执行的前缀附加到
它,就像])}while(1);。在同一域中运行的脚本可以
读取响应的内容并去掉前缀,但是
在其他域中运行的脚本不能。

As others said, it's a protection against Cross Site Script Inclusion (XSSI)

We explained this on Gruyere as:

Third, you should make sure that the script is not executable. The
standard way of doing this is to append some non-executable prefix to
it, like ])}while(1);. A script running in the same domain can
read the contents of the response and strip out the prefix, but
scripts running in other domains can't.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文