The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Check Mysql connection params for unsafe options (#73510)
Riley Thompsonc741cdff05bf
diff --git a/src/metabase/driver/mysql.clj b/src/metabase/driver/mysql.cljindex 039d7b1730d..d88a26a4ff7 100644--- a/src/metabase/driver/mysql.clj+++ b/src/metabase/driver/mysql.clj@@ -210,10 +210,15 @@"All Metabase features may not work properly when using an unsupported version.""\n********************************************************************************\n"))))))))+(def ^:private disallowed-additional-opts #"(?:allowLoadLocalInfile|allowLoadLocalInfileInPath|allowUrlInLocalInfile|autoDeserialize|serverRSAPublicKeyFile)")+(defmethod driver/can-connect? :mysql[driver details];; delegate to parent method to check whether we can connect; if so, check if it's an unsupported version and issue;; a warning if it is+ (let [match (re-find disallowed-additional-opts (:additional-options details ""))]+ (when match+ (throw (ex-info "Potentially dangerous keys in additional options" {:disallowed-key match}))))(when ((get-method driver/can-connect? :sql-jdbc) driver details)(warn-on-unsupported-versions driver details)true))diff --git a/test/metabase/driver/mysql_test.clj b/test/metabase/driver/mysql_test.cljindex 5fefd33b72e..0501376237c 100644--- a/test/metabase/driver/mysql_test.clj+++ b/test/metabase/driver/mysql_test.clj@@ -1039,3 +1039,20 @@;; Clean up: Reset partial_revokes to OFF before exiting(jdbc/execute! spec "SET GLOBAL partial_revokes = OFF;")(jdbc/execute! spec "DROP USER IF EXISTS 'partial_revokes_test_user';"))))))))++(deftest ^:parallel only-connect-when-non-malicious-properties+ (testing "Reject connection strings with malicious properties"+ (are [bad-option] (let [details (assoc (tx/dbdef->connection-details :mysql :db+ {:database-name "argent"})+ :additional-options bad-option)+ result (try (driver/can-connect? :mysql details)+ ::did-not-throw+ (catch Exception e e))]+ (is (instance? clojure.lang.ExceptionInfo result))+ (is (partial= {:cause "Potentially dangerous keys in additional options"}+ (Throwable->map result))))+ "allowLoadLocalInfile=true"+ "allowLoadLocalInfileInPath=1"+ "allowUrlInLocalInfile=1"+ "autoDeserialize=1"+ "serverRSAPublicKeyFile=/path/to/file")))