Skip to content

LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows

UN-3479 [FIX] Admin bypass on raw access helpers missed by #1989 (#1993)

Chandrasekharan Mfeb5abbbc5eb
diff --git a/backend/prompt_studio/permission.py b/backend/prompt_studio/permission.py
index 4bade8a46..8d29970e0 100644
--- a/backend/prompt_studio/permission.py
+++ b/backend/prompt_studio/permission.py
@@ -3,6 +3,7 @@ from typing import Any
from rest_framework import permissions
from rest_framework.request import Request
from rest_framework.views import APIView
+from tenant_account_v2.organization_member_service import OrganizationMemberService
class PromptAcesssToUser(permissions.BasePermission):
@@ -11,11 +12,8 @@ class PromptAcesssToUser(permissions.BasePermission):
def has_object_permission(self, request: Request, view: APIView, obj: Any) -> bool:
if getattr(request.user, "is_service_account", False):
return True
- return (
- True
- if (
- obj.tool_id.created_by == request.user
- or obj.tool_id.shared_users.filter(pk=request.user.pk).exists()
- )
- else False
- )
+ if obj.tool_id.created_by == request.user:
+ return True
+ if obj.tool_id.shared_users.filter(pk=request.user.pk).exists():
+ return True
+ return OrganizationMemberService.is_user_organization_admin(request.user)
diff --git a/backend/prompt_studio/prompt_studio_core_v2/prompt_studio_helper.py b/backend/prompt_studio/prompt_studio_core_v2/prompt_studio_helper.py
index 62cbf2d9a..c2f0b6f0e 100644
--- a/backend/prompt_studio/prompt_studio_core_v2/prompt_studio_helper.py
+++ b/backend/prompt_studio/prompt_studio_core_v2/prompt_studio_helper.py
@@ -16,6 +16,7 @@ from django.db.models.manager import BaseManager
from plugins import get_plugin
from rest_framework.exceptions import APIException
from rest_framework.request import Request
+from tenant_account_v2.organization_member_service import OrganizationMemberService
from utils.file_storage.constants import FileStorageKeys
from utils.file_storage.helpers.prompt_studio_file_helper import PromptStudioFileHelper
from utils.local_context import StateStore
@@ -189,7 +190,9 @@ class PromptStudioHelper:
"""
profile_manager_owner = profile_manager.created_by
if profile_manager_owner is None:
- # No owner on this profile manager — skip ownership validation
+ return
+
+ if OrganizationMemberService.is_user_organization_admin(profile_manager_owner):
return
is_llm_owned = (
diff --git a/backend/tool_instance_v2/tool_instance_helper.py b/backend/tool_instance_v2/tool_instance_helper.py
index 08f425f74..5fbf983dc 100644
--- a/backend/tool_instance_v2/tool_instance_helper.py
+++ b/backend/tool_instance_v2/tool_instance_helper.py
@@ -10,6 +10,7 @@ from django.core.exceptions import PermissionDenied
from django.core.exceptions import ValidationError as DjangoValidationError
from jsonschema.exceptions import ValidationError as JSONValidationError
from prompt_studio.prompt_studio_registry_v2.models import PromptStudioRegistry
+from tenant_account_v2.organization_member_service import OrganizationMemberService
from workflow_manager.workflow_v2.constants import WorkflowKey
from tool_instance_v2.constants import JsonSchemaKey
@@ -482,6 +483,7 @@ class ToolInstanceHelper:
adapter_ids: set[str],
) -> None:
adapter_instances = AdapterInstance.objects.filter(id__in=adapter_ids).all()
+ is_admin = OrganizationMemberService.is_user_organization_admin(user)
for adapter_instance in adapter_instances:
if not adapter_instance.is_usable:
@@ -494,7 +496,8 @@ class ToolInstanceHelper:
raise PermissionDenied(error_msg)
if not (
- adapter_instance.shared_to_org
+ is_admin
+ or adapter_instance.shared_to_org
or adapter_instance.created_by == user
or adapter_instance.shared_users.filter(pk=user.pk).exists()
):
@@ -521,11 +524,15 @@ class ToolInstanceHelper:
Raises:
PermissionDenied: If user doesn't have access to the tool
"""
+ is_admin = OrganizationMemberService.is_user_organization_admin(user)
+
# Try to find the tool in PromptStudioRegistry first
try:
prompt_registry_tool = PromptStudioRegistry.objects.get(pk=tool_uid)
if (
- prompt_registry_tool.shared_to_org
+ is_admin
+ or prompt_registry_tool.created_by == user
+ or prompt_registry_tool.shared_to_org
or prompt_registry_tool.shared_users.filter(pk=user.pk).exists()
):
return
@@ -543,7 +550,9 @@ class ToolInstanceHelper:
try:
agentic_registry_tool = AgenticStudioRegistry.objects.get(pk=tool_uid)
if (
- agentic_registry_tool.shared_to_org
+ is_admin
+ or agentic_registry_tool.created_by == user
+ or agentic_registry_tool.shared_to_org
or agentic_registry_tool.shared_users.filter(pk=user.pk).exists()
):
return
diff --git a/backend/workflow_manager/workflow_v2/permissions.py b/backend/workflow_manager/workflow_v2/permissions.py
index 8d3843515..3d957b6ea 100644
--- a/backend/workflow_manager/workflow_v2/permissions.py
+++ b/backend/workflow_manager/workflow_v2/permissions.py
@@ -1,5 +1,6 @@
from django.shortcuts import get_object_or_404
from rest_framework.permissions import BasePermission
+from tenant_account_v2.organization_member_service import OrganizationMemberService
from workflow_manager.workflow_v2.models.workflow import Workflow
@@ -35,11 +36,11 @@ class IsWorkflowOwnerOrShared(BasePermission):
workflow = request._workflow_cache
user = request.user
- # Check access: owner OR shared user OR shared to organization
has_access = (
workflow.created_by == user
or user in workflow.shared_users.all()
or (workflow.shared_to_org and workflow.organization == user.organization)
+ or OrganizationMemberService.is_user_organization_admin(user)
)
return has_access