: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
feat(llm-gateway): drop the desktop app ids from the signals product allowlist (#84630)
Georgiy Tarasov85faddded9e7
diff --git a/posthog/temporal/oauth.py b/posthog/temporal/oauth.pyindex c173c8d784a5..2cf0246a6fd6 100644--- a/posthog/temporal/oauth.py+++ b/posthog/temporal/oauth.py@@ -304,8 +304,10 @@ def get_sandbox_oauth_app(application: SandboxOAuthApplication = "array") -> OAusignals_app = get_signals_app()if signals_app is not None:return signals_app- # Array still authorizes the `signals` gateway product, so the run works; it just- # isn't isolated yet. Loud enough to notice, since the isolation is the point.+ # The gateway no longer accepts Array tokens for the `signals` product, so this run's+ # inference calls will be rejected there. Minting still succeeds so the failure surfaces+ # in the run (with this log to explain it) rather than as an opaque kickoff error; the+ # real fix is provisioning the region's Signals application row.logger.warning("signals_oauth_app_missing_falling_back_to_array", region=get_instance_region())return get_array_app()diff --git a/services/llm-gateway/README.md b/services/llm-gateway/README.mdindex 04ea0e8386dc..4e7448c2031c 100644--- a/services/llm-gateway/README.md+++ b/services/llm-gateway/README.md@@ -280,7 +280,7 @@ locks an entitled user out for at most a minute after their cached grant expires`signals` is authorized for its own OAuth application, so a Signals run's token cannot be spent as `posthog_code` or `background_agents` by declaring a different product in the path.Its US, EU, and dev application ids are pinned in `products/config.py` alongside every other first-party app.-The PostHog Code application ids stay listed on `signals` until every region mints under the new app; removing them completes the isolation.+The PostHog Code application ids are no longer accepted for `signals`, so a region whose runs still mint under the Code app rejects every Signals OAuth run at the gateway.### Adding a new productdiff --git a/services/llm-gateway/src/llm_gateway/products/config.py b/services/llm-gateway/src/llm_gateway/products/config.pyindex a5c55dddde5b..272cb3f6a985 100644--- a/services/llm-gateway/src/llm_gateway/products/config.py+++ b/services/llm-gateway/src/llm_gateway/products/config.py@@ -243,19 +243,9 @@ PRODUCTS: Final[dict[str, ProductConfig]] = {allow_api_keys=True,),"signals": ProductConfig(- # Dual-accept during the app migration: the PostHog Code ids stay listed until every- # region has a Signals application row and its runs mint under it. Dropping them is- # what finally makes this product unreachable from a Desktop-app token.- allowed_application_ids=frozenset(- {- POSTHOG_CODE_US_APP_ID,- POSTHOG_CODE_EU_APP_ID,- POSTHOG_CODE_DEV_APP_ID,- SIGNALS_US_APP_ID,- SIGNALS_EU_APP_ID,- SIGNALS_DEV_APP_ID,- }- ),+ # Only the dedicated Signals app: dropping the PostHog Code ids is what finally makes+ # this product unreachable from a Desktop-app token.+ allowed_application_ids=frozenset({SIGNALS_US_APP_ID, SIGNALS_EU_APP_ID, SIGNALS_DEV_APP_ID}),allowed_models=None, # any model — the signals pipeline picks models per stage (haiku, sonnet, ...)allow_api_keys=True,credit_bucket=None,diff --git a/services/llm-gateway/tests/test_dependencies.py b/services/llm-gateway/tests/test_dependencies.pyindex 73f01480f70b..76498978f447 100644--- a/services/llm-gateway/tests/test_dependencies.py+++ b/services/llm-gateway/tests/test_dependencies.py@@ -23,7 +23,7 @@ from llm_gateway.dependencies import (get_request_json,resolve_plan_and_quota,)-from llm_gateway.products.config import POSTHOG_CODE_US_APP_ID+from llm_gateway.products.config import POSTHOG_CODE_US_APP_ID, SIGNALS_DEV_APP_IDfrom llm_gateway.rate_limiting.cost_throttles import SandboxTaskCostThrottlefrom llm_gateway.rate_limiting.throttles import ThrottleContext, ThrottleResultfrom llm_gateway.services.plan_resolver import PlanInfo@@ -512,6 +512,7 @@ class TestBasetenExclusiveModelGateWiring:class TestServerCredentialRequirementWiring:+ # The signals path only accepts the Signals app now, so the marker wiring is pinned with itdef _oauth_user(self, scopes: list[str]) -> AuthenticatedUser:return AuthenticatedUser(user_id=7,@@ -519,7 +520,7 @@ class TestServerCredentialRequirementWiring:auth_method="oauth_access_token",distinct_id="test-distinct-id-7",scopes=scopes,- application_id=POSTHOG_CODE_US_APP_ID,+ application_id=SIGNALS_DEV_APP_ID,)@pytest.mark.asynciodiff --git a/services/llm-gateway/tests/test_product_config.py b/services/llm-gateway/tests/test_product_config.pyindex be6814115507..66de511568d1 100644--- a/services/llm-gateway/tests/test_product_config.py+++ b/services/llm-gateway/tests/test_product_config.py@@ -138,14 +138,15 @@ class TestCheckProductAccess:("llma_translation", "personal_api_key", None, "gpt-4.1-mini", True, None),("llma_translation", "personal_api_key", None, "claude-3-opus", False, "not allowed"),("llma_translation", "oauth_access_token", "any-app-id", "gpt-4.1-mini", False, "not authorized"),- # signals allows API keys (shared gateway key) with any model, and OAuth from the- # array/twig (posthog_code) app for coding-agent tasks+ # signals allows API keys (shared gateway key) with any model, and OAuth only from+ # the dedicated Signals app — a posthog_code (Desktop) token must not reach it("signals", "personal_api_key", None, "claude-haiku-4-5", True, None),("signals", "personal_api_key", None, "claude-sonnet-4-5", True, None),("signals", "personal_api_key", None, "claude-3-opus", True, None),("signals", "oauth_access_token", "any-app-id", "claude-haiku-4-5", False, "not authorized"),- ("signals", "oauth_access_token", POSTHOG_CODE_US_APP_ID, "claude-haiku-4-5", True, None),- ("signals", "oauth_access_token", POSTHOG_CODE_EU_APP_ID, "claude-sonnet-4-5", True, None),+ ("signals", "oauth_access_token", SIGNALS_DEV_APP_ID, "claude-haiku-4-5", True, None),+ ("signals", "oauth_access_token", POSTHOG_CODE_US_APP_ID, "claude-haiku-4-5", False, "not authorized"),+ ("signals", "oauth_access_token", POSTHOG_CODE_EU_APP_ID, "claude-sonnet-4-5", False, "not authorized"),# conversations: utility prompts (API key) and support-reply sandbox (array OAuth app)("conversations", "personal_api_key", None, "claude-haiku-4-5", True, None),("conversations", "personal_api_key", None, "claude-sonnet-4-6", True, None),@@ -623,27 +624,34 @@ class TestCheckFreeTierModelAccess:class TestServerCredentialRequirement:- """The internal products that share the PostHog Desktop OAuth app (background_agents, signals,- slack_app, conversations, onboarding) must accept only server-minted tokens — those carrying the- internal `internal_run:read` marker. Otherwise a user's own Desktop OAuth token could route around- the posthog_code free-tier gate through these products to premium models."""+ """Internal products driven by server-minted sandbox tokens (background_agents, signals,+ slack_app, conversations, onboarding) must accept only tokens carrying the internal+ `internal_run:read` marker. Otherwise a user's own OAuth token minted under the same app could+ route around the posthog_code free-tier gate through these products to premium models."""_MARKER_SCOPES = ["llm_gateway:read", "task:write", "internal_run:read"]- @pytest.mark.parametrize("product", ["background_agents", "signals", "slack_app", "conversations", "onboarding"])- def test_oauth_without_marker_is_rejected(self, product: str):- # a desktop Code token (wildcard scope, no internal marker); claude-sonnet-5 is in every+ # signals no longer accepts the Desktop app, so the marker check is exercised via its own app+ _PRODUCT_APPS = [+ ("background_agents", POSTHOG_CODE_US_APP_ID),+ ("signals", SIGNALS_DEV_APP_ID),+ ("slack_app", POSTHOG_CODE_US_APP_ID),+ ("conversations", POSTHOG_CODE_US_APP_ID),+ ("onboarding", POSTHOG_CODE_US_APP_ID),+ ]++ @pytest.mark.parametrize(("product", "app_id"), _PRODUCT_APPS)+ def test_oauth_without_marker_is_rejected(self, product: str, app_id: str):+ # a user-held token (wildcard scope, no internal marker); claude-sonnet-5 is in every# sibling's model list, so the rejection is unambiguously the missing server credential- allowed, error = check_product_access(- product, "oauth_access_token", POSTHOG_CODE_US_APP_ID, "claude-sonnet-5", scopes=["*"]- )+ allowed, error = check_product_access(product, "oauth_access_token", app_id, "claude-sonnet-5", scopes=["*"])assert allowed is Falseassert error is not None and "server-minted" in error- @pytest.mark.parametrize("product", ["background_agents", "signals", "slack_app", "conversations", "onboarding"])- def test_oauth_with_marker_is_allowed(self, product: str):+ @pytest.mark.parametrize(("product", "app_id"), _PRODUCT_APPS)+ def test_oauth_with_marker_is_allowed(self, product: str, app_id: str):allowed, error = check_product_access(- product, "oauth_access_token", POSTHOG_CODE_US_APP_ID, "claude-sonnet-5", scopes=self._MARKER_SCOPES+ product, "oauth_access_token", app_id, "claude-sonnet-5", scopes=self._MARKER_SCOPES)assert allowed is Trueassert error is None