Reject unneeded connection properties in SQL-JDBC additional-options (#81097)

This commit is contained in:
bryan
2026-08-27 10:29:18 -06:00
committed by GitHub
parent c24f084ae6
commit 13dde0bba3
2 changed files with 29 additions and 0 deletions

View File

@@ -53,8 +53,19 @@
;;; | Default SQL JDBC metabase.driver impls |
;;; +----------------------------------------------------------------------------------------------------------------+
(def ^:private disallowed-additional-opts
"JDBC connection properties that are not needed to connect to a warehouse and are rejected for every
SQL-JDBC driver. Matched case-insensitively against the raw `additional-options` string."
#"(?i)(?:socketFactory|sslfactory|sslhostnameverifier|sslpasswordcallback|xmlFactoryFactory|loggerFile)")
(defmethod driver/validate-db-details! :sql-jdbc
[_driver details]
(when-let [match (some->> (:additional-options details) (re-find disallowed-additional-opts))]
(throw (ex-info "Potentially dangerous keys in additional options" {:disallowed-key match}))))
(defmethod driver/can-connect? :sql-jdbc
[driver details]
(driver/validate-db-details! driver details)
(sql-jdbc.conn/can-connect? driver details))
(defmethod driver/table-rows-seq :sql-jdbc

View File

@@ -108,6 +108,24 @@
(throw e))
(some-> (.getCause e) recur))))))))))
(deftest validate-db-details-additional-options-test
(testing "validate-db-details! rejects disallowed connection properties in additional-options"
(doseq [opt ["socketFactory=a.b.C"
"sslfactory=a.b.C"
"sslhostnameverifier=a.b.C"
"sslpasswordcallback=a.b.C"
"xmlFactoryFactory=a.b.C"
"loggerFile=a/b"]]
(testing opt
(is (thrown-with-msg?
clojure.lang.ExceptionInfo #"dangerous"
(driver/validate-db-details! :sql-jdbc {:additional-options opt}))))))
(testing "benign additional options and no additional options are allowed"
(doseq [details [{}
{:additional-options nil}
{:additional-options "prepareThreshold=5&tcpKeepAlive=true"}]]
(is (nil? (driver/validate-db-details! :sql-jdbc details))))))
(defn- test-spliced-count-of [table filter-clause expected]
(let [query (mt/mbql-query nil
{:source-table (mt/id table)