Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Fix OAuth consent page breaking custom logo when logo URL is a data URI (#71835)

Edward Paget532470d7861d
diff --git a/src/metabase/oauth_server/consent_page.clj b/src/metabase/oauth_server/consent_page.clj
index d38d7a26acc..70f2b65c569 100644
--- a/src/metabase/oauth_server/consent_page.clj
+++ b/src/metabase/oauth_server/consent_page.clj
@@ -11,7 +11,8 @@
"Resolve a potentially relative path to an absolute URL using site-url."
[path]
(if (or (str/starts-with? path "http://")
- (str/starts-with? path "https://"))
+ (str/starts-with? path "https://")
+ (str/starts-with? path "data:"))
path
(str (str/replace (system/site-url) #"/$" "")
"/"
@@ -98,6 +99,7 @@
box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.05);
padding: 2.5rem; max-width: 440px; width: 100%; margin: 1rem; }
.logo { display: flex; justify-content: center; margin-bottom: 1.5rem; }
+ .logo img { max-height: 32px; max-width: 100%; min-height: 100%; height: auto; }
h1 { font-size: 1.25rem; font-weight: 700; color: #2e353b; text-align: center; margin-bottom: 0.25rem; }
.client-id { text-align: center; font-size: 0.75rem; color: #949aab; margin-bottom: 1rem;
font-family: monospace; word-break: break-all; }
diff --git a/test/metabase/oauth_server/consent_page_test.clj b/test/metabase/oauth_server/consent_page_test.clj
index dc0d16bde02..186dc65dfa6 100644
--- a/test/metabase/oauth_server/consent_page_test.clj
+++ b/test/metabase/oauth_server/consent_page_test.clj
@@ -4,6 +4,8 @@
[metabase.oauth-server.consent-page :as consent-page]
[metabase.test :as mt]))
+(set! *warn-on-reflection* true)
+
(defn- render!
"Render the consent page with default params."
[]
@@ -31,3 +33,46 @@
(is (re-find #"<svg" html) "should contain inline SVG")
(is (not (re-find #"currentColor" html)) "should not contain currentColor")
(is (re-find #"#509ee3" html) "should contain the default brand color"))))
+
+(deftest custom-logo-data-uri-test
+ (testing "data URI logo is preserved verbatim in img src"
+ (mt/with-premium-features #{:whitelabel}
+ (let [data-uri "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg=="
+ html (mt/with-temporary-setting-values [site-url "http://localhost:3000"
+ application-logo-url data-uri]
+ (consent-page/render-consent-page
+ {:client-name "Test App"
+ :oauth-params {:response_type "code" :client_id "abc123"}
+ :nonce "test-nonce"
+ :csrf-token "test-csrf"}))]
+ (is (re-find (re-pattern (java.util.regex.Pattern/quote data-uri)) html)
+ "data URI should appear verbatim in img src")
+ (is (not (re-find #"localhost:3000/data:" html))
+ "data URI should not be prefixed with site URL")))))
+
+(deftest custom-logo-external-url-test
+ (testing "external URL logo is passed through unchanged"
+ (mt/with-premium-features #{:whitelabel}
+ (let [logo-url "https://example.com/logo.png"
+ html (mt/with-temporary-setting-values [site-url "http://localhost:3000"
+ application-logo-url logo-url]
+ (consent-page/render-consent-page
+ {:client-name "Test App"
+ :oauth-params {:response_type "code" :client_id "abc123"}
+ :nonce "test-nonce"
+ :csrf-token "test-csrf"}))]
+ (is (re-find #"https://example\.com/logo\.png" html)
+ "external URL should appear unchanged in img src")))))
+
+(deftest custom-logo-relative-path-test
+ (testing "relative path logo gets site URL prepended"
+ (mt/with-premium-features #{:whitelabel}
+ (let [html (mt/with-temporary-setting-values [site-url "http://localhost:3000"
+ application-logo-url "app/assets/img/custom.png"]
+ (consent-page/render-consent-page
+ {:client-name "Test App"
+ :oauth-params {:response_type "code" :client_id "abc123"}
+ :nonce "test-nonce"
+ :csrf-token "test-csrf"}))]
+ (is (re-find #"http://localhost:3000/app/assets/img/custom\.png" html)
+ "relative path should be resolved to absolute URL")))))