: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(clickhouse): reject a URL in the host field with an actionable message (#78732)
Tom Owers12f58053cfdf
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/source.pyindex 93a51baae28f..1dc0be408c26 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/source.py@@ -62,6 +62,14 @@ GENERIC_CONNECTION_ERROR = ("your server, and that PostHog's IP addresses are allowed through any firewall.")+# A pasted URL or connection string in the host field otherwise fails DNS resolution with a+# misleading "check the spelling" message that echoes the raw value back (which can embed+# credentials). Catch it early with an actionable message that never reflects the input.+_HOST_IS_URL_ERROR = (+ "Enter just the hostname in the host field (for example, play.clickhouse.com), not a full URL or "+ "connection string. Remove any scheme (like https://) and any username, password, port, or path."+)+# A transient gateway/rate-limit response that survived the in-process connect# retries. The connection details are fine — the server is momentarily busy or# waking (idle ClickHouse Cloud services routinely 5xx the first request), so@@ -483,6 +491,9 @@ class ClickHouseSource(SimpleSource[ClickHouseSourceConfig], SSHTunnelMixin, Valif not is_ssh_valid:return is_ssh_valid, ssh_valid_errors+ if "://" in config.host:+ return False, _HOST_IS_URL_ERROR+valid_host, host_errors = self.is_database_host_valid(config.host, team_id, using_ssh_tunnel=config.ssh_tunnel.enabled if config.ssh_tunnel else False)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/test_clickhouse.py b/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/test_clickhouse.pyindex 4e4447d1caa2..1839638dbcd1 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/test_clickhouse.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/test_clickhouse.py@@ -1097,6 +1097,26 @@ class TestSourceClassValidateCredentials:assert valid is Falseassert msg == "Invalid user or password"+ def test_url_in_host_field_returns_actionable_message_without_reflecting_input(self):+ from products.warehouse_sources.backend.temporal.data_imports.sources.clickhouse import source as source_module++ source = source_module.ClickHouseSource()++ config = MagicMock()+ config.host = "https://secret.clickhouse.cloud"+ config.ssh_tunnel = None++ with patch.object(source, "ssh_tunnel_is_valid", return_value=(True, None)):+ with patch.object(source, "is_database_host_valid") as host_valid:+ valid, msg = source.validate_credentials(config, team_id=1)++ assert valid is False+ assert "Enter just the hostname" in (msg or "")+ # The pasted value can embed credentials — it must never be echoed back.+ assert "secret.clickhouse.cloud" not in (msg or "")+ # Short-circuits before we attempt DNS resolution of the bad host.+ host_valid.assert_not_called()+def test_returns_generic_message_for_unknown_error(self):from products.warehouse_sources.backend.temporal.data_imports.sources.clickhouse import source as source_modulefrom products.warehouse_sources.backend.temporal.data_imports.sources.clickhouse.clickhouse import (