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
Show redirect destination on the OAuth consent page (#77578)
Arik Aronov7a39244afe99
diff --git a/src/metabase/oauth_server/consent_page.clj b/src/metabase/oauth_server/consent_page.cljindex 071ee249521..c489a31dec3 100644--- a/src/metabase/oauth_server/consent_page.clj+++ b/src/metabase/oauth_server/consent_page.clj@@ -7,6 +7,8 @@[metabase.appearance.core :as appearance][metabase.system.core :as system]))+(set! *warn-on-reflection* true)+(defn- absolute-url"Resolve a potentially relative path to an absolute URL using site-url."[path]@@ -138,6 +140,8 @@padding: 0.75rem 1rem; margin-bottom: 1.5rem;font-size: 0.8125rem; line-height: 1.45; color: #883b34; }.warning .mark { flex: 0 0 auto; font-weight: 700; }+ .destination { text-align: center; font-size: 0.8125rem; color: #696e7b; margin-bottom: 1.5rem; }+ .destination strong { font-family: monospace; color: #4c5773; }.actions { display: flex; gap: 0.75rem; }button { flex: 1; padding: 0.75rem 1rem; border-radius: 8px; font-size: 0.875rem; font-weight: 700;font-family: inherit; cursor: pointer;@@ -162,6 +166,8 @@(or client-name "this application") " can do, including reading and changing all data you ""can reach. Only approve it for a tool you trust and control."]])(render-scope-list scopes)+ (when-let [redirect-host (some-> (:redirect_uri oauth-params) not-empty (java.net.URI.) (.getHost))]+ [:p.destination "Redirects to " [:strong redirect-host]])[:form {:method "POST" :action "/oauth/authorize/decision"}[:input {:type "hidden" :name "csrf_token" :value csrf-token}][:input {:type "hidden" :name "params_sig" :value params-sig}]diff --git a/test/metabase/oauth_server/consent_page_test.clj b/test/metabase/oauth_server/consent_page_test.cljindex 874919c9a6c..0645aa84c5a 100644--- a/test/metabase/oauth_server/consent_page_test.clj+++ b/test/metabase/oauth_server/consent_page_test.clj@@ -102,6 +102,30 @@(testing "no scope list is rendered when none were requested"(is (not (re-find #"class=\"scopes\"" (render-with-scopes! nil))))))+(defn- render-with-redirect-uri! [redirect-uri]+ (mt/with-temporary-setting-values [site-url "http://localhost:3000"]+ (consent-page/render-consent-page+ {:client-name "Test App"+ :oauth-params (cond-> {:response_type "code" :client_id "abc123"}+ redirect-uri (assoc :redirect_uri redirect-uri))+ :nonce "test-nonce"+ :csrf-token "test-csrf"})))++(deftest consent-page-redirect-destination-test+ (testing "the destination host the code will be sent to is shown"+ (let [html (render-with-redirect-uri! "https://claude.ai/api/mcp/callback")]+ (is (re-find #"Redirects to" html))+ (is (re-find #"<strong>claude\.ai</strong>" html))))+ (testing "only the parsed host is shown as the destination — userinfo can't spoof the bold host"+ (let [html (render-with-redirect-uri! "https://[email protected]/cb")]+ (is (re-find #"<strong>good\.example</strong>" html))+ (is (not (re-find #"<strong>evil\.example" html)))))+ (testing "no destination row when there is no meaningful host (custom-scheme native redirect)"+ (let [html (render-with-redirect-uri! "com.example.app:/oauth2redirect")]+ (is (not (re-find #"Redirects to" html)))))+ (testing "no destination row when redirect_uri is absent"+ (is (not (re-find #"Redirects to" (render-with-redirect-uri! nil))))))+(deftest consent-page-full-access-warning-test(testing "a full-access scope shows an explicit warning that it grants complete account access"(let [html (render-with-scopes! [{:scope "mb:full"