假设您不希望其他网站在 <iframe>
中“框定”您的网站:
<iframe src="http://example.org"></iframe>
因此,您将反框架、框架破坏 JavaScript 插入到所有页面中:
/* break us out of any containing iframes */
if (top != self) { top.location.replace(self.location.href); }
太棒了!现在,您会自动“破坏”或突破任何包含 iframe 的内容。除了一个小问题。
事实证明,你的框架破坏代码可能会被破坏,as shown here :
<script type="text/javascript">
var prevent_bust = 0
window.onbeforeunload = function() { prevent_bust++ }
setInterval(function() {
if (prevent_bust > 0) {
prevent_bust -= 2
window.top.location = 'http://example.org/page-which-responds-with-204'
}
}, 1)
</script>
此代码执行以下操作:
- 每次浏览器尝试通过
window.onbeforeunload
导航离开当前页面时,计数器都会递增。事件处理程序 - 通过
setInterval()
设置每毫秒触发一次的计时器,如果它看到计数器增加,则将当前位置更改为攻击者控制的服务器 - 该服务器提供带有 HTTP 状态代码 204 的页面,这不会导致浏览器在任何地方导航
我的问题是——这更像是一个 JavaScript 谜题,而不是一个实际的问题——你如何才能打败破坏框架的破坏者?
我有一些想法,但在我的测试中没有任何效果:
- 正在尝试清除
onbeforeunload
事件来自onbeforeunload = null
没有效果 - 添加
alert()
停止进程让用户知道它正在发生,但不会以任何方式干扰代码;点击确定让破坏继续正常进行 - 我想不出任何办法来清除
setInterval()
计时器
我不是一个 JavaScript 程序员,所以这是我对你的挑战:嘿,破坏者,你能破坏框架破坏破坏者吗?
最佳答案
FWIW,最新的浏览器 support X-Frame-Options: deny指令,即使在脚本被禁用时也有效。
IE8:
http://blogs.msdn.com/ie/archive/2009/01/27/ie8-security-part-vii-clickjacking-defenses.aspx
火狐 (3.6.9)
https://bugzilla.mozilla.org/show_bug.cgi?id=475530
https://developer.mozilla.org/en/The_X-FRAME-OPTIONS_response_header
Chrome/Webkit
http://blog.chromium.org/2010/01/security-in-depth-new-security-features.html
http://trac.webkit.org/changeset/42333
关于javascript - Frame Buster Buster ...需要破坏者代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/958997/