Skip to content

: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.

fix(code): isolate personal space context (#74350)

Shy Alter3c89f245a27d
diff --git a/posthog/api/file_system/file_system.py b/posthog/api/file_system/file_system.py
index cd438913d0d3..99eb9a518392 100644
--- a/posthog/api/file_system/file_system.py
+++ b/posthog/api/file_system/file_system.py
@@ -1086,6 +1086,13 @@ class DesktopFileSystemViewSet(FileSystemViewSet):
file_system_surface = "desktop"
+ def _scope_by_project(self, queryset: QuerySet) -> QuerySet:
+ queryset = super()._scope_by_project(queryset)
+ # Personal-space rows share the same path across users, so their creator
+ # is the ownership boundary even when project-level access is shared.
+ is_personal_space = Q(path="me") | Q(path__startswith="me/")
+ return queryset.filter(~is_personal_space | Q(created_by=self.request.user))
+
def _allow_delete_without_ref(self, entry: FileSystem) -> bool:
# Desktop canvases are `dashboard`-typed rows whose source lives in `meta`,
# not a backing Dashboard, so they legitimately have no ref. Delete the bare
diff --git a/posthog/api/file_system/test/test_folder_instructions.py b/posthog/api/file_system/test/test_folder_instructions.py
index d88c58468566..e12e86dda13c 100644
--- a/posthog/api/file_system/test/test_folder_instructions.py
+++ b/posthog/api/file_system/test/test_folder_instructions.py
@@ -6,7 +6,7 @@ from posthog.test.base import APIBaseTest
from rest_framework import status
from posthog.api.file_system.folder_instructions_service import FOLDER_INSTRUCTIONS_MAX_BYTES
-from posthog.models import Organization, Team
+from posthog.models import Organization, Team, User
from posthog.models.file_system.file_system import FileSystem
from posthog.models.file_system.folder_instructions import FileSystemFolderInstructions
@@ -171,6 +171,44 @@ class TestDesktopFolderInstructionsAPI(APIBaseTest):
response = self.client.patch(self._instructions_url(str(other_folder.id)), {"content": "leak"})
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND, response.json())
+ def test_me_folder_and_instructions_are_private_to_the_creator(self):
+ folder_id = self._create_desktop_folder("me")
+ self.client.patch(self._instructions_url(folder_id), {"content": "private"})
+ child = FileSystem.objects.create(
+ team=self.team,
+ path="me/private-canvas",
+ depth=2,
+ type="dashboard",
+ surface="desktop",
+ created_by=self.user,
+ )
+
+ other_user = User.objects.create_and_join(self.organization, "[email protected]", "testpass")
+ other_user.is_staff = True
+ other_user.save()
+ self.client.force_login(other_user)
+
+ listing = self.client.get(f"/api/projects/{self.team.id}/desktop_file_system/?type=folder")
+ self.assertNotIn(folder_id, [row["id"] for row in listing.json()["results"]])
+ children = self.client.get(f"/api/projects/{self.team.id}/desktop_file_system/?parent=me")
+ self.assertNotIn(str(child.id), [row["id"] for row in children.json()["results"]])
+ count = self.client.post(f"/api/projects/{self.team.id}/desktop_file_system/count_by_path?path=me")
+ self.assertNotIn(str(child.id), [row["id"] for row in count.json()["entries"]])
+ self.assertEqual(
+ self.client.get(f"/api/projects/{self.team.id}/desktop_file_system/{child.id}/").status_code,
+ status.HTTP_404_NOT_FOUND,
+ )
+ self.assertEqual(self.client.get(self._instructions_url(folder_id)).status_code, status.HTTP_404_NOT_FOUND)
+ self.assertEqual(
+ self.client.patch(self._instructions_url(folder_id), {"content": "leak"}).status_code,
+ status.HTTP_404_NOT_FOUND,
+ )
+
+ own_folder_id = self._create_desktop_folder("me")
+ self.assertNotEqual(own_folder_id, folder_id)
+ self.client.delete(f"/api/projects/{self.team.id}/desktop_file_system/{own_folder_id}/")
+ self.assertTrue(FileSystem.objects.filter(id=child.id).exists())
+
def test_personal_api_key_can_read_and_publish_instructions(self):
folder_id = self._create_desktop_folder()
key = self.create_personal_api_key_with_scopes(["file_system:write"])