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 s3 presign url check problem, support two versions(v2,v4) (#9093)

ybalbert00157994e4a244c
diff --git a/api/core/file/message_file_parser.py b/api/core/file/message_file_parser.py
index 83059b216ee..641686bd7cd 100644
--- a/api/core/file/message_file_parser.py
+++ b/api/core/file/message_file_parser.py
@@ -198,16 +198,34 @@ class MessageFileParser:
if "amazonaws.com" not in parsed_url.netloc:
return False
query_params = parse_qs(parsed_url.query)
- required_params = ["Signature", "Expires"]
- for param in required_params:
- if param not in query_params:
+
+ def check_presign_v2(query_params):
+ required_params = ["Signature", "Expires"]
+ for param in required_params:
+ if param not in query_params:
+ return False
+ if not query_params["Expires"][0].isdigit():
return False
- if not query_params["Expires"][0].isdigit():
- return False
- signature = query_params["Signature"][0]
- if not re.match(r"^[A-Za-z0-9+/]+={0,2}$", signature):
- return False
- return True
+ signature = query_params["Signature"][0]
+ if not re.match(r"^[A-Za-z0-9+/]+={0,2}$", signature):
+ return False
+
+ return True
+
+ def check_presign_v4(query_params):
+ required_params = ["X-Amz-Signature", "X-Amz-Expires"]
+ for param in required_params:
+ if param not in query_params:
+ return False
+ if not query_params["X-Amz-Expires"][0].isdigit():
+ return False
+ signature = query_params["X-Amz-Signature"][0]
+ if not re.match(r"^[A-Za-z0-9+/]+={0,2}$", signature):
+ return False
+
+ return True
+
+ return check_presign_v4(query_params) or check_presign_v2(query_params)
except Exception:
return False