Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix(file_factory): validate upload_file_id format as UUID (#12084)

-LAN-754791efd346
diff --git a/api/factories/file_factory.py b/api/factories/file_factory.py
index 856cf62e3ed..1e1e3fb7964 100644
--- a/api/factories/file_factory.py
+++ b/api/factories/file_factory.py
@@ -1,4 +1,5 @@
import mimetypes
+import uuid
from collections.abc import Callable, Mapping, Sequence
from typing import Any, cast
@@ -119,6 +120,11 @@ def _build_from_local_file(
upload_file_id = mapping.get("upload_file_id")
if not upload_file_id:
raise ValueError("Invalid upload file id")
+ # check if upload_file_id is a valid uuid
+ try:
+ uuid.UUID(upload_file_id)
+ except ValueError:
+ raise ValueError("Invalid upload file id format")
stmt = select(UploadFile).where(
UploadFile.id == upload_file_id,
UploadFile.tenant_id == tenant_id,