我正在创建一些IFrameable内容。我们希望用户能够IFrame此页面,但只能从域的集合列表。
有没有什么我们可以检查的,看看父页面的域名是什么?
if (top != self) { top.location.replace(self.location.href); }发布于 2009-12-03 11:03:07
否,如果父页面不在您的安全上下文(同源策略)中,则该页面的location不可见。你当然可以看看你自己的框架的document.referrer,但这不是完全防水的…在客户端上的引用检查比在服务器端的用处要小一些,但它仍然可以通过帧中的刷新转发器来规避。
Content Security Policy中的frame-ancestors限制有一天可能会允许这样做。
发布于 2009-12-03 12:42:44
正如博本斯所说,document.referrer看起来是你最好的选择。您可以在作为iFrame源的页面中检查这一点。但是,HTTP referer信息很容易被欺骗,因此这种方法不是很安全。
本文展示了如何使用PHP:How to bypass the REFERER security check
发布于 2015-05-16 03:31:43
我用它来检查页面是否是从白名单域加载的。我相信有办法解决这个问题,但它似乎是有效的。
var currentUrl = document.referrer;
var okayUrl = "http://good-domain.com";
var okayUrl2 = "http://another-good-domain.com";
//check if page is loaded in iframe
if ( window.location !== window.parent.location ) {
//check if parent is a whitelisted domain
if (currentUrl == okayUrl || currentUrl == okayUrl2)
{
//if it is a good domain, then just log the parent url or something
console.log(currentUrl);
} else {
//if it is a bad domain, then do something about it
alert ("Woah buddy. Can't touch this!");
window.location = "http://en.wikipedia.org/wiki/Rickrolling";
}
}https://stackoverflow.com/questions/1837121
复制相似问题