fix(aibox/skills): Batch M 波次2 路径边界收口(S2/S3/S6/S9/S10/S11/S12/S13)
- gitclient: delete 限工作区内 .git 仓库(S2);分支名白名单防选项注入(S3) - camera/screenshot: --filename 拒绝分隔符/绝对路径/父目录引用(S9/S10) - facerec: person_name 白名单(兼容中文)接入 add/remove/get-info(S11) - vision: 图片魔数白名单校验,data URL MIME 按实测类型(S12) - sftp-transfer: listdir 条目名双向过滤防恶意服务端目录逃逸(S6) - test-auto-appimage: exec_name 白名单防 sed 替换注入(S13) 测试 493 passed / 4 failed(既有平台环境项)/ 1 skipped,零回归
This commit is contained in:
1 parent
5dc5ec9af2
commit
9064750f33
8 files changed
+133
-5
No files matched your search
+27
-2
@@ -23,6 +23,27 @@ def get_api_key():
|
||||
return None
|
||||
|
||||
|
||||
def detect_image_mime(image_path):
|
||||
"""S12(审计 2026-08-20):按魔数识别真实图片类型——
|
||||
拒绝非图片文件(防任意文件读取外泄),并返回正确 MIME(此前硬编码 image/jpeg)"""
|
||||
try:
|
||||
with open(image_path, 'rb') as f:
|
||||
head = f.read(16)
|
||||
except Exception:
|
||||
return None
|
||||
if head.startswith(b'\xff\xd8\xff'):
|
||||
return 'image/jpeg'
|
||||
if head.startswith(b'\x89PNG\r\n\x1a\n'):
|
||||
return 'image/png'
|
||||
if head[:6] in (b'GIF87a', b'GIF89a'):
|
||||
return 'image/gif'
|
||||
if head.startswith(b'RIFF') and head[8:12] == b'WEBP':
|
||||
return 'image/webp'
|
||||
if head.startswith(b'BM'):
|
||||
return 'image/bmp'
|
||||
return None
|
||||
|
||||
|
||||
def encode_image_to_base64(image_path):
|
||||
"""将图片编码为base64"""
|
||||
with open(image_path, 'rb') as f:
|
||||
@@ -37,7 +58,11 @@ def analyze_image(image_path, prompt, stream=False):
|
||||
|
||||
if not os.path.exists(image_path):
|
||||
return f"❌ 错误:图片文件不存在 - {image_path}"
|
||||
|
||||
|
||||
mime = detect_image_mime(image_path)
|
||||
if not mime:
|
||||
return f"❌ 错误:文件不是有效图片(仅支持 JPEG/PNG/GIF/WebP/BMP) - {image_path}"
|
||||
|
||||
try:
|
||||
base64_image = encode_image_to_base64(image_path)
|
||||
except Exception as e:
|
||||
@@ -55,7 +80,7 @@ def analyze_image(image_path, prompt, stream=False):
|
||||
{
|
||||
"type": "image_url",
|
||||
"image_url": {
|
||||
"url": f"data:image/jpeg;base64,{base64_image}"
|
||||
"url": f"data:{mime};base64,{base64_image}"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user