zoukankan      html  css  js  c++  java
  • 关于防止 iframe 嵌套

    网页被他人嵌套,可能会引发一些问题:

    大量的403/404 访问问题,

    可能会被木马网站劫持,

    地址无法与内容对应。

    面对这样的情况,处理的方法有以下几种

    1、在haed中设置mata属性

    <meta http-equiv="X-Frame-Options" content="SAMEORIGIN">
    或者更详细:
    
    <meta http-equiv="X-Frame-Options" content="SAMEORIGIN / DENY "> 
    
    指定具体网站:
    <meta http-equiv="X-Frame-Options" content="ALLOW-FROM http://xxx.xxx.com">

    2、使用JS代码控制

    if (top.location != self.location){
        alert("本页面被其他网站嵌套");
        // 具体操作....
        top.location=self.location
    }
    
    或者: (function(window,document){ if(top != window){ top.location = location.href; } document.uniqueID != document.uniqueID && !!location.hash && (location.hash = location.hash); window.focus(); })(this,document);

    3、服务器中设置拦截

    配置 Apache 在所有页面上发送 X-Frame-Options 响应头,需要把下面这行添加到 'site' 的配置中:

    Header always append X-Frame-Options SAMEORIGIN

    配置 nginx 发送 X-Frame-Options 响应头,把下面这行添加到 'http', 'server' 或者 'location' 的配置中:

    add_header X-Frame-Options SAMEORIGIN

    配置 IIS 发送 X-Frame-Options 响应头,添加下面的配置到 Web.config 文件中:

    <system.webServer>
      ...
     
      <httpProtocol>
        <customHeaders>
          <add name="X-Frame-Options" value="SAMEORIGIN" />
        </customHeaders>
      </httpProtocol>
     
      ...
    </system.webServer>

    在web.xml文件下添加以下内容:

    <!-- 设置Frame头,防止被嵌套 --> 
    <filter>
     <filter-name>FrameFilter</filter-name> 
    <filter-class>filter.FrameTao</filter-class>
     </filter> 
    <filter-mapping>
     <filter-name>FrameFilter</filter-name>
     <url-pattern>/*</url-pattern> 
    </filter-mapping>
  • 相关阅读:
    Android--adb
    Android 爬坑之路
    Android倒计时实现
    Android Studio常用设置
    Java Web开发——MySQL数据库的安装与配置
    DOS命令(系统错误5,拒绝访问)的解决方法
    Java EE开发环境——MyEclipse2017破解 和 Tomcat服务器配置
    设计模式-工厂模式
    设计模式-简单工厂模式
    设计模式简介
  • 原文地址:https://www.cnblogs.com/LiangPF/p/14435929.html
Copyright © 2011-2022 走看看