tokens= request.getQueryParams();
+ token = request.getHeaders().getFirst(TokenConstants.TOKEN_HEAD);
+ if(tokens.get(hed)!=null && !tokens.get(hed).isEmpty()){
+ token =tokens.get("token").get(0);
+ if(nl.equals(token)){
+ token=null;
+ }
+ }
+ }
return token;
}
diff --git a/gateway/src/main/java/com/bonus/gateway/xss/CacheBodyGlobalFilter.java b/gateway/src/main/java/com/bonus/gateway/xss/CacheBodyGlobalFilter.java
new file mode 100644
index 0000000..89c48ea
--- /dev/null
+++ b/gateway/src/main/java/com/bonus/gateway/xss/CacheBodyGlobalFilter.java
@@ -0,0 +1,61 @@
+package com.bonus.gateway.xss;
+
+
+import org.springframework.cloud.gateway.filter.GatewayFilterChain;
+import org.springframework.cloud.gateway.filter.GlobalFilter;
+import org.springframework.core.Ordered;
+import org.springframework.core.io.buffer.DataBuffer;
+import org.springframework.core.io.buffer.DataBufferUtils;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.MediaType;
+import org.springframework.http.server.reactive.ServerHttpRequest;
+import org.springframework.http.server.reactive.ServerHttpRequestDecorator;
+import org.springframework.stereotype.Component;
+import org.springframework.web.server.ServerWebExchange;
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+
+/**
+ * @Author:
+ * @Description: 这个过滤器解决body不能重复读的问题,为后续的XssRequestGlobalFilter重写post|put请求的body做准备
+ * @Date:
+ *
+ * 没把body的内容放到attribute中去,因为从attribute取出body内容还是需要强转成 Flux,然后转换成String,和直接读取body没有什么区别
+ */
+@Component
+public class CacheBodyGlobalFilter implements Ordered, GlobalFilter {
+ @Override
+ public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) {
+ HttpMethod method = exchange.getRequest().getMethod();
+ String contentType = exchange.getRequest().getHeaders().getFirst(HttpHeaders.CONTENT_TYPE);
+ if (method == HttpMethod.POST || method == HttpMethod.PUT) {
+ if (MediaType.APPLICATION_FORM_URLENCODED_VALUE.equalsIgnoreCase(contentType)
+ || MediaType.APPLICATION_JSON_VALUE.equalsIgnoreCase(contentType)
+ || MediaType.APPLICATION_JSON_UTF8_VALUE.equals(contentType)) {
+ return DataBufferUtils.join(exchange.getRequest().getBody())
+ .flatMap(dataBuffer -> {
+ DataBufferUtils.retain(dataBuffer);
+ Flux cachedFlux = Flux
+ .defer(() -> Flux.just(dataBuffer.slice(0, dataBuffer.readableByteCount())));
+ ServerHttpRequest mutatedRequest = new ServerHttpRequestDecorator(
+ exchange.getRequest()) {
+ @Override
+ public Flux getBody() {
+ return cachedFlux;
+ }
+ };
+ return chain.filter(exchange.mutate().request(mutatedRequest).build());
+ });
+ }
+
+ }
+ return chain.filter(exchange);
+ }
+
+ @Override
+ public int getOrder() {
+ return Ordered.HIGHEST_PRECEDENCE;
+ }
+}
+
diff --git a/gateway/src/main/java/com/bonus/gateway/xss/XssCleanRuleUtils.java b/gateway/src/main/java/com/bonus/gateway/xss/XssCleanRuleUtils.java
new file mode 100644
index 0000000..f785769
--- /dev/null
+++ b/gateway/src/main/java/com/bonus/gateway/xss/XssCleanRuleUtils.java
@@ -0,0 +1,124 @@
+package com.bonus.gateway.xss;
+
+
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
+import org.jsoup.safety.Whitelist;
+import org.springframework.core.io.ClassPathResource;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Iterator;
+import java.util.regex.Pattern;
+
+/**
+ * @Author:
+ * @Description: xss过滤工具
+ * @Date:
+ */
+public class XssCleanRuleUtils {
+
+ //xss过滤规则(对于script、src及加载事件和弹窗事件的代码块)
+ private final static Pattern[] scriptPatterns = {
+ Pattern.compile("", Pattern.CASE_INSENSITIVE),
+ Pattern.compile("src[\r\n]*=[\r\n]*\\\'(.*?)\\\'", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL),
+ Pattern.compile("", Pattern.CASE_INSENSITIVE),
+ Pattern.compile("