假设您不希望其他网站在以下位置"构建"您的网站<iframe>
:
<iframe src="http://example.org"></iframe>
Run Code Online (Sandbox Code Playgroud)
因此,您将反框架,帧破坏JavaScript插入到您的所有页面中:
/* break us out of any containing iframes */
if (top != self) { top.location.replace(self.location.href); }
Run Code Online (Sandbox Code Playgroud)
优秀!现在你自动"破解"或突破任何包含iframe.除了一个小问题.
事实证明,您的帧破坏代码可能被破坏,如下所示:
<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>
Run Code Online (Sandbox Code Playgroud)
此代码执行以下操作:
window.onbeforeunload
事件处理程序离开当前页面时,都会递增计数器setInterval()
如果它看到计数器递增,则将当前位置更改为攻击者控制的服务器我的问题是 - 这更像是一个JavaScript拼图,而不是一个实际的问题 - 你怎么能打败破坏框架的破坏者呢?
我有一些想法,但在我的测试中没有任何效果:
onbeforeunload
事件onbeforeunload = null …
许多站点都有类似下面的脚本.这些都是为了阻止其他人构建网站.
if (top.location != location) {
top.location.href = document.location.href;
}
Run Code Online (Sandbox Code Playgroud)
我需要一些方法来实现iframe尝试重定向,如果是,我将删除iFrame,而是放置一个链接到该网站.这样,我不违反框架网站的使用政策,也链接到该网站.我知道你可以使用这里和这里讨论过的onbeforeunload事件,但两者看起来都是不道德的.我记得在某个地方读过一个完全相同的东西(digg做同样的事情).任何线索?
我有一个带有标准 iframe 标记的页面
框架内链接到 Https URL iframe 进行一些处理(付款信息等)
然后returns back a POST data
当处理失败大部分时间不重新加载父页面(Return url, plus POST data to that URL, loads inside Iframe
),当处理支付返回成功时,大部分时间它完全重新加载父页面(Returns url, plus POST data to the Successful URL, Reloads parent to that URL
)
由于这是来自安全支付的代码,因此我无法展示很多东西。
是否有任何 javascript 或 Html attr 可以使这个没有 randomness