Jailbreak 防护
Semantic Router 内置了 Jailbreak 检测,可识别并拦截绕过安全措施的对抗性提示。支持两种互补的检测 方法:
- BERT 分类器 — 使用微调模型快速、高精度地检测单轮攻击
- 对比嵌入 (Contrastive) — 用于捕捉多轮渐进式攻击(“温水煮青蛙”)。即单条看似无害的消息,但在连续对话中诱导模型越界。
这两种方法都存在于 signals.jailbreak 信号层中,并且可以在路由决策中通过 OR/AND 逻辑进行组合。
概述
Jailbreak 防护系统:
- 检测对抗性提示和 Jailbreak 尝试
- 拦截恶意请求,防止其到达 LLM
- 识别提示注入和操控技术
- 提供安全决策的详细说明
- 集成信号驱动决策,实现增强安全性
Jailbreak 检测类型
系统可识别以下攻击模式:
直接 Jailbreak
- 角色扮演攻击("你现在是 DAN...")
- 指令覆盖("忽略所有之前的指令...")
- 安全绕过尝试("假装你没有安全准则...")
提示注入
- 系统提示提取尝试
- 上下文操控
- 指令劫持
社会工程
- 权威冒充
- 紧迫感操控
- 虚假场景构造
配置
Jailbreak 检测现在是信号层中的一等公民信号。在 signals.jailbreak 下定义命名的 jailbreak 规则,然后在 decisions 中通过 type: "jailbreak" 引用它们。
基础 Jailbreak 防护
# router-config.yaml
# ── Prompt Guard 模型 ─────────────────────────────────────────────────────
prompt_guard:
enabled: true
use_modernbert: false
model_id: "models/mom-jailbreak-classifier"
jailbreak_mapping_path: "models/mom-jailbreak-classifier/jailbreak_type_mapping.json"
threshold: 0.7
use_cpu: true
# ── 信号 ──────────────────────────────────────────────────────────────────
signals:
jailbreak:
- name: "jailbreak_detected"
threshold: 0.7
description: "标准 Jailbreak 检测"
# ── 决策 ──────────────────────────────────────────────────────────────────
decisions:
- name: "block_jailbreak"
priority: 1000
rules:
operator: "OR"
conditions:
- type: "jailbreak"
name: "jailbreak_detected"
plugins:
- type: "fast_response"
configuration:
message: "很抱歉,该请求违反了使用政策,无法处理。"
多级灵敏度
定义不同阈值的多个 jailbreak 规则,为不同决策应用不同的灵敏度级别:
signals:
jailbreak:
# 标准灵敏度 — 捕获明显的 Jailbreak 尝试
- name: "jailbreak_standard"
threshold: 0.65
include_history: false
description: "标准灵敏度 — 捕获明显的 Jailbreak 尝试"
# 高灵敏度 — 检查完整对话历史以发现多轮攻击
- name: "jailbreak_strict"
threshold: 0.40
include_history: true
description: "高灵敏度 — 检查完整对话历史"
decisions:
# 检测到任何 jailbreak 信号时立即拦截
- name: "block_jailbreak"
priority: 1000
rules:
operator: "OR"
conditions:
- type: "jailbreak"
name: "jailbreak_standard"
- type: "jailbreak"
name: "jailbreak_strict"
plugins:
- type: "fast_response"
configuration:
message: "很抱歉,该请求违反了使用政策,无法处理。"
领域感知的 Jailbreak 防护
将 jailbreak 信号与领域信号结合,实现上下文感知的安全策略:
signals:
jailbreak:
- name: "jailbreak_standard"
threshold: 0.65
description: "标准 Jailbreak 检测"
- name: "jailbreak_strict"
threshold: 0.40
include_history: true
description: "严格 Jailbreak 检测(含完整历史)"
domains:
- name: "economics"
description: "金融和经济"
mmlu_categories: ["economics"]
- name: "general"
description: "通用查询"
mmlu_categories: ["other"]
decisions:
# 金融领域:使用完整历史的严格检测
- name: "block_jailbreak_finance"
priority: 1001
rules:
operator: "AND"
conditions:
- type: "jailbreak"
name: "jailbreak_strict"
- type: "domain"
name: "economics"
plugins:
- type: "fast_response"
configuration:
message: "您对金融服务的请求因违反政策而被拒绝。"
# 所有领域:标准 Jailbreak 检测
- name: "block_jailbreak"
priority: 1000
rules:
operator: "OR"
conditions:
- type: "jailbreak"
name: "jailbreak_standard"
plugins:
- type: "fast_response"
configuration:
message: "很抱歉,该请求违反了使用政策,无法处理。"
基于环境的策略(开发 vs 生产)
为不同环境使用不同的 jailbreak 阈值:
signals:
jailbreak:
- name: "jailbreak_relaxed"
threshold: 0.5
description: "宽松 — 减少代码/技术提示的误报"
- name: "jailbreak_strict"
threshold: 0.9
description: "严格 — 面向用户的端点,最大保护"
decisions:
# 开发环境:代码查询使用宽松阈值
- name: "code_to_dev"
priority: 100
rules:
operator: "AND"
conditions:
- type: "keyword"
name: "code_keywords"
- operator: "NOT"
conditions:
- type: "jailbreak"
name: "jailbreak_relaxed"
modelRefs:
- model: "qwen14b-dev"
# 生产环境:通用查询使用严格阈值
- name: "block_jailbreak_prod"
priority: 1000
rules:
operator: "OR"
conditions:
- type: "jailbreak"
name: "jailbreak_strict"
plugins:
- type: "fast_response"
configuration:
message: "请求因违反政策而被拦截。"
对比嵌入检测(多轮)
对比嵌入专为拦截多轮升级攻击设计。攻击者通常会发送表面无害的单条消息,通过连续多轮的铺垫,最终诱导模型执行不安全行为。