fix(v3): T30 安全加固(Mimosa 深度扫描驱动)
- 路径参数 ID 白名单(runs/agent/sessions),杀灭 Windows 反斜杠穿越(..%5C 直读 .env) - artifacts 端点关押 + pipeline 工件名消毒(模型输出名剥路径成分) - /llama/download dest 关押 models/ 内 + URL 协议白名单(先于 HF 别名转换) - GET /config architect.api_key 打码(api_key_set + 前 6 位),PUT 空串=保留 - TrustedHostMiddleware 信任围栏(GATEWAY_TRUSTED_HOSTS 可覆盖)+ __main__ 默认 127.0.0.1 - review 抽样改 CSPRNG - 新增 tests/test_security_hardening.py(13 项,全部离线)
This commit is contained in:
@@ -323,6 +323,15 @@ class LlamaManager:
|
||||
"""
|
||||
import httpx
|
||||
|
||||
# URL 协议白名单:只允许 http/https(file://、ftp:// 等一律拒绝)。
|
||||
# 必须先于 HF 别名转换判定,否则 ftp:// 会被误拼成 HF 地址。
|
||||
if "://" in url:
|
||||
scheme = url.split("://", 1)[0].lower()
|
||||
if scheme not in ("http", "https"):
|
||||
prog = DownloadProgress(url=url, dest=str(dest or ""),
|
||||
error=f"仅允许 http/https 下载地址(收到 {scheme})")
|
||||
return prog
|
||||
|
||||
# 路径别名转换
|
||||
if not url.startswith("http"):
|
||||
url = f"https://huggingface.co/{url}/resolve/main"
|
||||
@@ -334,6 +343,15 @@ class LlamaManager:
|
||||
|
||||
if dest:
|
||||
dest_path = Path(dest)
|
||||
# 目标关押:自定义 dest 必须仍位于 models/ 目录内(防 ../ 越界写盘)
|
||||
models_root = MODELS_DIR.resolve()
|
||||
resolved = (models_root / dest_path).resolve() if not dest_path.is_absolute() \
|
||||
else dest_path.resolve()
|
||||
if resolved != models_root and models_root not in resolved.parents:
|
||||
prog = DownloadProgress(url=url, dest=str(dest_path),
|
||||
error=f"下载目标必须在 models/ 目录内: {dest}")
|
||||
return prog
|
||||
dest_path = resolved
|
||||
else:
|
||||
dest_path = MODELS_DIR / filename
|
||||
|
||||
|
||||
Reference in New Issue
Block a user