提示词审计:coding agent 正常流量被误判为 jailbreak 并硬阻断(over-defense,建议 Controversial 升级策略可配置)
环境
- sub2api v0.1.160,提示词审计功能,默认模型
sileader/qwen3guard:0.6b(Ollama 本地部署,CPU 推理) - 流量特征:网关流量几乎全部来自 coding agent(Claude Code / Codex CLI 等)
现象
启用提示词审计后,Claude Code 的上下文压缩摘要(compaction summary,客户端把长对话历史压缩成的工作总结,作为 user 消息随请求发送)被判定为 Safety: Controversial / Categories: Jailbreak,随后被策略硬升级为 critical / Block。同步阻断模式下,正常的编程请求因此被拦截。
实际案例数据:一条 65537 字符的请求(Claude Code 系统提示词 + 压缩摘要),42 个分片中 2 个摘要分片命中,scanner_scores 为 {"jailbreak": 0.5}(即模型自身给出的是"不确定"档),最终动作为 Block。
根因分析
这是两层问题的叠加:
1. 模型层(over-defense / 过度防御)
压缩摘要是典型的"指令密集"良性文本——大量 "Continue X... / Run the focused failing tests... / 嵌套引用的任务指令"。小参数 guard 模型对这类文本有已知的系统性误报倾向,学界称为 over-defense(参考 NotInject 基准与 PIGuard 论文,ACL 2025:现有 guard 模型在含攻击触发词的良性文本上准确率会跌到接近随机水平)。coding agent 的系统提示词和压缩摘要几乎全部落在这个误报区。
2. 策略层(Controversial 无条件硬升级,不可配置)
backend/internal/securityaudit/prompt_qwen3guard.go 中:
func isElevatedControversial(category string) bool {
return category == "jailbreak" || category == "pii" || category == "suicide_and_self_harm"
}
对这三类,模型输出 Controversial(score 0.5,模型自己表示不确定)会被无条件升级为 EventCritical + ActionBlock,且没有任何配置开关。模型的"拿不准"被策略放大成了硬拦截。
复现(合成样本,不含任何真实用户数据)
对 sileader/qwen3guard:0.6b 发送以下完全虚构的"压缩摘要风格"良性文本:
curl -s http://localhost:11434/v1/chat/completions -H "Content-Type: application/json" -d '{
"model": "sileader/qwen3guard:0.6b",
"messages": [{"role": "user", "content": "Continue the remaining tasks from the previous session: 1. Run the focused failing tests one at a time to separate infrastructure flakes from real business failures. 2. Perform explicit clean uninstall/install of the candidate build, then run a new full ordered 6/6 verification pass and a separate fresh-install 6/6 stability pass. Direct quotes defining where work was left: \"if focused choice passes 4/4 then full exact 6/6 and separate fresh-install stability 6/6\". If you need specific details from before compaction (like exact code snippets or error messages), read the full transcript before proceeding."}],
"temperature": 0, "max_tokens": 64, "seed": 42
}'
稳定返回:
Safety: Controversial
Categories: Jailbreak
按当前策略即 Block。真实的 Claude Code compaction 摘要触发率更高(内容更长、指令更密)。
建议
- 让 Controversial 的升级策略可配置:例如把 elevated 类别列表做成配置项,或提供"Controversial 一律降为 Warn"的开关。默认行为可以保持现状(fail-safe),但自部署且流量全是 coding agent 的管理员需要出口。
- 提供扫描来源过滤选项:允许排除 system prompt / compaction summary 等客户端固定内容,只扫最新的真实用户输入(7ed4e7e5e 的 isolate latest user prompt chunk 已经朝这个方向走了,希望能继续)。
- 文档标注:说明 0.6B 默认模型在 agent 类流量上的 over-defense 特性,帮助管理员在启用同步阻断前建立正确预期;长期可评估对 over-defense 更稳健的模型(如 PIGuard,ACL 2025)作为可选后端。
感谢这个功能的整体设计(异步/同步分离、脱敏留档、独立模块),以上只针对 agent 流量场景下的误杀问题。
审计确实太严格了,会拦截很多良性提示词