Skip to content

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

Don't send Referer header on POST /oauth/authorize/decision (#76311)

Rodrigo López Dato573759e581e1
diff --git a/e2e/test/scenarios/admin/oauth-authorizations.cy.spec.ts b/e2e/test/scenarios/admin/oauth-authorizations.cy.spec.ts
index 6c8cf7ed054..a83c04449ea 100644
--- a/e2e/test/scenarios/admin/oauth-authorizations.cy.spec.ts
+++ b/e2e/test/scenarios/admin/oauth-authorizations.cy.spec.ts
@@ -61,6 +61,41 @@ describe("scenarios > admin > metabot > oauth authorizations", () => {
});
});
+ it("does not send the long authorization URL as a Referer header on submit (#76305)", () => {
+ // A long authorization URL (many scopes, PKCE challenge, etc.) sent as the Referer header on
+ // the consent form POST can exceed the server's header size limit and cause a 431. The consent
+ // page sets `<meta name="referrer" content="no-referrer">` so the browser omits it entirely.
+ // This needs a real browser navigation (cy.visit + click) — cy.request would not replicate the
+ // browser's automatic Referer behavior.
+ registerClient("E2E Referer Client", {
+ token_endpoint_auth_method: "client_secret_basic",
+ }).then((client) => {
+ const authorizeUrl =
+ `/oauth/authorize?client_id=${client.client_id}` +
+ `&redirect_uri=${encodeURIComponent(REDIRECT_URI)}` +
+ `&response_type=code&scope=${encodeURIComponent(SCOPE)}&state=test-state`;
+
+ // Stub a same-origin HTML response so the browser navigates to it (firing a `load` event
+ // Cypress can wait on) instead of following the real 302 to the external redirect_uri, which
+ // would break Cypress with a cross-origin navigation. A 204 would leave the browser on the
+ // current page with no `load` event, so `cy.wait` would hang until the page-load timeout.
+ cy.intercept("POST", "/oauth/authorize/decision", (req) => {
+ req.reply({
+ statusCode: 200,
+ headers: { "content-type": "text/html" },
+ body: "<html><body>ok</body></html>",
+ });
+ }).as("decision");
+
+ cy.visit(authorizeUrl);
+ cy.findByRole("button", { name: "Authorize" }).click();
+
+ cy.wait("@decision").then(({ request }) => {
+ expect(request.headers).to.not.have.property("referer");
+ });
+ });
+ });
+
it("is accessible to superusers only", () => {
cy.signInAsNormalUser();
cy.request({
diff --git a/src/metabase/oauth_server/consent_page.clj b/src/metabase/oauth_server/consent_page.clj
index 2fe823028d9..6c993a635f2 100644
--- a/src/metabase/oauth_server/consent_page.clj
+++ b/src/metabase/oauth_server/consent_page.clj
@@ -194,6 +194,10 @@
[:html {:lang "en"}
[:head
[:meta {:charset "UTF-8"}]
+ ;; Prevent the browser from sending the (very long) authorization URL as the Referer
+ ;; header when the consent form is submitted, which could exceed the server's header
+ ;; size limit and cause a 431. The Referer is not used by the decision endpoint.
+ [:meta {:name "referrer" :content "no-referrer"}]
[:meta {:name "viewport" :content "width=device-width, initial-scale=1.0"}]
[:title "Authorize " (or client-name "Unknown Application")]
[:style {:nonce nonce} (h/raw