fix(gateway): run_message空输入守卫——空/纯空白消息绝不进LLM(2026-09-07实测:空prompt致LLM幻觉delete_project要确认/直接run_command执行python3 heredoc非危险命令绕过确认门);入口拦截覆盖generic+全通道

This commit is contained in:
ymq 2026-09-07 18:04:43 +08:00
parent bf6cb5b24a
commit 25c9e7cdb3

View File

@ -147,6 +147,18 @@ class Gateway:
from pipeline_core.agent_config import load_agent_config
from .agent_loop_v2 import AgentExecutor
# 0. 空输入守卫2026-09-07 实测安全缺陷):空/纯空白消息绝不进 LLM。
# 实测根因curl --data-urlencode 'prompt@不存在的文件' 发出空 prompt
# 空用户消息下 LLM 自由发挥——一次幻觉出 delete_project 要求确认,
# 一次直接调 run_command 执行 python3 heredoc非危险清单命令
# 不触发确认门即执行)。空输入没有任何合法意图,必须入口拦截。
if not (content or "").strip():
yield json.dumps({
"type": "error",
"message": "收到空消息(可能前端输入丢失或调用方 prompt 为空),已拒绝处理。请输入内容后重试。",
}, ensure_ascii=False) + "\n"
return
# 1. 解析项目上下文(纯通用模式跳过,不挂任何产线插件)
if generic:
ctx = {"pid": "", "pipeline_id": "", "name": "", "project_model_name": ""}