You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@seata.apache.org by "YvCeung (via GitHub)" <gi...@apache.org> on 2025/06/29 06:56:46 UTC

[PR] feature: Add http request filter for seata-server [incubator-seata]

YvCeung opened a new pull request, #7485:
URL: https://github.com/apache/incubator-seata/pull/7485

   <!--
       Licensed to the Apache Software Foundation (ASF) under one or more
       contributor license agreements.  See the NOTICE file distributed with
       this work for additional information regarding copyright ownership.
       The ASF licenses this file to You under the Apache License, Version 2.0
       (the "License"); you may not use this file except in compliance with
       the License.  You may obtain a copy of the License at
   
       http://www.apache.org/licenses/LICENSE-2.0
       
       Unless required by applicable law or agreed to in writing, software
       distributed under the License is distributed on an "AS IS" BASIS,
       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       See the License for the specific language governing permissions and
       limitations under the License.
   -->
   <!-- Please make sure you have read and understood the contributing guidelines -->
   
   - [ ] I have registered the PR [changes](../changes).
   
   ### Ⅰ. Describe what this PR did
   
   
   1. Add filter logic for http requests from netty
   2. Not only does it support XSSFilter, but it also reserves expansion points to facilitate the easy integration of other types of filters in the future
   3. Add a new filter system configuration item to flexibly enable the on state of the relevant filters
   
   
   
     新增针对来自netty的http请求的过滤器逻辑
     不仅仅是支持了XSSFilter,同时预留了扩展点,以便未来轻松接入其他类型的过滤器
     新增过滤器系统配置项,以便灵活启用相关过滤器的开启状态
   
   ### Ⅱ. Does this pull request fix one issue?
   <!-- If that, add "fixes #xxx" below in the next line, for example, fixes #97. -->
   fix #7409 
   
   ### Ⅲ. Why don't you add test cases (unit test/integration test)? 
   
   
   ### Ⅳ. Describe how to verify it
   mvn clean test
   
   ### Ⅴ. Special notes for reviews
   1. Support the parsing logic for filtering four types of parameters: Query, Form, JSON, and Header: The original Seata Server only supported the POST parameter of the form type and did not support the request Body of the JSON type. This modification supplemented the parsing capability of the JSON Body parameter and enhanced the compatibility of the filter for multi-format request bodies to adapt to the parsing of the JSON type request body by the future SeATA-Server
   
   3. Support the execution of filters in a custom order
   4. Execution link
   ![image](https://github.com/user-attachments/assets/e4d27799-07ef-41de-bc9f-4b66cc5a3366)
   
   支持过滤 Query、Form、JSON、Header 四类参数的解析逻辑:原 Seata Server 仅支持表单类型 POST 参数,不支持 JSON 类型请求体,本次改动补充 JSON Body 参数解析能力,增强过滤器对多格式请求体的兼容性以适应未来seata-server对JSON类型请求体的解析
   
   支持 filter 按照自定义顺序执行
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] feature: Add http request filter for seata-server [incubator-seata]

Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on code in PR #7485:
URL: https://github.com/apache/incubator-seata/pull/7485#discussion_r2194187943


##########
core/src/main/java/org/apache/seata/core/rpc/netty/http/filter/impl/XSSHttpRequestFilter.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.seata.core.rpc.netty.http.filter.impl;
+
+import org.apache.seata.config.ConfigurationFactory;
+import org.apache.seata.config.ConfigurationKeys;
+import org.apache.seata.core.exception.HttpRequestFilterException;
+import org.apache.seata.core.rpc.netty.http.filter.HttpFilterContext;
+import org.apache.seata.core.rpc.netty.http.filter.HttpRequestFilter;
+
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Filter to detect and block potential XSS attack vectors in HTTP request parameters.
+ */
+public class XSSHttpRequestFilter implements HttpRequestFilter {

Review Comment:
   > My idea is that the specific filters can be placed on the server side but not managed by the spring container. They can be obtained through spi in the core module. This way, the timing issue of FilterManager being called before the Spring environment is ready can also be avoided. @funky-eyes do you think?
   
   I think we should combine SPI and Spring like Dubbo does, where singletons in SPI are also managed by Spring simultaneously, and beans in Spring can also be loaded through SPI, with both being the same singleton. However, this is currently outside the scope of this PR. So I think using either SPI or Spring beans is fine.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] feature: Add http request filter for seata-server [incubator-seata]

Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on code in PR #7485:
URL: https://github.com/apache/incubator-seata/pull/7485#discussion_r2184488947


##########
core/src/main/java/org/apache/seata/core/rpc/netty/http/HttpDispatchHandler.java:
##########
@@ -21,19 +21,14 @@
 import io.netty.buffer.Unpooled;
 import io.netty.channel.ChannelFutureListener;
 import io.netty.channel.ChannelHandlerContext;
-import io.netty.handler.codec.http.DefaultFullHttpResponse;
-import io.netty.handler.codec.http.FullHttpResponse;
-import io.netty.handler.codec.http.HttpHeaderNames;
-import io.netty.handler.codec.http.HttpMethod;
-import io.netty.handler.codec.http.HttpRequest;
-import io.netty.handler.codec.http.HttpResponseStatus;
-import io.netty.handler.codec.http.HttpUtil;
-import io.netty.handler.codec.http.HttpVersion;
-import io.netty.handler.codec.http.QueryStringDecoder;
+import io.netty.handler.codec.http.*;

