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


##########
console/src/main/java/org/apache/seata/mcp/store/HikariDataSourceProvider.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.store;
+
+import com.zaxxer.hikari.HikariConfig;
+import com.zaxxer.hikari.HikariDataSource;
+import com.zaxxer.hikari.util.IsolationLevel;
+import org.apache.seata.mcp.store.db.AbstractMCPDataSourceProvider;
+
+import javax.sql.DataSource;
+import java.util.Properties;
+
+/**
+ * The hikari datasource provider
+ */
+public class HikariDataSourceProvider extends AbstractMCPDataSourceProvider {
+
+    @Override
+    public DataSource doGenerate() {
+        Properties properties = new Properties();
+        properties.setProperty("dataSource.cachePrepStmts", "true"); // Enable 
prepared statement caching
+        properties.setProperty("dataSource.prepStmtCacheSize", "250"); // 
Number of prepared statements to cache
+        properties.setProperty("dataSource.prepStmtCacheSqlLimit", "2048"); // 
Maximum SQL statement length to cache
+        properties.setProperty("dataSource.useServerPrepStmts", "true"); // 
Use server-side prepared statements
+        properties.setProperty("dataSource.useLocalSessionState", "true"); // 
Track transaction state locally
+        properties.setProperty(
+                "dataSource.rewriteBatchedStatements", "true"); // Rewrite 
batched statements for efficiency
+        properties.setProperty("dataSource.cacheResultSetMetadata", "true"); 
// Cache result set metadata
+        properties.setProperty("dataSource.cacheServerConfiguration", "true"); 
// Cache server configuration
+        properties.setProperty("dataSource.elideSetAutoCommits", "true"); // 
Don't send autocommit if unchanged
+        properties.setProperty("dataSource.maintainTimeStats", "false"); // 
Disable time statistics tracking
+
+        HikariConfig config = new HikariConfig(properties);
+
+        config.setDriverClassName(getDriverClassName());
+        config.setJdbcUrl(getUrl());

Review Comment:
   ## CodeQL / 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/63)



##########
console/src/main/java/org/apache/seata/mcp/service/impl/BusinessDataSourceServiceImpl.java:
##########
@@ -0,0 +1,186 @@
+/*
+ * 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.service.impl;
+
+import org.apache.seata.common.exception.StoreException;
+import org.apache.seata.common.util.StringUtils;
+import org.apache.seata.mcp.core.constant.SqlConstant;
+import org.apache.seata.mcp.core.props.BusinessDataSourcesProperties;
+import org.apache.seata.mcp.entity.dto.MysqlDataSourceRegisterRequest;
+import org.apache.seata.mcp.entity.vo.BusinessQueryResult;
+import org.apache.seata.mcp.entity.vo.MysqlColumnInfo;
+import org.apache.seata.mcp.entity.vo.MysqlDataSourceInfo;
+import org.apache.seata.mcp.entity.vo.MysqlDataSourceTestResult;
+import org.apache.seata.mcp.entity.vo.MysqlTableInfo;
+import org.apache.seata.mcp.service.BusinessDataSourceService;
+import org.apache.seata.mcp.service.MysqlMetadataService;
+import org.apache.seata.mcp.store.DataSourceFactory;
+import org.apache.seata.mcp.store.SqlExecutionTemplate;
+import org.apache.seata.mcp.store.SqlSafetyValidator;
+import org.springframework.stereotype.Service;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+@Service
+public class BusinessDataSourceServiceImpl implements 
BusinessDataSourceService {
+
+    private static final Pattern IDENTIFIER_PATTERN = 
Pattern.compile("[A-Za-z0-9_$]+");
+
+    private final SqlExecutionTemplate sqlExecutionTemplate;
+
+    private final BusinessDataSourcesProperties businessDataSourcesProperties;
+
+    private final MysqlMetadataService mysqlMetadataService;
+
+    private final SqlSafetyValidator sqlSafetyValidator;
+
+    public BusinessDataSourceServiceImpl(
+            SqlExecutionTemplate sqlExecutionTemplate,
+            BusinessDataSourcesProperties businessDataSourcesProperties,
+            MysqlMetadataService mysqlMetadataService,
+            SqlSafetyValidator sqlSafetyValidator) {
+        this.sqlExecutionTemplate = sqlExecutionTemplate;
+        this.businessDataSourcesProperties = businessDataSourcesProperties;
+        this.mysqlMetadataService = mysqlMetadataService;
+        this.sqlSafetyValidator = sqlSafetyValidator;
+    }
+
+    @Override
+    public List<MysqlDataSourceInfo> getMysqlDataSources() {
+        return businessDataSourcesProperties.getMysqlDataSourceInfos();
+    }
+
+    @Override
+    public String registerMysqlDataSource(MysqlDataSourceRegisterRequest 
request) {
+        return businessDataSourcesProperties.registerMysqlDataSource(request);
+    }
+
+    @Override
+    public String unregisterMysqlDataSource(String name) {
+        String resourceId = 
businessDataSourcesProperties.unregisterMysqlDataSource(name);
+        DataSourceFactory.removeDataSource(resourceId);
+        return resourceId;
+    }
+
+    @Override
+    public MysqlDataSourceTestResult 
testMysqlDataSource(MysqlDataSourceRegisterRequest request) {
+        long start = System.currentTimeMillis();
+        MysqlDataSourceTestResult result = new MysqlDataSourceTestResult();
+        result.setValidationQuery(SqlConstant.MYSQL_VALIDATION_SQL);
+        try {
+            BusinessDataSourcesProperties.DataSourceProperties props =
+                    
businessDataSourcesProperties.buildDynamicMysqlProperties(request);
+            Class.forName(props.getDriverClassName());
+            try (Connection connection =
+                            DriverManager.getConnection(props.getUrl(), 
props.getUsername(), props.getPassword());

Review Comment:
   ## CodeQL / 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/62)



-- 
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