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
Allow app and capacitor schemes as valid origins for Ionic apps (#64719)
Rodrigo López Datob9ac3ab8868a
diff --git a/src/metabase/server/middleware/security.clj b/src/metabase/server/middleware/security.cljindex 7d325a1c985..57782b67e6a 100644--- a/src/metabase/server/middleware/security.clj+++ b/src/metabase/server/middleware/security.clj@@ -64,7 +64,7 @@[url](if (= url "*"){:protocol nil :domain "*" :port "*"}- (let [pattern #"^(?:(https?)://)?([^:/]+)(?::(\d+|\*))?$"+ (let [pattern #"^(?:(https?|app|capacitor)://)?([^:/]+)(?::(\d+|\*))?$"matches (re-matches pattern url)](if-not matches(do (log/errorf "Invalid URL: %s" url) nil)@@ -203,8 +203,12 @@(defn approved-protocol?"Checks if the protocol is compatible with the reference one"[protocol reference-protocol]- (or (nil? reference-protocol)- (= protocol reference-protocol)))+ (if (nil? reference-protocol)+ ;; When the approved origin has no protocol (e.g., "localhost"),+ ;; treat it as allowing only HTTP or HTTPS. Custom schemes like+ ;; app:// must be explicitly specified in the approved origins.+ (contains? #{"http" "https"} protocol)+ (= protocol reference-protocol)))(defn approved-port?"Checks if the port is compatible with the reference one"diff --git a/test/metabase/server/middleware/security_test.clj b/test/metabase/server/middleware/security_test.cljindex f49ef802a2e..63e78cf4ff8 100644--- a/test/metabase/server/middleware/security_test.clj+++ b/test/metabase/server/middleware/security_test.clj@@ -110,7 +110,9 @@"https://example.com" {:protocol "https" :domain "example.com" :port nil}"http://example.com:8080" {:protocol "http" :domain "example.com" :port "8080"}"example.com:80" {:protocol nil :domain "example.com" :port "80"}- "example.com:*" {:protocol nil :domain "example.com" :port "*"}))+ "example.com:*" {:protocol nil :domain "example.com" :port "*"}+ "app://localhost" {:protocol "app" :domain "localhost" :port nil}+ "capacitor://localhost" {:protocol "capacitor" :domain "localhost" :port nil}))(testing "Should return nil for invalid urls"(are [url] (nil? (mw.security/parse-url url))"ftp://example.com"@@ -141,9 +143,11 @@(is (mw.security/approved-protocol? "http" "http"))(is (mw.security/approved-protocol? "https" "https"))(is (not (mw.security/approved-protocol? "http" "https"))))- (testing "Nil reference should allow any protocol"+ (testing "Nil reference should allow only http/https"(is (mw.security/approved-protocol? "http" nil))- (is (mw.security/approved-protocol? "https" nil))))+ (is (mw.security/approved-protocol? "https" nil))+ (is (not (mw.security/approved-protocol? "app" nil)))+ (is (not (mw.security/approved-protocol? "capacitor" nil)))))(deftest ^:parallel test-approved-port?(testing "Exact port match"@@ -184,10 +188,11 @@(is (mw.security/approved-origin? "https://example3.com" approved))))(testing "Different protocol should fail"(is (not (mw.security/approved-origin? "https://example1.com" "http://example1.com"))))- (testing "Origins without protocol should accept both http and https"+ (testing "Origins without protocol should accept only http and https"(let [approved "example.com"](is (mw.security/approved-origin? "http://example.com" approved))- (is (mw.security/approved-origin? "https://example.com" approved))))+ (is (mw.security/approved-origin? "https://example.com" approved))+ (is (not (mw.security/approved-origin? "app://example.com" approved)))))(testing "Different ports should fail"(is (not (mw.security/approved-origin? "http://example.com:3000" "http://example.com:3003"))))(testing "Should allow anything with *"