: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(review_hog): let sandbox MCP tokens open a session (#88697)
Alex Lebedev8e36460613cd
diff --git a/products/review_hog/DECISIONS.md b/products/review_hog/DECISIONS.mdindex a5eeb5f36cae..4b4b28aaa994 100644--- a/products/review_hog/DECISIONS.md+++ b/products/review_hog/DECISIONS.md@@ -3163,9 +3163,13 @@ RATE_LIMITED` (GraphQL's primary signal, invisible to the REST-shaped helper) noReviewHog sandbox session (perspectives, validation, resolution) ran with the context default of **full**PostHog MCP access — execute-sql and every write tool — while reading untrusted PR-comment text; no promptever uses more than `skill-get`/`skill-file-get`. The executor now pins `posthog_mcp_scopes` to- `REVIEW_MCP_SCOPES = ["llm_skill:read"]` at both context constructions (internal sandbox-plumbing scopes- are re-added by the resolver). A future skill that legitimately needs product data adds its specific read- scope with that feature.+ `REVIEW_MCP_SCOPES = ["llm_skill:read", "user:read"]` at both context constructions (internal sandbox-plumbing+ scopes are re-added by the resolver). `user:read` is the MCP handshake, not a data grant: the MCP server+ resolves the calling user (`/api/users/@me/`) when a session opens and refuses the connection without it.+ The pin shipped on 2026-08-13 with only `llm_skill:read`, so until 2026-08-25 every ReviewHog session+ (perspectives, blind-spot, validation, resolution) had its MCP connection refused and reviewed without its+ skill — the agents carry on without MCP instead of failing, so nothing flagged it. A future skill that+ legitimately needs product data adds its specific read scope with that feature._Same date (fix-commit provenance gate, maintainer decision):_ `commit_on_branch`'s "reachable from thebranch tip" necessarily accepts every ancestor (later turns and the author push on top mid-run), so asteered turn could echo someone's old clean commit and have every check inspect the wrong one. Thediff --git a/products/review_hog/backend/reviewer/constants.py b/products/review_hog/backend/reviewer/constants.pyindex 89f3478fa880..dba0015fc1a8 100644--- a/products/review_hog/backend/reviewer/constants.py+++ b/products/review_hog/backend/reviewer/constants.py@@ -25,8 +25,10 @@ REVIEW_INITIAL_PERMISSION_MODE = "full-access"# untrusted PR-comment text, and their only legitimate MCP use is reading their criteria skill# (skill-get / skill-file-get) — without this the context defaults to "full", handing an injectable# agent execute-sql and every write tool. Internal sandbox-plumbing scopes are re-added by the-# resolver, so this cannot break session mechanics.-REVIEW_MCP_SCOPES: list[str] = ["llm_skill:read"]+# resolver, so this cannot break session mechanics. `user:read` is the MCP handshake: the MCP+# server resolves the calling user (`/api/users/@me/`) when a session opens and refuses the whole+# connection without it, so the agent never gets `skill-get` and silently reviews without its skill.+REVIEW_MCP_SCOPES: list[str] = ["llm_skill:read", "user:read"]@dataclass(frozen=True)diff --git a/products/review_hog/backend/reviewer/tests/test_constants.py b/products/review_hog/backend/reviewer/tests/test_constants.pyindex 00562d723749..a78ba701a682 100644--- a/products/review_hog/backend/reviewer/tests/test_constants.py+++ b/products/review_hog/backend/reviewer/tests/test_constants.py@@ -1,5 +1,7 @@import pytest+from posthog.temporal.oauth import has_write_scopes, resolve_scopes+from products.review_hog.backend.reviewer.constants import (CHUNKING_MODEL,CHUNKING_REASONING_EFFORT,@@ -9,6 +11,7 @@ from products.review_hog.backend.reviewer.constants import (DEDUP_RUNTIME_ADAPTER,DEFAULT_REVIEW_ARM,REVIEW_EXPERIMENT_ARMS,+ REVIEW_MCP_SCOPES,REVIEW_MODEL,REVIEW_REASONING_EFFORT,REVIEW_RUNTIME_ADAPTER,@@ -116,3 +119,13 @@ def test_resolve_review_arm_honors_valid_assignments_and_falls_back(persisted: tuple[str | None, str | None, str | None, str | None], expected: ReviewArm) -> None:assert resolve_review_arm(*persisted) == expected+++def test_review_mcp_scopes_open_a_session_and_stay_read_only() -> None:+ # The MCP server resolves the calling user when a session opens, so a token without `user:read`+ # is refused outright and the agent runs without its skill. Lock both halves of the pin: the+ # handshake scope is present, and the token still carries no user-facing write scope.+ resolved = resolve_scopes(REVIEW_MCP_SCOPES)+ assert "user:read" in resolved+ assert "llm_skill:read" in resolved+ assert not has_write_scopes(REVIEW_MCP_SCOPES)diff --git a/products/review_hog/backend/reviewer/tests/test_executor.py b/products/review_hog/backend/reviewer/tests/test_executor.pyindex 6feb2ba74dc6..8bd590b89c29 100644--- a/products/review_hog/backend/reviewer/tests/test_executor.py+++ b/products/review_hog/backend/reviewer/tests/test_executor.py@@ -78,7 +78,7 @@ class TestRunSandboxReview:assert (context.team_id, context.user_id, context.repository) == (7, 9, "acme/app")# Least privilege: an unset scope list means "full" MCP access for a session that reads# untrusted PR-comment text — dropping this pin is a security regression.- assert context.posthog_mcp_scopes == ["llm_skill:read"]+ assert context.posthog_mcp_scopes == ["llm_skill:read", "user:read"]@parameterized.expand([@@ -144,7 +144,7 @@ class TestRunSandboxReview:assert call_kwargs["ai_stage"] == "validation-c3"assert call_kwargs["workflow_id_prefix"] == "review-pr:1:o/r:7/validate:validation-c3"# The session path builds its own context, so the least-privilege pin must hold here too.- assert call_kwargs["context"].posthog_mcp_scopes == ["llm_skill:read"]+ assert call_kwargs["context"].posthog_mcp_scopes == ["llm_skill:read", "user:read"]@parameterized.expand([