假设您不希望其他网站在以下位置"构建"您的网站<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 …
我有一个基本的ASP.NET MVC 3应用程序.我有一个基本操作,如下所示:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult AddItem(string id, string name, string description, string username)
{
// Do stuff
return Json(new { statusCode = 1 });
}
Run Code Online (Sandbox Code Playgroud)
我试图通过将在Phone Gap中托管的JQuery Mobile应用程序让某人访问此操作.有人告诉我,我需要Access-Control-Allow-Origin: *
在标题中返回.但是,我不知道如何在标题中返回它.有人可以告诉我该怎么做吗?
非常感谢.