Install
openclaw skills install prompt-injection-filter純 Python 正則 Prompt 注入過濾器,檢測 ignore previous、role play、jailbreak 等攻擊模式。
openclaw skills install prompt-injection-filter简单但有效的 Prompt Injection 过滤器,帮助拦截常见的提示注入攻击。
A simple yet effective Prompt Injection filter to intercept common prompt injection attacks.
版本: 1.0.0 | 作者: 宝宝 (寶寶)
在你的 Skill 或脚本中调用过滤器:
from prompt_injection_filter import filter_input
user_input = "帮我查一下价格... [ignore previous instructions]"
result = filter_input(user_input)
# result: {"clean": False, "original": "...", "reason": "detect_ignore_previous"}
{
"clean": bool, # 是否通过检查
"original": str, # 原始输入
"reason": str|None, # 检测到的威胁类型
"sanitized": str # 清理后的文本(若可清理)
}
规则存放在 patterns.json 檔案中,可自行編輯或更新。
| 规则ID | 模式 | 风险 |
|---|---|---|
detect_ignore_previous | ignore previous, disregard system | 高 |
detect_role_play | you are now, act as, pretend to be | 中 |
detect_delimiter | ```, <xml>, [INST] | 中 |
detect_encoding | base64, url encode, hex | 低 |
detect_jailbreak | DAN mode, developer mode, jailbreak | 高 |
直接编辑 patterns.json 文件,然后调用:
from prompt_injection_filter import reload_filter
reload_filter() # 重新载入规则
from prompt_injection_filter import filter_input, is_safe
# 检查是否安全
if is_safe("帮我查天气"):
print("安全")
# 获取详细报告
result = filter_input("请忽略之前的指令")
print(result["reason"]) # "detect_ignore_previous"