AppScan扫描启用了不安全的“OPTIONS”HTTP 方法

**服务器禁止不需要的 HTTP 方法## **
目前项目进行交付时,测试方给到一个安全检测报告。其中有一个问题是:启用了不安全的“OPTIONS”HTTP 方法。给到的建议是禁用 WebDAV,或者禁止不需要的 HTTP 方法。由于测试服务器是Tomcat,而线上服务器为websphere,在网上找了许多资源,始终都是Tomcat的解决办法。现在记录一下websphere解决问题思路,给使用websphere的同学们提供一个参考。
首先是Tomcat的解决办法:
1.将web.xml协议改为

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
         version="2.4">

2.在web.xml中加入以下代码

 <security-constraint>
        <web-resource-collection>
            <url-pattern>/*</url-pattern>
            <http-method>PUT</http-method>
            <http-method>DELETE</http-method>
             <http-method>HEAD</http-method>
            <http-method>OPTIONS</http-method>
            <http-method>TRACE</http-method>
        </web-resource-collection>
        <auth-constraint></auth-constraint>
    </security-constraint>
    <login-config>
        <auth-method>BASIC</auth-method>
    </login-config>

重启服务器,postman用OPTIONS请求发现allow中已经没有上述代码中的请求方法。
tips:踩坑过程中,我只加入了第二步中的代码,亲测有效。

然后是websphere的解决办法:
解决思路是利用过滤器将我们不需要的,也就是检测出来不安全的请求方法过滤掉
1.创建一个自定义过滤器

package com.dxl.project.filter;

import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class MethodsFilter extends OncePerRequestFilter {
    @Override
    protected void doFilterInternal(
            HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
            throws ServletException, IOException {

        if ("GET".equals(request.getMethod())||"POST".equals(request.getMethod())) {
            filterChain.doFilter(request, response);
        }
    }
}

2.在web.xml中配置过滤器,我将这个过滤器放在了所有过滤器的最上面

<!-- http请求方法过滤器 -->
    <filter>
        <filter-name>methodsFilter</filter-name>
        <filter-class>com.dxl.project.filter.MethodsFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>methodsFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

重启服务器,postman用OPTIONS请求,发现Headers中并无allow。
在查找资料的过程中我发现有用weblogic的小伙伴也有遇到相同的问题,或许能提供一种思路。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值