: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(active-campaign): explain redirects as a likely wrong account name (#65444)
Tom Owerse5bd39ba12b3
diff --git a/posthog/temporal/data_imports/sources/active_campaign/active_campaign.py b/posthog/temporal/data_imports/sources/active_campaign/active_campaign.pyindex aa35d1b05824..68d695ae27bf 100644--- a/posthog/temporal/data_imports/sources/active_campaign/active_campaign.py+++ b/posthog/temporal/data_imports/sources/active_campaign/active_campaign.py@@ -180,4 +180,13 @@ def validate_credentials(api_url: str, api_key: str) -> tuple[bool, str | None]:return True, Noneif response.status_code in (401, 403):return False, "Invalid ActiveCampaign API URL or key"+ # A redirect from a valid account+key is never expected (the API answers directly).+ # It almost always means the account name in the URL is wrong, so the host doesn't+ # resolve to an API tenant and ActiveCampaign bounces the request to a login page.+ if response.is_redirect:+ return (+ False,+ "ActiveCampaign redirected the request, which usually means the account name in the API URL is "+ "incorrect. Check that your API URL looks like https://<youraccountname>.api-us1.com",+ )return False, f"ActiveCampaign returned an unexpected status code: {response.status_code}"diff --git a/posthog/temporal/data_imports/sources/active_campaign/tests/test_active_campaign.py b/posthog/temporal/data_imports/sources/active_campaign/tests/test_active_campaign.pyindex 7da47d293a70..18740ea523a2 100644--- a/posthog/temporal/data_imports/sources/active_campaign/tests/test_active_campaign.py+++ b/posthog/temporal/data_imports/sources/active_campaign/tests/test_active_campaign.py@@ -268,6 +268,7 @@ class TestValidateCredentials:mock_session = MockSession.return_valueresponse = MagicMock()response.status_code = status_code+ response.is_redirect = Falsemock_session.get.return_value = responsevalid, error = validate_credentials("https://acme.api-us1.com", "test-key")@@ -312,6 +313,7 @@ class TestValidateCredentials:mock_session = MockSession.return_valueresponse = MagicMock()response.status_code = 302+ response.is_redirect = Truemock_session.get.return_value = responsevalid, error = validate_credentials("https://acme.api-us1.com", "test-key")@@ -320,6 +322,30 @@ class TestValidateCredentials:assert error is not Noneassert mock_session.get.call_args.kwargs["allow_redirects"] is False+ def test_redirect_returns_actionable_account_name_message(self) -> None:+ # A redirect means the account name in the URL is likely wrong — surface that+ # instead of a bare status code.+ with (+ patch(+ "posthog.temporal.data_imports.sources.active_campaign.active_campaign.make_tracked_session"+ ) as MockSession,+ patch(+ "posthog.temporal.data_imports.sources.active_campaign.active_campaign.is_url_allowed",+ return_value=(True, None),+ ),+ ):+ mock_session = MockSession.return_value+ response = MagicMock()+ response.status_code = 302+ response.is_redirect = True+ mock_session.get.return_value = response++ valid, error = validate_credentials("https://acme.api-us1.com", "test-key")++ assert valid is False+ assert error is not None and "account name" in error+ assert "status code" not in error+class TestSsrfProtection:"""The user-supplied api_url must not be usable to reach internal/metadata hosts."""