: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(tasks): return 404 for a non-UUID sandbox environment or image id (#86487)
posthog[bot]b9b0825aae95
diff --git a/products/tasks/backend/presentation/views/api.py b/products/tasks/backend/presentation/views/api.pyindex 1bc9bf74a73a..72730477e852 100644--- a/products/tasks/backend/presentation/views/api.py+++ b/products/tasks/backend/presentation/views/api.py@@ -213,6 +213,10 @@ def _pi_cloud_runtime_disabled_response() -> Response:TASKS_PREWARM_SANDBOX_FLAG = "tasks-prewarm-sandbox"+# Detail-route lookup pattern for viewsets keyed on a UUID primary key. Keeps the router from+# matching an unknown collection path as a pk and passing a non-UUID string to the ORM.+UUID_LOOKUP_REGEX = r"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"+TASK_RUN_STREAM_KEEPALIVE_INTERVAL_SECONDS = 20.0TASK_RUN_STREAM_KEEPALIVE_EVENT_NAME = "keepalive"TASK_RUN_STREAM_KEEPALIVE_PAYLOAD = {"type": "keepalive"}@@ -3364,6 +3368,7 @@ class SandboxEnvironmentViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet)permission_classes = [IsAuthenticated, APIScopePermission]scope_object = "task"http_method_names = ["get", "post", "patch", "delete", "head", "options"]+ lookup_value_regex = UUID_LOOKUP_REGEX@extend_schema(responses={200: SandboxEnvironmentListSerializer(many=True)})def list(self, request, **kwargs):@@ -3427,6 +3432,7 @@ class SandboxCustomImageViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet)permission_classes = [IsAuthenticated, APIScopePermission]scope_object = "task"http_method_names = ["get", "post", "patch", "delete", "head", "options"]+ lookup_value_regex = UUID_LOOKUP_REGEXdef initial(self, request, *args, **kwargs):super().initial(request, *args, **kwargs)diff --git a/products/tasks/backend/tests/test_api.py b/products/tasks/backend/tests/test_api.pyindex b95fc4b3b971..d5047ab4653b 100644--- a/products/tasks/backend/tests/test_api.py+++ b/products/tasks/backend/tests/test_api.py@@ -11403,6 +11403,11 @@ class TestSandboxEnvironmentAPI(BaseTaskAPITest):self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)self.assertFalse(SandboxEnvironment.objects.filter(id=env.id).exists())+ def test_non_uuid_detail_path_returns_404(self):+ # A non-UUID id (e.g. a mistyped nested route matched as a pk) must 404, not 500.+ response = self.client.get(self.detail_url("custom_images"))+ self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)+def test_private_environment_only_visible_to_creator(self):other_user = User.objects.create_user(email="[email protected]", first_name="Other", password="password")self.organization.members.add(other_user)