: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(replay-vision): object-check the scanner on session-route label writes (#69148)
Arno Hillend999cd3bfca0
diff --git a/products/replay_vision/backend/api/observations.py b/products/replay_vision/backend/api/observations.pyindex f0b037064646..f406507a609c 100644--- a/products/replay_vision/backend/api/observations.py+++ b/products/replay_vision/backend/api/observations.py@@ -802,6 +802,9 @@ class ReplayObservationViewSet(if not is_replay_vision_quality_enabled(cast(User, request.user), self.team):raise NotFound()observation = self.get_object()+ # Label writes are scanner writes; the session route's get_object only object-checks the observation row.+ scanner = getattr(self, "_scanner_for_url_cache", None) or observation.scanner+ self.check_object_permissions(self.request, scanner)# Editing the shared label needs edit access, not just the viewer access reading needs.if not self.user_access_control.check_access_level_for_resource("session_recording", required_level="editor"):raise PermissionDenied("Editing observation labels requires session_recording edit access.")diff --git a/products/replay_vision/backend/tests/test_observation_labels_api.py b/products/replay_vision/backend/tests/test_observation_labels_api.pyindex 71172258c7ed..33c55ccd3ee7 100644--- a/products/replay_vision/backend/tests/test_observation_labels_api.py+++ b/products/replay_vision/backend/tests/test_observation_labels_api.py@@ -68,6 +68,20 @@ class TestObservationLabels(_VisionAPITestCase):self.assertEqual(delete_resp.status_code, 404, delete_resp.content)self.assertEqual(read_resp.status_code, 200, read_resp.content)+ def test_label_write_denied_without_scanner_editor_access_on_session_route(self) -> None:+ # The session route's get_object only checks the observation row; label writes must object-check the scanner.+ with patch(+ "posthog.rbac.user_access_control.UserAccessControl.check_access_level_for_object",+ side_effect=lambda obj, required_level=None, **_: not isinstance(obj, ReplayScanner),+ ):+ resp = self.client.post(+ f"/api/environments/{self.team.id}/vision/observations/{self.observation.id}/label/",+ {"is_correct": True},+ format="json",+ )+ self.assertEqual(resp.status_code, 403, resp.json())+ self.assertFalse(ReplayObservationLabel.objects.filter(observation=self.observation).exists())+def test_relabeling_updates_the_single_shared_label(self) -> None:self.client.post(self._label_url(self.observation), {"is_correct": False, "feedback": "wrong"}, format="json")self.client.post(self._label_url(self.observation), {"is_correct": True}, format="json")