X-Frame-Options防止网页被Frame

防止被 FRAME 加载你的网站页面

1. meta 标签:很多时候没有效果,无视

<meta http-equiv="Windows-Target" contect="_top">

 

2. js 判断顶层窗口跳转,可轻易破解,意义不大

function locationTop(){
    if (top.location != self.location) {
        top.location = self.location;
        return false;       
    }
    return true;
}
locationTop();

破解:

// 顶层窗口中放入代码
var location = document.location;
// 或者 var location = "";

 

3. header 控制,绝大部分浏览器支持

 

使用 X-Frame-Options 有三个可选的值:

DENY:浏览器拒绝当前页面加载任何Frame页面

SAMEORIGIN:frame页面的地址只能为同源域名下的页面

ALLOW-FROM:允许frame加载的页面地址

PHP代码:

header('X-Frame-Options:Deny');

Nginx配置:

add_header X-Frame-Options SAMEORIGIN

Apache配置:

Header always append X-Frame-Options SAMEORIGIN

具体参见:https://developer.mozilla.org/en-US/docs/HTTP/X-Frame-Options?redirectlocale=en-US&redirectslug=The_X-FRAME-OPTIONS_response_header

posted @ 2014-06-12 09:48  i凉快  阅读(397)  评论(0编辑  收藏  举报