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(vercel): remove cross-region proxy forwarding to EU (#68999)

Matt Brooker46dac9da4987
diff --git a/ee/api/vercel/test/test_vercel_proxy.py b/ee/api/vercel/test/test_vercel_proxy.py
index fb2d49731770..c5561023f485 100644
--- a/ee/api/vercel/test/test_vercel_proxy.py
+++ b/ee/api/vercel/test/test_vercel_proxy.py
@@ -325,8 +325,6 @@ class TestVercelProxyAPI(APIBaseTest):
@patch("ee.api.vercel.vercel_proxy.forward_to_vercel")
def test_proxy_handles_network_errors(self, mock_forward, mock_license):
- import requests as req
-
mock_license.return_value = self.license
mock_forward.side_effect = req.RequestException("Network error")
@@ -341,173 +339,6 @@ class TestVercelProxyAPI(APIBaseTest):
assert response.json() == {"error": "Failed to reach Vercel API"}
-@patch("ee.api.authentication.get_cached_instance_license")
-class TestVercelProxyCrossRegion(APIBaseTest):
- def setUp(self):
- super().setUp()
- self.license_key = "test_license_id::test_license_secret"
- self.license = License.objects.create(key=self.license_key, plan="enterprise", valid_until=datetime.now(UTC))
- self.unauthenticated_client = APIClient()
- self.other_org = Organization.objects.create(name="EU Org")
-
- def _create_billing_service_token(
- self,
- organization_id: str | None = None,
- audience: str = BillingServiceAuthentication.EXPECTED_AUDIENCE,
- ) -> str:
- secret = self.license_key.split("::")[1]
- exp = datetime.now(UTC) + timedelta(minutes=15)
- payload = {"exp": exp, "aud": audience}
- if organization_id is not None:
- payload["organization_id"] = organization_id
- return jwt.encode(payload, secret, algorithm="HS256")
-
- def _get_auth_headers(self, organization_id: str | None = None) -> dict:
- if organization_id is None:
- organization_id = str(self.other_org.id)
- token = self._create_billing_service_token(organization_id=organization_id)
- return {"HTTP_AUTHORIZATION": f"Bearer {token}"}
-
- @patch("ee.api.vercel.vercel_proxy.requests.post")
- @patch("ee.api.vercel.vercel_proxy.django_settings")
- def test_cross_region_proxy_to_eu_when_integration_not_found_locally(self, mock_settings, mock_post, mock_license):
- mock_license.return_value = self.license
- mock_settings.SITE_URL = "https://us.posthog.com"
- mock_settings.REGION_US_DOMAIN = "us.posthog.com"
- mock_settings.REGION_EU_DOMAIN = "eu.posthog.com"
-
- mock_eu_response = MagicMock()
- mock_eu_response.status_code = 200
- mock_eu_response.content = b'{"invoice_id": "inv_eu_123"}'
- mock_eu_response.json.return_value = {"invoice_id": "inv_eu_123"}
- mock_post.return_value = mock_eu_response
-
- response = self.unauthenticated_client.post(
- "/api/vercel/proxy/",
- {"path": "/billing/invoices", "method": "POST", "body": {"amount": 50}},
- format="json",
- **self._get_auth_headers(),
- )
-
- assert response.status_code == status.HTTP_200_OK
- assert response.json() == {"invoice_id": "inv_eu_123"}
-
- mock_post.assert_called_once()
- call_kwargs = mock_post.call_args
- assert call_kwargs.kwargs["url"] == "https://eu.posthog.com/api/vercel/proxy/"
- assert "Authorization" in call_kwargs.kwargs["headers"]
-
- @patch("ee.api.vercel.vercel_proxy.requests.post")
- @patch("ee.api.vercel.vercel_proxy.django_settings")
- def test_cross_region_returns_404_when_eu_also_returns_404(self, mock_settings, mock_post, mock_license):
- mock_license.return_value = self.license
- mock_settings.SITE_URL = "https://us.posthog.com"
- mock_settings.REGION_US_DOMAIN = "us.posthog.com"
- mock_settings.REGION_EU_DOMAIN = "eu.posthog.com"
-
- mock_eu_response = MagicMock()
- mock_eu_response.status_code = 404
- mock_eu_response.content = b'{"error": "No Vercel integration found for this organization"}'
- mock_eu_response.json.return_value = {"error": "No Vercel integration found for this organization"}
- mock_post.return_value = mock_eu_response
-
- response = self.unauthenticated_client.post(
- "/api/vercel/proxy/",
- {"path": "/billing/invoices", "method": "POST", "body": {}},
- format="json",
- **self._get_auth_headers(),
- )
-
- assert response.status_code == status.HTTP_404_NOT_FOUND
- assert response.json() == {"error": "No Vercel integration found for this organization"}
-
- @patch("ee.api.vercel.vercel_proxy.requests.post")
- @patch("ee.api.vercel.vercel_proxy.django_settings")
- def test_cross_region_returns_404_when_eu_proxy_network_error(self, mock_settings, mock_post, mock_license):
- mock_license.return_value = self.license
- mock_settings.SITE_URL = "https://us.posthog.com"
- mock_settings.REGION_US_DOMAIN = "us.posthog.com"
- mock_settings.REGION_EU_DOMAIN = "eu.posthog.com"
-
- mock_post.side_effect = req.RequestException("Connection refused")
-
- response = self.unauthenticated_client.post(
- "/api/vercel/proxy/",
- {"path": "/billing/invoices", "method": "POST", "body": {}},
- format="json",
- **self._get_auth_headers(),
- )
-
- assert response.status_code == status.HTTP_404_NOT_FOUND
- assert response.json() == {"error": "No Vercel integration found for this organization"}
-
- def test_cross_region_not_attempted_in_eu_region(self, mock_license):
- mock_license.return_value = self.license
-
- with patch("ee.api.vercel.vercel_proxy.django_settings") as mock_settings:
- mock_settings.SITE_URL = "https://eu.posthog.com"
- mock_settings.REGION_US_DOMAIN = "us.posthog.com"
- mock_settings.REGION_EU_DOMAIN = "eu.posthog.com"
-
- with patch("ee.api.vercel.vercel_proxy.requests.post") as mock_post:
- response = self.unauthenticated_client.post(
- "/api/vercel/proxy/",
- {"path": "/billing/invoices", "method": "POST", "body": {}},
- format="json",
- **self._get_auth_headers(),
- )
-
- assert response.status_code == status.HTTP_404_NOT_FOUND
- mock_post.assert_not_called()
-
- def test_cross_region_not_attempted_in_dev_env(self, mock_license):
- mock_license.return_value = self.license
-
- with patch("ee.api.vercel.vercel_proxy.django_settings") as mock_settings:
- mock_settings.SITE_URL = "http://localhost:8000"
- mock_settings.REGION_US_DOMAIN = "us.posthog.com"
- mock_settings.REGION_EU_DOMAIN = "eu.posthog.com"
-
- with patch("ee.api.vercel.vercel_proxy.requests.post") as mock_post:
- response = self.unauthenticated_client.post(
- "/api/vercel/proxy/",
- {"path": "/billing/invoices", "method": "POST", "body": {}},
- format="json",
- **self._get_auth_headers(),
- )
-
- assert response.status_code == status.HTTP_404_NOT_FOUND
- mock_post.assert_not_called()
-
- @patch("ee.api.vercel.vercel_proxy.requests.post")
- @patch("ee.api.vercel.vercel_proxy.django_settings")
- def test_cross_region_forwards_auth_header(self, mock_settings, mock_post, mock_license):
- mock_license.return_value = self.license
- mock_settings.SITE_URL = "https://us.posthog.com"
- mock_settings.REGION_US_DOMAIN = "us.posthog.com"
- mock_settings.REGION_EU_DOMAIN = "eu.posthog.com"
-
- mock_eu_response = MagicMock()
- mock_eu_response.status_code = 200
- mock_eu_response.content = b'{"ok": true}'
- mock_eu_response.json.return_value = {"ok": True}
- mock_post.return_value = mock_eu_response
-
- auth_headers = self._get_auth_headers()
-
- self.unauthenticated_client.post(
- "/api/vercel/proxy/",
- {"path": "/billing/invoices", "method": "POST", "body": {}},
- format="json",
- **auth_headers,
- )
-
- call_kwargs = mock_post.call_args.kwargs
- assert call_kwargs["headers"]["Authorization"] == auth_headers["HTTP_AUTHORIZATION"]
- assert call_kwargs["json"]["path"] == "/billing/invoices"
- assert call_kwargs["json"]["method"] == "POST"
-
-
@patch("ee.api.authentication.get_cached_instance_license")
class TestBillingServiceAuthentication(BaseTest):
def setUp(self):
diff --git a/ee/api/vercel/vercel_proxy.py b/ee/api/vercel/vercel_proxy.py
index 9af9f2febe5a..f464ed22818e 100644
--- a/ee/api/vercel/vercel_proxy.py
+++ b/ee/api/vercel/vercel_proxy.py
@@ -1,8 +1,6 @@
import urllib.parse
from typing import Any, cast
-from django.conf import settings as django_settings
-
import requests
import structlog
from rest_framework import serializers, status, viewsets
@@ -31,10 +29,6 @@ ALLOWED_VERCEL_PATH_PREFIXES = (
VERCEL_API_BASE_URL = "https://api.vercel.com"
REQUEST_TIMEOUT_SECONDS = 30
-CROSS_REGION_PROXY_TIMEOUT_SECONDS = 10
-
-DEFAULT_US_DOMAIN = "us.posthog.com"
-DEFAULT_EU_DOMAIN = "eu.posthog.com"
class VercelProxyRequestSerializer(serializers.Serializer):
@@ -116,10 +110,6 @@ class VercelProxyViewSet(viewsets.ViewSet):
integration = self._get_integration(organization_id)
if not integration:
- eu_response = self._try_proxy_to_eu(request)
- if eu_response is not None:
- return eu_response
-
return Response(
{"error": "No Vercel integration found for this organization"},
status=status.HTTP_404_NOT_FOUND,
@@ -134,58 +124,6 @@ class VercelProxyViewSet(viewsets.ViewSet):
return self._call_vercel(integration.integration_id, access_token, path, method, body)
- @property
- def _current_region(self) -> str | None:
- site_url = django_settings.SITE_URL
- us_domain = getattr(django_settings, "REGION_US_DOMAIN", DEFAULT_US_DOMAIN)
- eu_domain = getattr(django_settings, "REGION_EU_DOMAIN", DEFAULT_EU_DOMAIN)
- if site_url == f"https://{us_domain}":
- return "us"
- elif site_url == f"https://{eu_domain}":
- return "eu"
- return None
-
- def _try_proxy_to_eu(self, request: Request) -> Response | None:
- if self._current_region != "us":
- return None
-
- eu_domain = getattr(django_settings, "REGION_EU_DOMAIN", DEFAULT_EU_DOMAIN)
- target_url = f"https://{eu_domain}/api/vercel/proxy/"
-
- headers = {
- "Authorization": request.headers.get("authorization", ""),
- "Content-Type": "application/json",
- }
-
- try:
- response = requests.post(
- url=target_url,
- headers=headers,
- json=request.data,
- timeout=CROSS_REGION_PROXY_TIMEOUT_SECONDS,
- )
- except requests.RequestException as e:
- logger.warning(
- "Cross-region proxy to EU failed",
- error=str(e),
- )
- return None
-
- logger.info(
- "Cross-region proxy to EU completed",
- status_code=response.status_code,
- )
-
- if response.status_code == 404:
- return None
-
- try:
- data = response.json() if response.content else {}
- except ValueError:
- data = {"error": "Invalid response from EU region"}
-
- return Response(data=data, status=response.status_code)
-
def _get_integration(self, organization_id: str) -> OrganizationIntegration | None:
try:
integration = OrganizationIntegration.objects.get(