This commit is contained in:
meraklbz
2026-02-10 21:04:14 +08:00
parent 3aaa913d7b
commit 702571d1ef
2 changed files with 5 additions and 7 deletions
+2 -5
View File
@@ -2444,11 +2444,8 @@ async def _get_project_root(
check_cancelled() # 🔥 解压前再次检查
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
# 🔥 逐个文件解压,支持取消检查
file_list = zip_ref.namelist()
for i, file_name in enumerate(file_list):
if i % 50 == 0: # 每50个文件检查一次
check_cancelled()
zip_ref.extract(file_name, base_path)
# 🔥 Security Fix: 使用 safe_extract_zip 替代 extract,防止 Zip Slip 和软链接攻击
safe_extract_zip(zip_ref, base_path, task_id)
logger.info(f"✅ Extracted ZIP project {project.id} to {base_path}")
await emit(f"✅ ZIP 文件解压完成")
except Exception as e:
@@ -135,8 +135,9 @@ class FileReadTool(AgentTool):
)
# 安全检查:防止路径遍历
full_path = os.path.normpath(os.path.join(self.project_root, file_path))
if not full_path.startswith(os.path.normpath(self.project_root)):
# Security Fix: 使用 realpath 解析软链接,防止绕过项目根目录检查
full_path = os.path.realpath(os.path.join(self.project_root, file_path))
if not full_path.startswith(os.path.realpath(self.project_root)):
return ToolResult(
success=False,
error="安全错误:不允许访问项目目录外的文件",