【问题标题】:Spring WebFlux block Http.CONNECT methodSpring WebFlux 块 Http.CONNECT 方法
【发布时间】:2019-06-12 20:16:55
【问题描述】:

我们在公司周围进行了一些安全测试,其中应用程序以不同的方式进行测试。其中之一是尝试像这样的 CONNECT:

telnet localhost 8080
CONNECT http://test.com HTTP/1.1

在这种情况下返回400405。现有的 Spring MVC 应用程序返回一个400,但似乎我们的新 Spring WebFlux:5.1.2.RELEASE 应用程序(Netty 服务器)返回一个200

我做的第一件事是切换到最新的spring WebFlux版本:5.1.4.RELEASE,在这种情况下响应http错误代码是:404,但仍然不够好。所以我尝试:

  1. 创建一个网络过滤器
  2. 修改 CORS 过滤器
  3. 修改 Spring Security 链

,但所有这些解决方案都失败了。你是怎么解决的?创建自定义 http 处理程序是个好主意?

【问题讨论】:

    标签: java spring-boot spring-security netty spring-webflux


    【解决方案1】:

    我创建了一个自定义 http 处理程序:

    public class AppContextPathCompositeHandler extends ContextPathCompositeHandler {
    
    public AppContextPathCompositeHandler(Map<String, ? extends HttpHandler> handlerMap) {
        super(handlerMap);
    }
    
    @Override
    public Mono<Void> handle(ServerHttpRequest request, ServerHttpResponse response) {
        if (HttpMethod.CONNECT.name().equals(request.getMethodValue())) {
            response.setStatusCode(HttpStatus.METHOD_NOT_ALLOWED);
            return response.setComplete();
        }
    
        return super.handle(request, response);
    }
    }
    

    它的配置如下:

    @Configuration
    public class NettyReactiveWebServerConfig extends NettyReactiveWebServerFactory {
    @Value("${server.context-path}")
    private String contextPath;
    
    @Override
    public WebServer getWebServer(HttpHandler httpHandler) {
        Map<String, HttpHandler> handlerMap = new HashMap<>();
        handlerMap.put(contextPath, httpHandler);
        return super.getWebServer(new AppContextPathCompositeHandler(handlerMap));
    }
    }
    

    【讨论】:

      猜你喜欢
      • 2020-06-20
      • 2021-12-18
      • 2018-05-09
      • 2020-03-20
      • 1970-01-01
      • 1970-01-01
      • 2019-08-31
      • 2020-05-18
      • 2020-03-15
      相关资源
      最近更新 更多