|
|
@@ -11,6 +11,7 @@ import org.springframework.core.io.buffer.DataBufferUtils;
|
|
11
|
11
|
import org.springframework.core.io.buffer.NettyDataBufferFactory;
|
|
12
|
12
|
import org.springframework.http.HttpHeaders;
|
|
13
|
13
|
import org.springframework.http.HttpMethod;
|
|
|
14
|
+import org.springframework.http.MediaType;
|
|
14
|
15
|
import org.springframework.http.server.reactive.ServerHttpRequest;
|
|
15
|
16
|
import org.springframework.http.server.reactive.ServerHttpRequestDecorator;
|
|
16
|
17
|
import org.springframework.stereotype.Component;
|
|
|
@@ -45,6 +46,11 @@ public class XssFilter implements GlobalFilter, Ordered
|
|
45
|
46
|
{
|
|
46
|
47
|
return chain.filter(exchange);
|
|
47
|
48
|
}
|
|
|
49
|
+ // 非json类型,不过滤
|
|
|
50
|
+ if (!isJsonRequest(exchange))
|
|
|
51
|
+ {
|
|
|
52
|
+ return chain.filter(exchange);
|
|
|
53
|
+ }
|
|
48
|
54
|
// excludeUrls 不过滤
|
|
49
|
55
|
String url = request.getURI().getPath();
|
|
50
|
56
|
if (StringUtils.matches(url, xss.getExcludeUrls()))
|
|
|
@@ -95,6 +101,17 @@ public class XssFilter implements GlobalFilter, Ordered
|
|
95
|
101
|
return serverHttpRequestDecorator;
|
|
96
|
102
|
}
|
|
97
|
103
|
|
|
|
104
|
+ /**
|
|
|
105
|
+ * 是否是Json请求
|
|
|
106
|
+ *
|
|
|
107
|
+ * @param request
|
|
|
108
|
+ */
|
|
|
109
|
+ public boolean isJsonRequest(ServerWebExchange exchange)
|
|
|
110
|
+ {
|
|
|
111
|
+ String header = exchange.getRequest().getHeaders().getFirst(HttpHeaders.CONTENT_TYPE);
|
|
|
112
|
+ return StringUtils.startsWithIgnoreCase(header, MediaType.APPLICATION_JSON_VALUE);
|
|
|
113
|
+ }
|
|
|
114
|
+
|
|
98
|
115
|
@Override
|
|
99
|
116
|
public int getOrder()
|
|
100
|
117
|
{
|