github-advanced-security[bot] commented on code in PR #8035:
URL: https://github.com/apache/incubator-seata/pull/8035#discussion_r3014651724


##########
namingserver/src/main/java/org/apache/seata/namingserver/filter/ConsoleRemotingFilter.java:
##########
@@ -108,33 +123,66 @@
                                     .forEach(headerName -> 
headers.add(headerName, request.getHeader(headerName)));
 
                             // Create the HttpEntity with headers and body
-                            HttpEntity<byte[]> httpEntity = new 
HttpEntity<>(request.getCachedBody(), headers);
                             HttpMethod httpMethod;
                             try {
                                 httpMethod = 
HttpMethod.valueOf(request.getMethod());
                             } catch (IllegalArgumentException ex) {
-                                logger.error("Unsupported HTTP method: {}", 
request.getMethod(), ex);
+                                LOGGER.error("Unsupported HTTP method: {}", 
request.getMethod(), ex);
                                 
response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
                                 return;
                             }
+
+                            // GET/HEAD methods should not have a body; other 
methods may include a body as needed.
+                            HttpEntity<byte[]> httpEntity;
+                            if (HttpMethod.GET.equals(httpMethod) || 
HttpMethod.HEAD.equals(httpMethod)) {
+                                headers.remove(HttpHeaders.CONTENT_LENGTH);
+                                headers.remove(HttpHeaders.TRANSFER_ENCODING);
+                                // headers-only
+                                httpEntity = new HttpEntity<>(headers);
+                            } else {
+                                byte[] body = request.getCachedBody();
+                                if (body == null || body.length == 0) {
+                                    headers.remove(HttpHeaders.CONTENT_LENGTH);
+                                    
headers.remove(HttpHeaders.TRANSFER_ENCODING);
+                                    // headers-only for empty body

Review Comment:
   ## Cross-site scripting
   
   Cross-site scripting vulnerability due to a [user-provided value](1).
   
   [Show more 
details](https://github.com/apache/incubator-seata/security/code-scanning/60)



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to