5 javascript security xss cross-domain websocket
根据10.4跨文档消息传递:domainA.com可以使用跨文档消息传递向domainB.com发送消息,以防止在验证源和数据时发生跨站点脚本攻击.

为了更好地理解:它可以通过改变原始Web Socket对象来嗅探Web Socket流量,工作示例解释了这里,我提取了这部分:
if (captureWebsocket && window.WebSocket) {
// add logging onmessage listener
function captureRecv(ws) {
if (typeof ws.captured == 'undefined') {
ws.addEventListener('message', function(e) {
var event = {
event: 'websocket_recv',
from: location,
data: e.data,
url: e.target.URL
}
log(event);
});
ws.captured = true;
}
}
// capture sending
var captureSend = this.contentWindow.WebSocket.prototype.send = function() {
captureRecv(this); // in case socket contruction was before constructor switching
var event = {
event: 'websocket_send',
from: location,
data: arguments[0],
url: this.URL
};
log(event);
return window.WebSocket.prototype.send.apply(this, arguments);
}
// capture constructor
this.contentWindow.WebSocket = function(a,b) {
var base;
base = (typeof b !== "undefined") ? new WebSocket(a,b) : new WebSocket(a);
captureRecv(base);
base.send = captureSend;
this.__proto__ = WebSocket.constructor;
return base;
}
}
});
Run Code Online (Sandbox Code Playgroud)
如果domainA.com 被泄露,您就完蛋了。注入的脚本只需添加另一个窗口“消息”事件处理程序,并且由于它位于同一源,因此它开始接收domainB postMessage 的所有内容,并且能够将postMessage 返回到domainB。
不仅如此,他们还可以使用 JS 来查找 iframe,删除任何沙箱标签,允许将其视为同一源,访问其内容,然后开始在该源上执行任意 JS。它甚至可以修补方法,以便注入的脚本接收所有内容,而合法代码则不会。
然而,如果他们只能注入到domainB,并且iframe被正确沙箱化,他们就无法改变domainA所做的任何事情。不过,这仍然足以让他们看到 postMessage() 发送和接收的所有内容。
最好的办法可能是让“secureDomain.com”在沙盒 iframe 中包含这两个脚本,然后它们相互通信。假设 secureDomain.com 无法被注入,那么至少注入只会影响单个域,并且不允许访问两个域。
| 归档时间: |
|
| 查看次数: |
475 次 |
| 最近记录: |