Skip to content

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

V0.77.9 hotfix (#615)

alia3763c8fe4de
diff --git a/backend/account/custom_auth_middleware.py b/backend/account/custom_auth_middleware.py
index 966583ef5..020f5f413 100644
--- a/backend/account/custom_auth_middleware.py
+++ b/backend/account/custom_auth_middleware.py
@@ -4,6 +4,7 @@ from account.constants import Common
from django.conf import settings
from django.http import HttpRequest, HttpResponse, JsonResponse
from utils.local_context import StateStore
+from utils.user_session import UserSessionUtils
from backend.constants import RequestHeader
@@ -34,8 +35,9 @@ class CustomAuthMiddleware:
auth_service = AuthenticationService()
is_authenticated = auth_service.is_authenticated(request)
+ is_authorized = UserSessionUtils.is_authorized_path(request)
- if is_authenticated:
+ if is_authenticated and is_authorized:
StateStore.set(Common.LOG_EVENTS_ID, request.session.session_key)
response = self.get_response(request)
StateStore.clear(Common.LOG_EVENTS_ID)
diff --git a/backend/utils/user_session.py b/backend/utils/user_session.py
index 888c6c353..e3cb36d0d 100644
--- a/backend/utils/user_session.py
+++ b/backend/utils/user_session.py
@@ -1,5 +1,7 @@
from typing import Optional
+from django.conf import settings
+from django.db import connection
from django.http import HttpRequest
from tenant_account.models import OrganizationMember
from utils.constants import FeatureFlag
@@ -34,3 +36,27 @@ class UserSessionUtils:
@staticmethod
def get_organization_member_role(request: HttpRequest) -> Optional[str]:
return request.session.get("role")
+
+ @classmethod
+ def is_authorized_path(cls, request: HttpRequest) -> bool:
+ """Checks if the requested path is authorized based on the organization
+ ID of user.
+
+ Args:
+ request (HttpRequest): The HTTP request containing session data,
+ including the organization ID.
+
+ Returns:
+ bool: `True` if the path is authorized; `False` otherwise.
+ """
+
+ requested_organization_uid = connection.tenant.organization_id
+
+ # Always authorize if the organization is public
+ if requested_organization_uid == settings.PUBLIC_ORG_ID:
+ return True
+
+ # Get the session organization UID
+ session_organization_uid = cls.get_organization_id(request=request)
+
+ return requested_organization_uid == session_organization_uid