clickjacking:X-frame-options header missing 漏洞解决办法

  1. Apache配置X-Frame-Options   ,httpd.conf 添加Header always append X-Frame-Options SAMEORIGIN

2.在项目里添加过滤器;

/**
 *  Software published by the Open Web Application Security Project (http://www.owasp.org)
 *  This software is licensed under the new BSD license.
 *
 * @author     Jeff Williams <a href="http://www.aspectsecurity.com">Aspect Security</a>
 * @created    February 6, 2009
 */

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;

public class ClickjackFilter implements Filter
{

private String mode = "DENY";
    
    /**
     * Add X-FRAME-OPTIONS response header to tell IE8 (and any other browsers who
     * decide to implement) not to display this content in a frame. For details, please
     * refer to http://blogs.msdn.com/sdl/archive/2009/02/05/clickjacking-defense-in-ie8.aspx.
     */
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
    {
        HttpServletResponse res = (HttpServletResponse)response;
        chain.doFilter(request, response);
        System.out.println("限制mode============"+mode);
        res.addHeader("X-FRAME-OPTIONS",mode );            
    }

public void destroy() {
    }

public void init(FilterConfig filterConfig) {
         System.out.println("限制mode   init============"+mode);
        String configMode = filterConfig.getInitParameter("mode");
        if ( configMode != null ) {
            mode = configMode;
        }
    }
    
}

<filter>
        <filter-name>ClickjackFilterDeny</filter-name>
        <filter-class>cn.aresoft.web.servlet.ClickjackFilter</filter-class>
        <init-param>
            <param-name>mode</param-name>
            <param-value>SAMEORIGIN</param-value>
        </init-param>
    </filter>

<filter>
        <filter-name>ClickjackFilterSameOrigin</filter-name>
        <filter-class>cn.aresoft.web.servlet.ClickjackFilter</filter-class>
        <init-param>
            <param-name>mode</param-name>
            <param-value>DENY</param-value>
        </init-param>
    </filter>

<!--  use the Deny version to prevent anyone, including yourself, from framing the page -->
    <filter-mapping>
        <filter-name>ClickjackFilterDeny</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

<!-- use the SameOrigin version to allow your application to frame, but nobody else
    <filter-mapping>
        <filter-name>ClickjackFilterSameOrigin</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

时间: 2024-08-26 00:18:50

clickjacking:X-frame-options header missing 漏洞解决办法的相关文章

JAVA反序列化漏洞解决办法

一.漏洞描述: 近期,反序列化任意代码执行漏洞持续发酵,越来越多的系统被爆出存在此漏洞.Apache Commons工具集广泛应用于JAVA技术平台,存在Apache Commons Components InvokerTransformer反序列化任意代码执行漏洞, WebLogic.IBM WebSphere.JBoss.Jenkins和OpenNMS等应用都大量调用了Commons工具集,通过远程代码执行可对上述应用发起远程攻击. 二.漏洞解决办法: 1 使用 SerialKiller 替

通过ajax访问Tomcat服务器web service接口时出现No &#39;Access-Control-Allow-Origin&#39; header问题的解决办法

问题描述 通过ajax访问Web服务器(Tomcat7.0.42)中的json web service接口的时候,报以下跨域问题: XMLHttpRequest cannot load http://localhost:8080/get-employees-by-name/name/admin. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhos

Zend Guard Run-time support missing!的解决办法

问题:安装新版本wordlpress的时候遇到如下问题, Zend Guard Run-time support missing! One more more files on this web site were encoded by ZendGuard and the required run-time support is not installed orproperly configured.For the Web site user This means that this Web s

apache2.2.15漏洞解决办法

1.服务器扫面 ■ HTTP TRACE Method Enabled 说明: Apache服务器启用了TRACE Method. 1.TRACE_Method是HTTP(超文本传输)协议定义的一种协议调试方法,该方法会使服务器原样返回任意客户端请求的任何内容. 2. 由于该方法会原样返回客户端提交的任意数据,因此可以用来进行跨站脚本简称XSS攻击,这种攻击方式又称为跨站跟踪攻击简称XST. 危害: 1. 恶意攻击者可以通过TRACE Method返回的信息了解到网站前端的一些信息,如缓存服务器

Slow HTTP Denial of Service Attack 漏洞解决办法

问题名称: Slow HTTP Denial of Service Attack 问题URL http://10.238.*.*:58*** 风险等级: 高 问题类型: 服务器配置类 漏洞描述: 利用的HTTP POST:POST的时候,指定一个非常大的 content-length,然后以很低的速度发包,比如10-100s发一个字节,hold住这个连接不断开.这样当客户端连接多了后,占用住了webserver的所有可用连接,从而导致DOS. 解决方案: 对web服务器的http头部传输的最大许

X-Scan扫描端口80,443提示http TRACE 跨站攻击漏洞解决办法

在用X-Scan-v3.3扫描主机端口提示http TRACE 跨站攻击漏洞; 一,修改配置文件httpd.conf 1.1 apache下面修改httpd.conf文件,在文件最后面新建一行加入:TraceEnable off 1.2 service httpd restart #重启apache服务器 二,如果没有修改配置文件权限的时候,我们可以在.htaccess文件中加入如下内容: 2.1 RewriteEngine onRewriteCond %{REQUEST_METHOD} ^(T

“Execution failed for task ‘:app:compileDebugAidl&#39;: aidl is missing”解决办法

转载: “Execution failed for task ‘:app:compileDebugAidl': aidl is missing”解决办法 今天重建android studio编程环境,老编译不过,提示:Execution failed for task ‘:app:compileDebugAidl': aidl is missing,在网上查了不少资料,终于在一个国外网站找到了解决办法: In my case I downloaded version 22 of Android

header头设置解决 “已拦截跨源请求:同源策略禁止读取位于 http://47.104.128.87/back/test/test 的远程资源。(原因:CORS 头缺少 &#39;Access-Control-Allow-Origin&#39;)。”

跨域请求错误提示如下图: 解决方法在请求的php页面添加header头: 代码如下: public function test() { //支持全域名访问,不安全,部署后需要固定限制为客户端网址 header('Access-Control-Allow-Origin:*'); //支持的http 动作 header('Access-Control-Allow-Methods:POST,GET,OPTIONS,DELETE'); //响应头 请按照自己需求添加. header('Access-Co

调用gitlab API提示{&quot;error&quot;:&quot;ref is missing, ref is empty&quot;},解决办法

问题复现 官方给的写法,以创建远程分支举例 curl --request POST --header "PRIVATE-TOKEN: ${私钥}" ${gitlab地址}/api/v4/projects/${目录名}%2F${仓库名}/repository/branches?branch=${新分支名}&ref=${来源分支} 返回错误信息 {"error":"ref is missing, ref is empty"} 我尝试交换ref