如何在Spring Cloud Gateway级别上应用XSS过滤器

时间:2019-05-28 19:47:19

标签: spring-boot microservices xss spring-cloud-gateway

有关如何在Spring Cloud Gateway级别上实现XSS过滤器的任何帮助。

我已经成功实现了CORS过滤器,但是显然,基于webflux的网关使其变得更加困难

下面的代码段显示了成功的过滤器

@Bean
public WebFilter corsFilter() {

    return (ServerWebExchange ctx, WebFilterChain chain) -> {

        ServerHttpRequest request = ctx.getRequest();

        if (CorsUtils.isCorsRequest(request)) {
            ServerHttpResponse response = ctx.getResponse();
            HttpHeaders headers = response.getHeaders();
            headers.add("Access-Control-Allow-Origin", ALLOWED_ORIGIN);
            headers.add("Access-Control-Allow-Methods", ALLOWED_METHODS);
            headers.add("Access-Control-Max-Age", MAX_AGE);
            headers.add("Access-Control-Allow-Headers", ALLOWED_HEADERS);
            if (request.getMethod() == HttpMethod.OPTIONS) {
                response.setStatusCode(HttpStatus.OK);
                return Mono.empty();
            }
        }

        return chain.filter(ctx);
    };
}

0 个答案:

没有答案