| | |
| | | |
| | | import java.nio.charset.StandardCharsets; |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.terra.gateway.utils.StringUtils; |
| | | import com.terra.gateway.utils.html.EscapeUtil; |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| | | import org.springframework.cloud.gateway.filter.GatewayFilterChain; |
| | | import org.springframework.cloud.gateway.filter.GlobalFilter; |
| | |
| | | } |
| | | // excludeUrls 不过滤 |
| | | String url = request.getURI().getPath(); |
| | | // if (StringUtils.matches(url, xss.getExcludeUrls())) |
| | | // { |
| | | // return chain.filter(exchange); |
| | | // } |
| | | if (StringUtils.matches(url, xss.getExcludeUrls())) |
| | | { |
| | | return chain.filter(exchange); |
| | | } |
| | | ServerHttpRequestDecorator httpRequestDecorator = requestDecorator(exchange); |
| | | return chain.filter(exchange.mutate().request(httpRequestDecorator).build()); |
| | | |
| | |
| | | DataBufferUtils.release(join); |
| | | String bodyStr = new String(content, StandardCharsets.UTF_8); |
| | | // 防xss攻击过滤 |
| | | //bodyStr = EscapeUtil.clean(bodyStr); |
| | | bodyStr = EscapeUtil.clean(bodyStr); |
| | | // 转成字节 |
| | | byte[] bytes = bodyStr.getBytes(StandardCharsets.UTF_8); |
| | | NettyDataBufferFactory nettyDataBufferFactory = new NettyDataBufferFactory(ByteBufAllocator.DEFAULT); |
| | |
| | | public boolean isJsonRequest(ServerWebExchange exchange) |
| | | { |
| | | String header = exchange.getRequest().getHeaders().getFirst(HttpHeaders.CONTENT_TYPE); |
| | | //return StringUtils.startsWithIgnoreCase(header, MediaType.APPLICATION_JSON_VALUE); |
| | | return true; |
| | | return StringUtils.startsWithIgnoreCase(header, MediaType.APPLICATION_JSON_VALUE); |
| | | } |
| | | |
| | | @Override |