Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(metabase): show a clear error when the instance URL redirects (#89909)

Tom Owersacd21d03f599
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/metabase/metabase.py b/products/warehouse_sources/backend/temporal/data_imports/sources/metabase/metabase.py
index 4c74caa5b5f2..e8468517acf2 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/metabase/metabase.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/metabase/metabase.py
@@ -30,6 +30,14 @@ REQUEST_TIMEOUT_SECONDS = 60
HOST_NOT_ALLOWED_ERROR = "Metabase host is not allowed"
+# Returned when the Instance URL responds with a 3xx. We refuse to follow redirects (an off-host
+# 3xx is an SSRF vector), so a redirecting URL can never be probed. The raw HOST_NOT_ALLOWED_ERROR
+# told the user nothing they could act on; this points them at the canonical instance URL.
+REDIRECT_NOT_FOLLOWED_ERROR = (
+ "Your Metabase instance redirected the connection, which PostHog doesn't follow. "
+ "Enter the direct https:// URL of your Metabase instance, then reconnect."
+)
+
# Stable substring matched by MetabaseSource.get_non_retryable_errors when the session endpoint
# returns a 2xx that isn't JSON (the Instance URL isn't a Metabase API).
SESSION_RESPONSE_NOT_JSON_ERROR = "Metabase session response was not valid JSON"
@@ -237,7 +245,7 @@ def validate_credentials(
return False, _connection_error_message(e)
if response.is_redirect or response.is_permanent_redirect:
- return False, HOST_NOT_ALLOWED_ERROR
+ return False, REDIRECT_NOT_FOLLOWED_ERROR
if response.status_code == 200:
return True, None
if response.status_code == 401:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/metabase/tests/test_metabase.py b/products/warehouse_sources/backend/temporal/data_imports/sources/metabase/tests/test_metabase.py
index ab243e608ef9..b7bfe2584486 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/metabase/tests/test_metabase.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/metabase/tests/test_metabase.py
@@ -220,7 +220,7 @@ class TestValidateCredentials:
with self._patch_session(_response(status_code=302)) as patched:
valid, msg = validate_credentials("https://x.metabaseapp.com", _api_key_auth())
assert valid is False
- assert msg == metabase_module.HOST_NOT_ALLOWED_ERROR
+ assert msg == metabase_module.REDIRECT_NOT_FOLLOWED_ERROR
assert patched.return_value.get.call_args.kwargs["allow_redirects"] is False
def test_blocks_unsafe_host(self):