From c87877bb8023753614c5c1de855b145cb6544e2f Mon Sep 17 00:00:00 2001 From: cristhianzl Date: Thu, 4 Sep 2025 16:26:31 -0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20(agent.py):=20Improve=20user=20ID?= =?UTF-8?q?=20validation=20by=20checking=20if=20it=20is=20a=20Google=20num?= =?UTF-8?q?eric=20ID=20or=20a=20Langflow=20UUID=20format=20=E2=99=BB?= =?UTF-8?q?=EF=B8=8F=20(langflow=5Fhistory=5Fservice.py,=20user=5Fbinding?= =?UTF-8?q?=5Fservice.py):=20Refactor=20UUID=20format=20check=20to=20use?= =?UTF-8?q?=20a=20more=20descriptive=20and=20clear=20logic=20based=20on=20?= =?UTF-8?q?user=20ID=20type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/agent.py | 16 ++++------------ src/services/langflow_history_service.py | 8 +++----- src/services/user_binding_service.py | 8 +++----- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/src/agent.py b/src/agent.py index b8816291..07fd911e 100644 --- a/src/agent.py +++ b/src/agent.py @@ -418,12 +418,8 @@ async def async_langflow_chat( from services.session_ownership_service import session_ownership_service from services.user_binding_service import user_binding_service - # Check if this is a Google user (has binding but not UUID format) - import re - uuid_pattern = r'^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}$' - is_uuid = bool(re.match(uuid_pattern, user_id.lower().replace('-', ''))) - - if not is_uuid and user_binding_service.has_binding(user_id): + # Check if this is a Google user (Google IDs are numeric, Langflow IDs are UUID) + if user_id.isdigit() and user_binding_service.has_binding(user_id): langflow_user_id = user_binding_service.get_langflow_user_id(user_id) if langflow_user_id: session_ownership_service.claim_session(user_id, response_id, langflow_user_id) @@ -511,12 +507,8 @@ async def async_langflow_chat_stream( from services.session_ownership_service import session_ownership_service from services.user_binding_service import user_binding_service - # Check if this is a Google user (has binding but not UUID format) - import re - uuid_pattern = r'^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}$' - is_uuid = bool(re.match(uuid_pattern, user_id.lower().replace('-', ''))) - - if not is_uuid and user_binding_service.has_binding(user_id): + # Check if this is a Google user (Google IDs are numeric, Langflow IDs are UUID) + if user_id.isdigit() and user_binding_service.has_binding(user_id): langflow_user_id = user_binding_service.get_langflow_user_id(user_id) if langflow_user_id: session_ownership_service.claim_session(user_id, response_id, langflow_user_id) diff --git a/src/services/langflow_history_service.py b/src/services/langflow_history_service.py index e6e49f4d..ad17a238 100644 --- a/src/services/langflow_history_service.py +++ b/src/services/langflow_history_service.py @@ -44,11 +44,9 @@ class LangflowHistoryService: return None def _is_uuid_format(self, user_id: str) -> bool: - """Check if string looks like a UUID (Langflow user ID format)""" - import re - # Basic UUID pattern check (with or without dashes) - uuid_pattern = r'^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}$' - return bool(re.match(uuid_pattern, user_id.lower().replace('-', ''))) + """Check if string looks like a UUID (Langflow user ID format vs Google numeric ID)""" + # Langflow IDs are UUID v4, Google IDs are purely numeric + return not user_id.isdigit() def _filter_sessions_by_ownership(self, session_ids: List[str], user_id: str, langflow_user_id: str) -> List[str]: """Filter sessions based on user type and ownership""" diff --git a/src/services/user_binding_service.py b/src/services/user_binding_service.py index 4cead0aa..b7bbe905 100644 --- a/src/services/user_binding_service.py +++ b/src/services/user_binding_service.py @@ -237,11 +237,9 @@ class UserBindingService: return self.bindings.copy() def is_langflow_user_id(self, user_id: str) -> bool: - """Check if user_id appears to be a Langflow UUID""" - import re - # Basic UUID pattern check (with or without dashes) - uuid_pattern = r'^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}$' - return bool(re.match(uuid_pattern, user_id.lower().replace('-', ''))) + """Check if user_id appears to be a Langflow UUID (vs Google numeric ID)""" + # Langflow IDs are UUID v4, Google IDs are purely numeric + return not user_id.isdigit() def get_user_type(self, user_id: str) -> str: """Determine user type: 'google_oauth', 'langflow_direct', or 'unknown'"""