Review Comment:
   Wildcard imports are not allowed



##########
core/src/main/java/org/apache/seata/core/rpc/netty/http/filter/impl/XSSHttpRequestFilter.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.seata.core.rpc.netty.http.filter.impl;
+
+import org.apache.seata.config.ConfigurationFactory;
+import org.apache.seata.config.ConfigurationKeys;
+import org.apache.seata.core.exception.HttpRequestFilterException;
+import org.apache.seata.core.rpc.netty.http.filter.HttpFilterContext;
+import org.apache.seata.core.rpc.netty.http.filter.HttpRequestFilter;
+
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Filter to detect and block potential XSS attack vectors in HTTP request parameters.
+ */
+public class XSSHttpRequestFilter implements HttpRequestFilter {

Review Comment:
   Can this filter be placed on the server side, built as a Spring bean, and then injected into the FilterManager?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] feature: Add http request filter for seata-server [incubator-seata]

Posted by "YvCeung (via GitHub)" <gi...@apache.org>.
YvCeung commented on code in PR #7485:
URL: https://github.com/apache/incubator-seata/pull/7485#discussion_r2173635275


##########
core/src/main/java/org/apache/seata/core/rpc/netty/http/filter/HttpRequestParamWrapper.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.seata.core.rpc.netty.http.filter;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import io.netty.handler.codec.http.DefaultFullHttpRequest;
+import io.netty.handler.codec.http.FullHttpRequest;
+import io.netty.handler.codec.http.HttpHeaderNames;
+import io.netty.handler.codec.http.HttpRequest;
+import io.netty.handler.codec.http.QueryStringDecoder;
+import io.netty.handler.codec.http.multipart.Attribute;
+import io.netty.handler.codec.http.multipart.HttpPostRequestDecoder;
+import io.netty.handler.codec.http.multipart.InterfaceHttpData;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Wrapper for HTTP request parameters from multiple sources: query, form, header, JSON body.
+ */
+public class HttpRequestParamWrapper {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(HttpRequestParamWrapper.class);
+    private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+
+    private final Map<String, List<String>> queryParams = new HashMap<>();
+    private final Map<String, List<String>> formParams = new HashMap<>();
+    private final Map<String, List<String>> headerParams = new HashMap<>();
+    private final Map<String, List<String>> jsonParams = new HashMap<>();
+
+    public HttpRequestParamWrapper(HttpRequest httpRequest) {
+        if (!(httpRequest instanceof FullHttpRequest)) {
+            throw new IllegalArgumentException("HttpRequest must be FullHttpRequest to read body.");
+        }
+        FullHttpRequest fullRequest = (FullHttpRequest) httpRequest;
+        parseQueryParams(fullRequest);
+        parseHeaders(fullRequest);
+        parseBody(fullRequest);
+    }
+
+    private void parseQueryParams(FullHttpRequest request) {
+        QueryStringDecoder decoder = new QueryStringDecoder(request.uri());
+        queryParams.putAll(decoder.parameters());
+    }
+
+    private void parseHeaders(FullHttpRequest request) {
+        for (Map.Entry<String, String> entry : request.headers()) {
+            headerParams.computeIfAbsent(entry.getKey(), k -> new ArrayList<>()).add(entry.getValue());
+        }
+    }
+
+    private void parseBody(FullHttpRequest request) {
+        String contentType = request.headers().get(HttpHeaderNames.CONTENT_TYPE);
+        if (contentType == null) {
+            return;
+        }
+
+        ByteBuf originalContent = request.content();
+        ByteBuf copiedBuf = Unpooled.copiedBuffer(originalContent);
+
+        String bodyStr = copiedBuf.toString(StandardCharsets.UTF_8);
+
+        try {
+            if (contentType.contains("application/json")) {
+                parseJsonBody(bodyStr);
+            } else if (contentType.contains("application/x-www-form-urlencoded")
+                    || contentType.contains("multipart/form-data")) {
+                FullHttpRequest copiedRequest = new DefaultFullHttpRequest(
+                        request.protocolVersion(), request.method(), request.uri(), copiedBuf);

Review Comment:
   This is a false positive. The request.uri() here is only used to construct a new Netty FullHttpRequest for internal server request body parsing, not for making any outbound network calls.
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] feature: Add http request filter for seata-server [incubator-seata]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #7485:
URL: https://github.com/apache/incubator-seata/pull/7485#issuecomment-3018397976

   ## [Codecov](https://app.codecov.io/gh/apache/incubator-seata/pull/7485?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   Attention: Patch coverage is `69.64286%` with `51 lines` in your changes missing coverage. Please review.
   > Project coverage is 60.37%. Comparing base [(`01a839f`)](https://app.codecov.io/gh/apache/incubator-seata/commit/01a839f92b3533272d5297a9386e4c2eec1c4bcf?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`29eba88`)](https://app.codecov.io/gh/apache/incubator-seata/commit/29eba882b8be693ed084d617fff72d35fbe5e658?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/incubator-seata/pull/7485?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [...a/org/apache/seata/common/util/HttpClientUtil.java](https://app.codecov.io/gh/apache/incubator-seata/pull/7485?src=pr&el=tree&filepath=common%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fcommon%2Futil%2FHttpClientUtil.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Y29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zZWF0YS9jb21tb24vdXRpbC9IdHRwQ2xpZW50VXRpbC5qYXZh) | 0.00% | [13 Missing :warning: ](https://app.codecov.io/gh/apache/incubator-seata/pull/7485?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...rpc/netty/http/filter/HttpRequestParamWrapper.java](https://app.codecov.io/gh/apache/incubator-seata/pull/7485?src=pr&el=tree&filepath=core%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fcore%2Frpc%2Fnetty%2Fhttp%2Ffilter%2FHttpRequestParamWrapper.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Y29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2VhdGEvY29yZS9ycGMvbmV0dHkvaHR0cC9maWx0ZXIvSHR0cFJlcXVlc3RQYXJhbVdyYXBwZXIuamF2YQ==) | 81.69% | [8 Missing and 5 partials :warning: ](https://app.codecov.io/gh/apache/incubator-seata/pull/7485?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...c/netty/http/filter/impl/XSSHttpRequestFilter.java](https://app.codecov.io/gh/apache/incubator-seata/pull/7485?src=pr&el=tree&filepath=core%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fcore%2Frpc%2Fnetty%2Fhttp%2Ffilter%2Fimpl%2FXSSHttpRequestFilter.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Y29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2VhdGEvY29yZS9ycGMvbmV0dHkvaHR0cC9maWx0ZXIvaW1wbC9YU1NIdHRwUmVxdWVzdEZpbHRlci5qYXZh) | 76.00% | [3 Missing and 3 partials :warning: ](https://app.codecov.io/gh/apache/incubator-seata/pull/7485?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...seata/core/rpc/netty/http/HttpDispatchHandler.java](https://app.codecov.io/gh/apache/incubator-seata/pull/7485?src=pr&el=tree&filepath=core%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fcore%2Frpc%2Fnetty%2Fhttp%2FHttpDispatchHandler.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Y29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2VhdGEvY29yZS9ycGMvbmV0dHkvaHR0cC9IdHRwRGlzcGF0Y2hIYW5kbGVyLmphdmE=) | 63.63% | [4 Missing :warning: ](https://app.codecov.io/gh/apache/incubator-seata/pull/7485?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [.../core/rpc/netty/http/filter/HttpFilterContext.java](https://app.codecov.io/gh/apache/incubator-seata/pull/7485?src=pr&el=tree&filepath=core%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fcore%2Frpc%2Fnetty%2Fhttp%2Ffilter%2FHttpFilterContext.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Y29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2VhdGEvY29yZS9ycGMvbmV0dHkvaHR0cC9maWx0ZXIvSHR0cEZpbHRlckNvbnRleHQuamF2YQ==) | 70.00% | [1 Missing and 2 partials :warning: ](https://app.codecov.io/gh/apache/incubator-seata/pull/7485?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...pc/netty/http/filter/HttpRequestFilterManager.java](https://app.codecov.io/gh/apache/incubator-seata/pull/7485?src=pr&el=tree&filepath=core%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fcore%2Frpc%2Fnetty%2Fhttp%2Ffilter%2FHttpRequestFilterManager.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Y29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2VhdGEvY29yZS9ycGMvbmV0dHkvaHR0cC9maWx0ZXIvSHR0cFJlcXVlc3RGaWx0ZXJNYW5hZ2VyLmphdmE=) | 75.00% | [1 Missing and 2 partials :warning: ](https://app.codecov.io/gh/apache/incubator-seata/pull/7485?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...ies/server/filter/ServerHttpFiltersProperties.java](https://app.codecov.io/gh/apache/incubator-seata/pull/7485?src=pr&el=tree&filepath=seata-spring-autoconfigure%2Fseata-spring-autoconfigure-server%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fspring%2Fboot%2Fautoconfigure%2Fproperties%2Fserver%2Ffilter%2FServerHttpFiltersProperties.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c2VhdGEtc3ByaW5nLWF1dG9jb25maWd1cmUvc2VhdGEtc3ByaW5nLWF1dG9jb25maWd1cmUtc2VydmVyL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zZWF0YS9zcHJpbmcvYm9vdC9hdXRvY29uZmlndXJlL3Byb3BlcnRpZXMvc2VydmVyL2ZpbHRlci9TZXJ2ZXJIdHRwRmlsdGVyc1Byb3BlcnRpZXMuamF2YQ==) | 40.00% | [3 Missing :warning: ](https://app.codecov.io/gh/apache/incubator-seata/pull/7485?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...s/server/filter/ServerHttpXSSFilterProperties.java](https://app.codecov.io/gh/apache/incubator-seata/pull/7485?src=pr&el=tree&filepath=seata-spring-autoconfigure%2Fseata-spring-autoconfigure-server%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fspring%2Fboot%2Fautoconfigure%2Fproperties%2Fserver%2Ffilter%2FServerHttpXSSFilterProperties.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c2VhdGEtc3ByaW5nLWF1dG9jb25maWd1cmUvc2VhdGEtc3ByaW5nLWF1dG9jb25maWd1cmUtc2VydmVyL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zZWF0YS9zcHJpbmcvYm9vdC9hdXRvY29uZmlndXJlL3Byb3BlcnRpZXMvc2VydmVyL2ZpbHRlci9TZXJ2ZXJIdHRwWFNTRmlsdGVyUHJvcGVydGllcy5qYXZh) | 40.00% | [3 Missing :warning: ](https://app.codecov.io/gh/apache/incubator-seata/pull/7485?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...ata/core/exception/HttpRequestFilterException.java](https://app.codecov.io/gh/apache/incubator-seata/pull/7485?src=pr&el=tree&filepath=core%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fcore%2Fexception%2FHttpRequestFilterException.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Y29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2VhdGEvY29yZS9leGNlcHRpb24vSHR0cFJlcXVlc3RGaWx0ZXJFeGNlcHRpb24uamF2YQ==) | 50.00% | [2 Missing :warning: ](https://app.codecov.io/gh/apache/incubator-seata/pull/7485?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [.../core/rpc/netty/http/filter/HttpRequestFilter.java](https://app.codecov.io/gh/apache/incubator-seata/pull/7485?src=pr&el=tree&filepath=core%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fcore%2Frpc%2Fnetty%2Fhttp%2Ffilter%2FHttpRequestFilter.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Y29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2VhdGEvY29yZS9ycGMvbmV0dHkvaHR0cC9maWx0ZXIvSHR0cFJlcXVlc3RGaWx0ZXIuamF2YQ==) | 0.00% | [1 Missing :warning: ](https://app.codecov.io/gh/apache/incubator-seata/pull/7485?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   ```diff
   @@             Coverage Diff              @@
   ##                2.x    #7485      +/-   ##
   ============================================
   + Coverage     60.34%   60.37%   +0.03%     
     Complexity      658      658              
   ============================================
     Files          1281     1290       +9     
     Lines         48308    48476     +168     
     Branches       5676     5696      +20     
   ============================================
   + Hits          29150    29268     +118     
   - Misses        16553    16589      +36     
   - Partials       2605     2619      +14     
   ```
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/incubator-seata/pull/7485?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [...ava/org/apache/seata/common/ConfigurationKeys.java](https://app.codecov.io/gh/apache/incubator-seata/pull/7485?src=pr&el=tree&filepath=common%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fcommon%2FConfigurationKeys.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Y29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zZWF0YS9jb21tb24vQ29uZmlndXJhdGlvbktleXMuamF2YQ==) | `0.00% <ø> (ø)` | |
   | [.../rpc/netty/http/filter/HttpRequestFilterChain.java](https://app.codecov.io/gh/apache/incubator-seata/pull/7485?src=pr&el=tree&filepath=core%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fcore%2Frpc%2Fnetty%2Fhttp%2Ffilter%2FHttpRequestFilterChain.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Y29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2VhdGEvY29yZS9ycGMvbmV0dHkvaHR0cC9maWx0ZXIvSHR0cFJlcXVlc3RGaWx0ZXJDaGFpbi5qYXZh) | `100.00% <100.00%> (ø)` | |
   | [...ta/spring/boot/autoconfigure/StarterConstants.java](https://app.codecov.io/gh/apache/incubator-seata/pull/7485?src=pr&el=tree&filepath=seata-spring-autoconfigure%2Fseata-spring-autoconfigure-core%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fspring%2Fboot%2Fautoconfigure%2FStarterConstants.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c2VhdGEtc3ByaW5nLWF1dG9jb25maWd1cmUvc2VhdGEtc3ByaW5nLWF1dG9jb25maWd1cmUtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2VhdGEvc3ByaW5nL2Jvb3QvYXV0b2NvbmZpZ3VyZS9TdGFydGVyQ29uc3RhbnRzLmphdmE=) | `100.00% <ø> (ø)` | |
   | [...configure/SeataServerEnvironmentPostProcessor.java](https://app.codecov.io/gh/apache/incubator-seata/pull/7485?src=pr&el=tree&filepath=seata-spring-autoconfigure%2Fseata-spring-autoconfigure-server%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fspring%2Fboot%2Fautoconfigure%2FSeataServerEnvironmentPostProcessor.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c2VhdGEtc3ByaW5nLWF1dG9jb25maWd1cmUvc2VhdGEtc3ByaW5nLWF1dG9jb25maWd1cmUtc2VydmVyL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zZWF0YS9zcHJpbmcvYm9vdC9hdXRvY29uZmlndXJlL1NlYXRhU2VydmVyRW52aXJvbm1lbnRQb3N0UHJvY2Vzc29yLmphdmE=) | `100.00% <100.00%> (ø)` | |
   | [.../core/rpc/netty/http/filter/HttpRequestFilter.java](https://app.codecov.io/gh/apache/incubator-seata/pull/7485?src=pr&el=tree&filepath=core%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fcore%2Frpc%2Fnetty%2Fhttp%2Ffilter%2FHttpRequestFilter.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Y29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2VhdGEvY29yZS9ycGMvbmV0dHkvaHR0cC9maWx0ZXIvSHR0cFJlcXVlc3RGaWx0ZXIuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...ata/core/exception/HttpRequestFilterException.java](https://app.codecov.io/gh/apache/incubator-seata/pull/7485?src=pr&el=tree&filepath=core%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fcore%2Fexception%2FHttpRequestFilterException.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Y29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2VhdGEvY29yZS9leGNlcHRpb24vSHR0cFJlcXVlc3RGaWx0ZXJFeGNlcHRpb24uamF2YQ==) | `50.00% <50.00%> (ø)` | |
   | [.../core/rpc/netty/http/filter/HttpFilterContext.java](https://app.codecov.io/gh/apache/incubator-seata/pull/7485?src=pr&el=tree&filepath=core%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fcore%2Frpc%2Fnetty%2Fhttp%2Ffilter%2FHttpFilterContext.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Y29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2VhdGEvY29yZS9ycGMvbmV0dHkvaHR0cC9maWx0ZXIvSHR0cEZpbHRlckNvbnRleHQuamF2YQ==) | `70.00% <70.00%> (ø)` | |
   | [...pc/netty/http/filter/HttpRequestFilterManager.java](https://app.codecov.io/gh/apache/incubator-seata/pull/7485?src=pr&el=tree&filepath=core%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fcore%2Frpc%2Fnetty%2Fhttp%2Ffilter%2FHttpRequestFilterManager.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Y29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2VhdGEvY29yZS9ycGMvbmV0dHkvaHR0cC9maWx0ZXIvSHR0cFJlcXVlc3RGaWx0ZXJNYW5hZ2VyLmphdmE=) | `75.00% <75.00%> (ø)` | |
   | [...ies/server/filter/ServerHttpFiltersProperties.java](https://app.codecov.io/gh/apache/incubator-seata/pull/7485?src=pr&el=tree&filepath=seata-spring-autoconfigure%2Fseata-spring-autoconfigure-server%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fspring%2Fboot%2Fautoconfigure%2Fproperties%2Fserver%2Ffilter%2FServerHttpFiltersProperties.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c2VhdGEtc3ByaW5nLWF1dG9jb25maWd1cmUvc2VhdGEtc3ByaW5nLWF1dG9jb25maWd1cmUtc2VydmVyL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zZWF0YS9zcHJpbmcvYm9vdC9hdXRvY29uZmlndXJlL3Byb3BlcnRpZXMvc2VydmVyL2ZpbHRlci9TZXJ2ZXJIdHRwRmlsdGVyc1Byb3BlcnRpZXMuamF2YQ==) | `40.00% <40.00%> (ø)` | |
   | [...s/server/filter/ServerHttpXSSFilterProperties.java](https://app.codecov.io/gh/apache/incubator-seata/pull/7485?src=pr&el=tree&filepath=seata-spring-autoconfigure%2Fseata-spring-autoconfigure-server%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fspring%2Fboot%2Fautoconfigure%2Fproperties%2Fserver%2Ffilter%2FServerHttpXSSFilterProperties.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c2VhdGEtc3ByaW5nLWF1dG9jb25maWd1cmUvc2VhdGEtc3ByaW5nLWF1dG9jb25maWd1cmUtc2VydmVyL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zZWF0YS9zcHJpbmcvYm9vdC9hdXRvY29uZmlndXJlL3Byb3BlcnRpZXMvc2VydmVyL2ZpbHRlci9TZXJ2ZXJIdHRwWFNTRmlsdGVyUHJvcGVydGllcy5qYXZh) | `40.00% <40.00%> (ø)` | |
   | ... and [4 more](https://app.codecov.io/gh/apache/incubator-seata/pull/7485?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | |
   
   ... and [4 files with indirect coverage changes](https://app.codecov.io/gh/apache/incubator-seata/pull/7485/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   [![Impacted file tree graph](https://app.codecov.io/gh/apache/incubator-seata/pull/7485/graphs/tree.svg?width=650&height=150&src=pr&token=tbmHt2ZfxO&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)](https://app.codecov.io/gh/apache/incubator-seata/pull/7485?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   </details>
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] feature: Add http request filter for seata-server [incubator-seata]

Posted by "YvCeung (via GitHub)" <gi...@apache.org>.
YvCeung commented on code in PR #7485:
URL: https://github.com/apache/incubator-seata/pull/7485#discussion_r2173638744


##########
core/src/main/java/org/apache/seata/core/rpc/netty/http/filter/impl/XSSHttpRequestFilter.java:
##########
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.seata.core.rpc.netty.http.filter.impl;
+
+import org.apache.seata.config.ConfigurationFactory;
+import org.apache.seata.config.ConfigurationKeys;
+import org.apache.seata.core.exception.HttpRequestFilterException;
+import org.apache.seata.core.rpc.netty.http.filter.HttpFilterContext;
+import org.apache.seata.core.rpc.netty.http.filter.HttpRequestFilter;
+
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+/**
+ * Filter to detect and block potential XSS attack vectors in HTTP request parameters.
+ */
+public class XSSHttpRequestFilter implements HttpRequestFilter {
+
+    private static final String[] XSS_KEYWORDS = {
+        "<script>",
+        "</script>",
+        "javascript:",
+        "vbscript:",
+        "data:",
+        "expression(",
+        "onerror",
+        "onload",
+        "onclick",
+        "onmouseover",
+        "onfocus",
+        "onblur",
+        "onmouseenter",
+        "onmouseleave",
+        "onkeydown",
+        "onkeyup",
+        "onchange",
+        "<iframe>",
+        "<img>",
+        "<svg>",
+        "<embed>",
+        "<object>",
+        "<style>",
+        "<link>"
+    };
+
+    private static final Pattern EVENT_HANDLER_PATTERN =
+            Pattern.compile("on\\w+\\s*=\\s*['\"].*?['\"]", Pattern.CASE_INSENSITIVE);
+
+    @Override
+    public int getOrder() {
+        return 1;
+    }
+
+    /**
+     * Checks all request parameters for XSS risks and throws if found.
+     */
+    @Override
+    public void doFilter(HttpFilterContext context) throws HttpRequestFilterException {
+        Map<String, List<String>> allParams = context.getParamWrapper().getAllParamsAsMultiMap();
+        for (Map.Entry<String, List<String>> entry : allParams.entrySet()) {
+            for (String value : entry.getValue()) {
+                if (value != null && containsXssRisk(value)) {
+                    throw new HttpRequestFilterException(
+                            "XSS risk detected in param: " + entry.getKey() + ", value: " + value);
+                }
+            }
+        }
+    }
+
+    /**
+     * Returns whether this XSS filter is enabled via configuration.
+     */
+    @Override
+    public boolean shouldApply() {
+        return ConfigurationFactory.getInstance()
+                .getBoolean(ConfigurationKeys.SERVER_HTTP_FILTER_XSS_FILTER_ENABLE, true);
+    }
+
+    /**
+     * Basic check for common XSS patterns in a string value.
+     */
+    private boolean containsXssRisk(String value) {
+        if (value == null) {
+            return false;
+        }
+
+        String normalized = value.toLowerCase().replaceAll("\\s+", "");
+
+        for (String keyword : XSS_KEYWORDS) {
+            if (normalized.contains(keyword)) {
+                return true;
+            }
+        }
+
+        if (EVENT_HANDLER_PATTERN.matcher(value).find()) {

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] feature: Add http request filter for seata-server [incubator-seata]

Posted by "YvCeung (via GitHub)" <gi...@apache.org>.
YvCeung commented on code in PR #7485:
URL: https://github.com/apache/incubator-seata/pull/7485#discussion_r2184723122


##########
core/src/main/java/org/apache/seata/core/rpc/netty/http/filter/impl/XSSHttpRequestFilter.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.seata.core.rpc.netty.http.filter.impl;
+
+import org.apache.seata.config.ConfigurationFactory;
+import org.apache.seata.config.ConfigurationKeys;
+import org.apache.seata.core.exception.HttpRequestFilterException;
+import org.apache.seata.core.rpc.netty.http.filter.HttpFilterContext;
+import org.apache.seata.core.rpc.netty.http.filter.HttpRequestFilter;
+
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Filter to detect and block potential XSS attack vectors in HTTP request parameters.
+ */
+public class XSSHttpRequestFilter implements HttpRequestFilter {

Review Comment:
   Is that what you mean?
   ![image](https://github.com/user-attachments/assets/aec33058-21dd-42ec-a32f-b0edd5d51951)
   ![image](https://github.com/user-attachments/assets/c34ad786-447e-4044-9883-8a2098443e05)
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] feature: Add http request filter for seata-server [incubator-seata]

Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on code in PR #7485:
URL: https://github.com/apache/incubator-seata/pull/7485#discussion_r2195182581


##########
seata-spring-autoconfigure/seata-spring-autoconfigure-server/src/main/java/org/apache/seata/spring/boot/autoconfigure/properties/server/filter/ServerHttpFiltersProperties.java:
##########
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.seata.spring.boot.autoconfigure.properties.server.filter;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+import static org.apache.seata.spring.boot.autoconfigure.StarterConstants.SERVER_HTTP_FILTER_PREFIX;
+
+@Component
+@ConfigurationProperties(prefix = SERVER_HTTP_FILTER_PREFIX)
+public class ServerHttpFiltersProperties {
+    private boolean enabled = true;

Review Comment:
   Why not merge ServerHttpFiltersProperties and ServerHttpXSSFilterProperties? Both can use seata.http as the prefix.



##########
server/src/main/java/org/apache/seata/server/filter/XSSHttpRequestFilter.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.seata.server.filter;
+
+import org.apache.seata.config.ConfigurationFactory;
+import org.apache.seata.config.ConfigurationKeys;
+import org.apache.seata.core.exception.HttpRequestFilterException;
+import org.apache.seata.core.rpc.netty.http.filter.HttpFilterContext;
+import org.apache.seata.core.rpc.netty.http.filter.HttpRequestFilter;
+
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Filter to detect and block potential XSS attack vectors in HTTP request parameters.
+ */
+public class XSSHttpRequestFilter implements HttpRequestFilter {
+
+    private static final String[] XSS_KEYWORDS = {

Review Comment:
   It would be even better if this value could be configured through the yml file, and these common keywords could be set as the default configuration.



##########
server/src/main/java/org/apache/seata/server/filter/XSSHttpRequestFilter.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.seata.server.filter;
+
+import org.apache.seata.config.ConfigurationFactory;
+import org.apache.seata.config.ConfigurationKeys;
+import org.apache.seata.core.exception.HttpRequestFilterException;
+import org.apache.seata.core.rpc.netty.http.filter.HttpFilterContext;
+import org.apache.seata.core.rpc.netty.http.filter.HttpRequestFilter;
+
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Filter to detect and block potential XSS attack vectors in HTTP request parameters.
+ */
+public class XSSHttpRequestFilter implements HttpRequestFilter {

Review Comment:
   Why not add the `@LoadLevel` annotation?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] feature: Add http request filter for seata-server [incubator-seata]

Posted by "YvCeung (via GitHub)" <gi...@apache.org>.
YvCeung commented on PR #7485:
URL: https://github.com/apache/incubator-seata/pull/7485#issuecomment-3034625467

   > > @funky-eyes PTAL
   > 
   > Please resolve the code conflicts and make this PR's functionality cover both HTTP and HTTP2.
   
   done


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] feature: Add http request filter for seata-server [incubator-seata]

Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes merged PR #7485:
URL: https://github.com/apache/incubator-seata/pull/7485


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] feature: Add http request filter for seata-server [incubator-seata]

Posted by "YvCeung (via GitHub)" <gi...@apache.org>.
YvCeung commented on code in PR #7485:
URL: https://github.com/apache/incubator-seata/pull/7485#discussion_r2184723122


##########
core/src/main/java/org/apache/seata/core/rpc/netty/http/filter/impl/XSSHttpRequestFilter.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.seata.core.rpc.netty.http.filter.impl;
+
+import org.apache.seata.config.ConfigurationFactory;
+import org.apache.seata.config.ConfigurationKeys;
+import org.apache.seata.core.exception.HttpRequestFilterException;
+import org.apache.seata.core.rpc.netty.http.filter.HttpFilterContext;
+import org.apache.seata.core.rpc.netty.http.filter.HttpRequestFilter;
+
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Filter to detect and block potential XSS attack vectors in HTTP request parameters.
+ */
+public class XSSHttpRequestFilter implements HttpRequestFilter {

Review Comment:
   Is that what you mean?
   ![image](https://github.com/user-attachments/assets/aec33058-21dd-42ec-a32f-b0edd5d51951)
   ![image](https://github.com/user-attachments/assets/c34ad786-447e-4044-9883-8a2098443e05)
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] feature: Add http request filter for seata-server [incubator-seata]

Posted by "YvCeung (via GitHub)" <gi...@apache.org>.
YvCeung commented on code in PR #7485:
URL: https://github.com/apache/incubator-seata/pull/7485#discussion_r2184831140


##########
core/src/main/java/org/apache/seata/core/rpc/netty/http/filter/impl/XSSHttpRequestFilter.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.seata.core.rpc.netty.http.filter.impl;
+
+import org.apache.seata.config.ConfigurationFactory;
+import org.apache.seata.config.ConfigurationKeys;
+import org.apache.seata.core.exception.HttpRequestFilterException;
+import org.apache.seata.core.rpc.netty.http.filter.HttpFilterContext;
+import org.apache.seata.core.rpc.netty.http.filter.HttpRequestFilter;
+
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Filter to detect and block potential XSS attack vectors in HTTP request parameters.
+ */
+public class XSSHttpRequestFilter implements HttpRequestFilter {

Review Comment:
   My idea is that the specific filters can be placed on the server side but not managed by the spring container. They can be obtained through spi in the core module. This way, the timing issue of FilterManager being called before the Spring environment is ready can also be avoided.  @funky-eyes   do you think?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] feature: Add http request filter for seata-server [incubator-seata]

Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on PR #7485:
URL: https://github.com/apache/incubator-seata/pull/7485#issuecomment-3030028744

   > @funky-eyes PTAL
   
   Please resolve the code conflicts and make this PR's functionality cover both HTTP and HTTP2.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] feature: Add http request filter for seata-server [incubator-seata]

Posted by "YvCeung (via GitHub)" <gi...@apache.org>.
YvCeung commented on PR #7485:
URL: https://github.com/apache/incubator-seata/pull/7485#issuecomment-3021553935

   @funky-eyes  PTAL 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] feature: Add http request filter for seata-server [incubator-seata]

Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #7485:
URL: https://github.com/apache/incubator-seata/pull/7485#discussion_r2173623134


##########
core/src/main/java/org/apache/seata/core/rpc/netty/http/filter/impl/XSSHttpRequestFilter.java:
##########
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.seata.core.rpc.netty.http.filter.impl;
+
+import org.apache.seata.config.ConfigurationFactory;
+import org.apache.seata.config.ConfigurationKeys;
+import org.apache.seata.core.exception.HttpRequestFilterException;
+import org.apache.seata.core.rpc.netty.http.filter.HttpFilterContext;
+import org.apache.seata.core.rpc.netty.http.filter.HttpRequestFilter;
+
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+/**
+ * Filter to detect and block potential XSS attack vectors in HTTP request parameters.
+ */
+public class XSSHttpRequestFilter implements HttpRequestFilter {
+
+    private static final String[] XSS_KEYWORDS = {
+        "<script>",
+        "</script>",
+        "javascript:",
+        "vbscript:",
+        "data:",
+        "expression(",
+        "onerror",
+        "onload",
+        "onclick",
+        "onmouseover",
+        "onfocus",
+        "onblur",
+        "onmouseenter",
+        "onmouseleave",
+        "onkeydown",
+        "onkeyup",
+        "onchange",
+        "<iframe>",
+        "<img>",
+        "<svg>",
+        "<embed>",
+        "<object>",
+        "<style>",
+        "<link>"
+    };
+
+    private static final Pattern EVENT_HANDLER_PATTERN =
+            Pattern.compile("on\\w+\\s*=\\s*['\"].*?['\"]", Pattern.CASE_INSENSITIVE);
+
+    @Override
+    public int getOrder() {
+        return 1;
+    }
+
+    /**
+     * Checks all request parameters for XSS risks and throws if found.
+     */
+    @Override
+    public void doFilter(HttpFilterContext context) throws HttpRequestFilterException {
+        Map<String, List<String>> allParams = context.getParamWrapper().getAllParamsAsMultiMap();
+        for (Map.Entry<String, List<String>> entry : allParams.entrySet()) {
+            for (String value : entry.getValue()) {
+                if (value != null && containsXssRisk(value)) {
+                    throw new HttpRequestFilterException(
+                            "XSS risk detected in param: " + entry.getKey() + ", value: " + value);
+                }
+            }
+        }
+    }
+
+    /**
+     * Returns whether this XSS filter is enabled via configuration.
+     */
+    @Override
+    public boolean shouldApply() {
+        return ConfigurationFactory.getInstance()
+                .getBoolean(ConfigurationKeys.SERVER_HTTP_FILTER_XSS_FILTER_ENABLE, true);
+    }
+
+    /**
+     * Basic check for common XSS patterns in a string value.
+     */
+    private boolean containsXssRisk(String value) {
+        if (value == null) {
+            return false;
+        }
+
+        String normalized = value.toLowerCase().replaceAll("\\s+", "");
+
+        for (String keyword : XSS_KEYWORDS) {
+            if (normalized.contains(keyword)) {
+                return true;
+            }
+        }
+
+        if (EVENT_HANDLER_PATTERN.matcher(value).find()) {

Review Comment:
   ## Polynomial regular expression used on uncontrolled data
   
   This [regular expression](1) that depends on a [user-provided value](2) may run slow on strings starting with 'on' and with many repetitions of 'on'.
   
   [Show more details](https://github.com/apache/incubator-seata/security/code-scanning/46)



##########
core/src/main/java/org/apache/seata/core/rpc/netty/http/filter/HttpRequestParamWrapper.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.seata.core.rpc.netty.http.filter;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import io.netty.handler.codec.http.DefaultFullHttpRequest;
+import io.netty.handler.codec.http.FullHttpRequest;
+import io.netty.handler.codec.http.HttpHeaderNames;
+import io.netty.handler.codec.http.HttpRequest;
+import io.netty.handler.codec.http.QueryStringDecoder;
+import io.netty.handler.codec.http.multipart.Attribute;
+import io.netty.handler.codec.http.multipart.HttpPostRequestDecoder;
+import io.netty.handler.codec.http.multipart.InterfaceHttpData;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Wrapper for HTTP request parameters from multiple sources: query, form, header, JSON body.
+ */
+public class HttpRequestParamWrapper {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(HttpRequestParamWrapper.class);
+    private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+
+    private final Map<String, List<String>> queryParams = new HashMap<>();
+    private final Map<String, List<String>> formParams = new HashMap<>();
+    private final Map<String, List<String>> headerParams = new HashMap<>();
+    private final Map<String, List<String>> jsonParams = new HashMap<>();
+
+    public HttpRequestParamWrapper(HttpRequest httpRequest) {
+        if (!(httpRequest instanceof FullHttpRequest)) {
+            throw new IllegalArgumentException("HttpRequest must be FullHttpRequest to read body.");
+        }
+        FullHttpRequest fullRequest = (FullHttpRequest) httpRequest;
+        parseQueryParams(fullRequest);
+        parseHeaders(fullRequest);
+        parseBody(fullRequest);
+    }
+
+    private void parseQueryParams(FullHttpRequest request) {
+        QueryStringDecoder decoder = new QueryStringDecoder(request.uri());
+        queryParams.putAll(decoder.parameters());
+    }
+
+    private void parseHeaders(FullHttpRequest request) {
+        for (Map.Entry<String, String> entry : request.headers()) {
+            headerParams.computeIfAbsent(entry.getKey(), k -> new ArrayList<>()).add(entry.getValue());
+        }
+    }
+
+    private void parseBody(FullHttpRequest request) {
+        String contentType = request.headers().get(HttpHeaderNames.CONTENT_TYPE);
+        if (contentType == null) {
+            return;
+        }
+
+        ByteBuf originalContent = request.content();
+        ByteBuf copiedBuf = Unpooled.copiedBuffer(originalContent);
+
+        String bodyStr = copiedBuf.toString(StandardCharsets.UTF_8);
+
+        try {
+            if (contentType.contains("application/json")) {
+                parseJsonBody(bodyStr);
+            } else if (contentType.contains("application/x-www-form-urlencoded")
+                    || contentType.contains("multipart/form-data")) {
+                FullHttpRequest copiedRequest = new DefaultFullHttpRequest(
+                        request.protocolVersion(), request.method(), request.uri(), copiedBuf);

Review Comment:
   ## Server-side request forgery
   
   Potential server-side request forgery due to a [user-provided value](1).
   
   [Show more details](https://github.com/apache/incubator-seata/security/code-scanning/47)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [PR] feature: Add http request filter for seata-server [incubator-seata]

Posted by "YvCeung (via GitHub)" <gi...@apache.org>.
YvCeung commented on PR #7485:
URL: https://github.com/apache/incubator-seata/pull/7485#issuecomment-3095959141

   > https://github.com/apache/incubator-seata/blob/2.x/script/config-center/config.txt https://github.com/apache/incubator-seata/blob/2.x/server/src/main/resources/application.example.yml https://github.com/apache/incubator-seata/blob/2.x/server/src/main/resources/application.raft.example.yml Please add the newly added configuration to the above setup.
   
   done


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org