: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(canvas): require task:write to request a canvas fix (#83210)
Peter Kirkhame1ef485017b6
diff --git a/products/canvas/backend/presentation/views.py b/products/canvas/backend/presentation/views.pyindex 42373afcaa42..ef02c54bb290 100644--- a/products/canvas/backend/presentation/views.py+++ b/products/canvas/backend/presentation/views.py@@ -893,7 +893,10 @@ class CanvasViewSet(TeamAndOrgViewSetMixin, viewsets.ModelViewSet):429: OpenApiResponse(description="The team's compute quota is exhausted; retry later."),},)- @action(methods=["POST"], detail=True)+ # task:write as well: the dispatched fix run executes with the creator's+ # credentials, so canvas:write alone must not be able to start or steer it —+ # consistent with the task-run endpoints themselves.+ @action(methods=["POST"], detail=True, required_scopes=["canvas:write", "task:write"])def request_fix(self, request: Request, *args: Any, **kwargs: Any) -> Response:"""Wake the canvas's authoring agent to fix a failing build or runtime error.diff --git a/products/canvas/backend/tests/test_canvas_api.py b/products/canvas/backend/tests/test_canvas_api.pyindex 2ab7a230a0fe..61dbd4e3372d 100644--- a/products/canvas/backend/tests/test_canvas_api.py+++ b/products/canvas/backend/tests/test_canvas_api.py@@ -13,8 +13,10 @@ from rest_framework.test import APIClientfrom posthog.models.activity_logging.activity_log import ActivityLogfrom posthog.models.oauth import OAuthAccessToken, OAuthApplication+from posthog.models.personal_api_key import PersonalAPIKeyfrom posthog.models.scoping import team_scopefrom posthog.models.user import User+from posthog.models.utils import generate_random_token_personal, hash_key_valuefrom posthog.temporal.oauth import ARRAY_APP_CLIENT_ID_DEVfrom products.canvas.backend import activity_visibility, build_service@@ -1325,6 +1327,25 @@ class TestCanvasErrorReports(CanvasAPIBaseTest):assert response.json()["dispatch_outcome"] == "already_queued"assert TaskRun.objects.filter(task=task).count() == 1+ def test_scoped_keys_need_task_write_to_request_a_fix(self):+ # The dispatched fix run executes with the creator's credentials, so a+ # canvas:write-only token must not be able to start or steer it.+ canvas_id, build_id, _task = self._authored_canvas()+ raw_key = generate_random_token_personal()+ PersonalAPIKey.objects.create(+ label="canvas-fix", user=self.user, secure_value=hash_key_value(raw_key), scopes=["canvas:write"]+ )+ self.client.logout()++ response = self.client.post(+ f"/api/projects/{self.team.id}/canvases/{canvas_id}/request_fix/",+ {"build_id": build_id},+ format="json",+ HTTP_AUTHORIZATION=f"Bearer {raw_key}",+ )++ assert response.status_code == status.HTTP_403_FORBIDDEN, response.json()+def test_request_fix_rejects_sandbox_callers(self):# An agent dispatching fixes to itself is a paid-run loop; the wake is# human-initiated only.