yuqi1129 commented on code in PR #7615:
URL: https://github.com/apache/gravitino/pull/7615#discussion_r2203763964


##########
common/src/main/java/org/apache/gravitino/utils/JdbcUrlUtils.java:
##########
@@ -0,0 +1,123 @@
+/*
+ *  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.gravitino.utils;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import org.apache.gravitino.exceptions.GravitinoRuntimeException;
+
+/**
+ * Utility class for validating JDBC URLs and configurations. It checks for 
unsafe parameters
+ * specific to MySQL, MariaDB, and PostgreSQL JDBC URLs. Unsafe parameters can 
lead to security
+ * vulnerabilities or unexpected behavior, so this utility helps ensure that 
JDBC configurations are
+ * safe to use.
+ */
+public class JdbcUrlUtils {
+
+  // Unsafe parameters for MySQL and MariaDB, other parameters like
+  // trustCertificateKeyStoreUrl, serverTimezone, characterEncoding,
+  // useSSL are also risky, please use it with caution.
+  private static final List<String> UNSAFE_MYSQL_PARAMETERS =
+      Arrays.asList(
+          "maxAllowedPacket",
+          "autoDeserialize",
+          "queryInterceptors",
+          "statementInterceptors",
+          "detectCustomCollations",
+          "allowloadlocalinfile",
+          "allowUrlInLocalInfile",
+          "allowLoadLocalInfileInPath");
+
+  private static final List<String> UNSAFE_POSTGRES_PARAMETERS =
+      Arrays.asList(
+          "socketFactory",
+          "socketFactoryArg",
+          "sslfactory",
+          "sslhostnameverifier",
+          "sslpasswordcallback",
+          "authenticationPluginClassName");
+
+  private JdbcUrlUtils() {
+    // Utility class, no instantiation allowed
+  }
+
+  /**
+   * Validates the JDBC configuration by checking the driver and URL for 
unsafe parameters.
+   *
+   * @param driver the JDBC driver class name
+   * @param url the JDBC URL
+   * @param all the JDBC configuration properties
+   */
+  public static void validateJdbcConfig(String driver, String url, Map<String, 
String> all) {
+    String lowerUrl = url.toLowerCase();
+    String decodedUrl = recursiveDecode(lowerUrl);
+
+    if (driver != null) {
+      if (decodedUrl.startsWith("jdbc:mysql")) {

Review Comment:
   
https://gravitino.apache.org/docs/0.9.0-incubating/gravitino-server-config#storage-backend-configuration



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

Reply via email to