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): don't leak raw upstream response body on credential check (#66516)

Tom Owersaaaac64d3787
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 3ac51a1da46b..2f5b9fe92f49 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
@@ -202,11 +202,14 @@ def validate_credentials(
return True, None
return False, "Metabase credentials lack the required permissions"
- try:
- body = response.json()
- return False, body.get("message", response.text)
- except Exception:
- return False, response.text
+ # Any other status: the host responded but not in a way we recognise — often it isn't a
+ # Metabase instance at all (e.g. a proxy or hosting-provider error page). Surface the status
+ # only; never echo the raw response body, which can carry arbitrary upstream content.
+ return (
+ False,
+ f"Metabase returned an unexpected response (HTTP {response.status_code}). "
+ "Check that the Instance URL points to your Metabase instance.",
+ )
def get_rows(
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 b79e37c4d890..f9a4b15ad9d8 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
@@ -221,6 +221,18 @@ class TestValidateCredentials:
assert msg is not None
session.get.assert_not_called()
+ def test_unexpected_status_does_not_leak_response_body(self):
+ # When the host isn't a Metabase instance it returns an arbitrary body (e.g. a hosting
+ # provider's error page). That body must never reach the user — only a friendly,
+ # status-coded message that points them back at the Instance URL.
+ leaked_body = '{"error": {"code": "404", "message": "SENTINEL_UPSTREAM_BODY"}}'
+ with self._patch_session(_response(status_code=404, json_data={"error": {"code": "404"}}, text=leaked_body)):
+ valid, msg = validate_credentials("https://x.metabaseapp.com", _api_key_auth())
+ assert valid is False
+ assert msg is not None
+ assert "SENTINEL_UPSTREAM_BODY" not in msg
+ assert "404" in msg
+
class TestMetabaseSourceResponse:
@pytest.mark.parametrize(