: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: v-312 (#60801)
Alex V70ee41efb1f8
diff --git a/products/conversations/backend/api/tests/test_widget.py b/products/conversations/backend/api/tests/test_widget.pyindex fece84b1996d..93116de29f1e 100644--- a/products/conversations/backend/api/tests/test_widget.py+++ b/products/conversations/backend/api/tests/test_widget.py@@ -115,6 +115,32 @@ class TestWidgetAPI(BaseTest):self.assertEqual(response.status_code, status.HTTP_200_OK)self.assertEqual(response.json()["ticket_id"], str(ticket.id))+ def test_unverified_request_cannot_repoint_ticket_distinct_id(self):+ # An anonymous (widget_session_id-only) request must not be able to overwrite an+ # existing ticket's distinct_id with another identity. Otherwise an attacker who+ # owns a ticket could re-point it at a victim's distinct_id and have it surface in+ # the victim's verified history / be linked to the victim's profile for staff.+ ticket = Ticket.objects.create_with_number(+ team=self.team,+ widget_session_id=self.widget_session_id,+ distinct_id=self.distinct_id,+ channel_source="widget",+ )+ response = self.client.post(+ "/api/conversations/v1/widget/message",+ {+ "message": "Trying to hijack identity",+ "widget_session_id": self.widget_session_id,+ "distinct_id": "[email protected]",+ "ticket_id": str(ticket.id),+ },+ **self._get_headers(),+ )+ self.assertEqual(response.status_code, status.HTTP_200_OK)++ ticket.refresh_from_db()+ self.assertEqual(ticket.distinct_id, self.distinct_id)+def test_create_message_updates_session_data_on_existing_ticket(self):ticket = Ticket.objects.create_with_number(team=self.team,diff --git a/products/conversations/backend/api/widget.py b/products/conversations/backend/api/widget.pyindex 1e68a7cd263e..5a46f940032a 100644--- a/products/conversations/backend/api/widget.py+++ b/products/conversations/backend/api/widget.py@@ -157,8 +157,9 @@ class WidgetMessageView(APIView):if ticket.widget_session_id != widget_session_id:return Response({"error": "Forbidden"}, status=status.HTTP_403_FORBIDDEN)- # Update distinct_id if changed (anonymous → identified transition)- if ticket.distinct_id != distinct_id:+ # Only HMAC-verified requests may (re)bind a ticket's distinct_id.+ # Anonymous → identified continuity is still handled by person merging.+ if verified_distinct_id is not None and ticket.distinct_id != distinct_id:ticket.distinct_id = distinct_id# Update traits if provided