Copilot commented on code in PR #7876:
URL: https://github.com/apache/incubator-seata/pull/7876#discussion_r2642152724
##########
console/src/main/java/org/apache/seata/console/config/WebSecurityConfig.java:
##########
@@ -98,7 +106,13 @@ public AuthenticationManager authenticationManager() {
@Bean
public WebSecurityCustomizer webSecurityCustomizer() {
- RequestMatcher[] ignoredMatchers =
buildAntMatchers(env.getProperty("seata.security.ignore.urls", "/**"));
+ StringBuilder ignoreURLsBuilder = new StringBuilder(ignoreURLs);
+ List<String> mcpEndpoints = mcpProperties.getEndpoints();
+ for (String endpoint : mcpEndpoints) {
+ ignoreURLsBuilder.append(",").append(endpoint);
Review Comment:
The security approach of bypassing authentication for MCP endpoints by
adding them to the ignore list is problematic. The MCPProperties class has an
`isEnableAuth()` method, but it's not being used here. The code unconditionally
adds MCP endpoints to the ignore list (bypassing authentication), regardless of
whether `seata.mcp.auth.enabled` is true or false. This means authentication
cannot be enforced for MCP endpoints even when configured to do so. Consider
checking `mcpProperties.isEnableAuth()` before adding endpoints to the ignore
list.
```suggestion
if (!mcpProperties.isEnableAuth() && mcpEndpoints != null) {
for (String endpoint : mcpEndpoints) {
ignoreURLsBuilder.append(",").append(endpoint);
}
```
##########
console/src/main/java/org/apache/seata/console/config/WebSecurityConfig.java:
##########
@@ -109,8 +123,13 @@ public WebSecurityCustomizer webSecurityCustomizer() {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http,
AuthenticationManager authenticationManager)
throws Exception {
- RequestMatcher[] csrfIgnored =
buildAntMatchers(env.getProperty("seata.security.csrf-ignore-urls"));
-
+ StringBuilder csrfIgnoreUrlsBuilder = new
StringBuilder(csrfIgnoreUrls);
+ List<String> mcpEndpoints = mcpProperties.getEndpoints();
+ for (String endpoint : mcpEndpoints) {
+ csrfIgnoreUrlsBuilder.append(",").append(endpoint);
Review Comment:
The same security issue exists here with CSRF protection. The MCP endpoints
are unconditionally added to the CSRF ignore list regardless of the
`seata.mcp.auth.enabled` configuration. This could expose MCP endpoints to CSRF
attacks even when authentication is intended to be enabled. Consider checking
`mcpProperties.isEnableAuth()` before adding endpoints to the CSRF ignore list.
```suggestion
if (!mcpProperties.isEnableAuth()) {
for (String endpoint : mcpEndpoints) {
csrfIgnoreUrlsBuilder.append(",").append(endpoint);
}
```
##########
console/src/main/java/org/apache/seata/mcp/core/props/MCPProperties.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.mcp.core.props;
+
+import jakarta.annotation.Nullable;
+import jakarta.annotation.PostConstruct;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import
org.springframework.ai.mcp.server.common.autoconfigure.properties.McpServerProperties;
+import
org.springframework.ai.mcp.server.common.autoconfigure.properties.McpServerSseProperties;
+import
org.springframework.ai.mcp.server.common.autoconfigure.properties.McpServerStreamableHttpProperties;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+@Component
+public class MCPProperties {
+
+ private final Environment env;
+
+ private boolean enableAuth = true;
+
+ private Long queryDuration = TimeUnit.DAYS.toMillis(1);
+
+ private final McpServerProperties mcpServerProperties;
+
+ private final McpServerSseProperties mcpServerSseProperties;
+
+ private final McpServerStreamableHttpProperties
mcpServerStreamableHttpProperties;
+
+ private final List<String> endpoints = new ArrayList<>();
+
+ private final Logger logger = LoggerFactory.getLogger(MCPProperties.class);
+
+ @Autowired
+ public MCPProperties(
+ @Nullable McpServerProperties mcpServerProperties,
+ Environment env,
+ @Nullable McpServerSseProperties serverSseProperties,
+ @Nullable McpServerStreamableHttpProperties
serverStreamableHttpProperties) {
+ this.mcpServerProperties = mcpServerProperties;
+ this.env = env;
+ this.mcpServerSseProperties = serverSseProperties;
+ this.mcpServerStreamableHttpProperties =
serverStreamableHttpProperties;
+ }
+
+ public List<String> getEndpoints() {
+ return Collections.unmodifiableList(new ArrayList<>(endpoints));
Review Comment:
The method creates a defensive copy by wrapping the endpoints list in an
unmodifiable list, but then creates another ArrayList copy. The double copy
(new ArrayList inside unmodifiableList) is redundant. Since
Collections.unmodifiableList already protects against modifications, the inner
ArrayList copy is unnecessary. Simply return
Collections.unmodifiableList(endpoints) to maintain immutability while avoiding
the unnecessary object allocation.
```suggestion
return Collections.unmodifiableList(endpoints);
```
##########
console/src/main/java/org/apache/seata/mcp/core/props/MCPProperties.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.mcp.core.props;
+
+import jakarta.annotation.Nullable;
+import jakarta.annotation.PostConstruct;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import
org.springframework.ai.mcp.server.common.autoconfigure.properties.McpServerProperties;
+import
org.springframework.ai.mcp.server.common.autoconfigure.properties.McpServerSseProperties;
+import
org.springframework.ai.mcp.server.common.autoconfigure.properties.McpServerStreamableHttpProperties;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+@Component
+public class MCPProperties {
+
+ private final Environment env;
+
+ private boolean enableAuth = true;
+
+ private Long queryDuration = TimeUnit.DAYS.toMillis(1);
+
+ private final McpServerProperties mcpServerProperties;
+
+ private final McpServerSseProperties mcpServerSseProperties;
+
+ private final McpServerStreamableHttpProperties
mcpServerStreamableHttpProperties;
+
+ private final List<String> endpoints = new ArrayList<>();
+
+ private final Logger logger = LoggerFactory.getLogger(MCPProperties.class);
+
+ @Autowired
+ public MCPProperties(
+ @Nullable McpServerProperties mcpServerProperties,
+ Environment env,
+ @Nullable McpServerSseProperties serverSseProperties,
+ @Nullable McpServerStreamableHttpProperties
serverStreamableHttpProperties) {
+ this.mcpServerProperties = mcpServerProperties;
+ this.env = env;
+ this.mcpServerSseProperties = serverSseProperties;
+ this.mcpServerStreamableHttpProperties =
serverStreamableHttpProperties;
+ }
+
+ public List<String> getEndpoints() {
+ return Collections.unmodifiableList(new ArrayList<>(endpoints));
+ }
+
+ public Long getQueryDuration() {
+ return queryDuration;
+ }
+
+ @PostConstruct
+ public void init() {
+ String maxQueryDurationStr =
env.getProperty("seata.mcp.query.max-query-duration", "86400000");
+ try {
+ queryDuration = Long.parseLong(maxQueryDurationStr);
+ } catch (NumberFormatException ex) {
+ queryDuration = TimeUnit.DAYS.toMillis(1);
+ }
+ enableAuth =
Boolean.parseBoolean(env.getProperty("seata.mcp.auth.enabled", "true"));
+
+ if (!enableAuth) {
+ logger.warn(
+ "MCP server authentication is disabled. This creates a
security risk. It is strongly recommended to enable authentication by setting
seata.mcp.auth.enabled=true");
+ }
+
+ if (mcpServerProperties != null) {
+ McpServerProperties.ServerProtocol protocol =
mcpServerProperties.getProtocol();
+ if (protocol == McpServerProperties.ServerProtocol.SSE &&
mcpServerSseProperties != null) {
+ endpoints.add(mcpServerSseProperties.getSseEndpoint());
+ endpoints.add(mcpServerSseProperties.getSseMessageEndpoint());
+ } else if (protocol ==
McpServerProperties.ServerProtocol.STREAMABLE
+ && mcpServerStreamableHttpProperties != null) {
+
endpoints.add(mcpServerStreamableHttpProperties.getMcpEndpoint());
+ } else {
+ throw new IllegalStateException(
+ "MCP server properties not properly configured or
unsupported protocol");
+ }
+ } else {
+ logger.warn("MCP server properties not properly configured");
Review Comment:
The error handling in the else block silently logs a warning and continues
when the protocol is unsupported or properties are null. This could lead to the
endpoints list being empty, which might cause the application to behave
unexpectedly. Consider throwing the IllegalStateException in all cases where
the configuration is invalid, not just when protocol properties don't match the
configured protocol.
```suggestion
throw new IllegalStateException("MCP server properties not
properly configured");
```
--
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]