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>
  • 相关阅读:
    负margin的原理及应用
    css display:flex 属性
    MapReduce api实战
    配置YARN高可用
    Yarn 分布式资源调度
    MapReduce 案例与概述
    HDFS 伪分布式集群搭建
    Hadoop的HA高可用实验
    Hadoop HDFS 集群的分布式搭建
    Zookeeper分布式协调服务
  • 原文地址:https://www.cnblogs.com/LiangPF/p/14435929.html
Copyright © 2011-2022 走看看