cdxiaodong/dsh-guardian
项目介绍Project Overview
dsh-guardian 是 DeepSeek Harness 的安全护栏插件,基于 Cordis 内核,在 Agent 每次工具调用前做安全审查。内置五大引擎:危险命令、凭据保护、密钥泄露、SSRF 网络目标、提示注入与工具投毒,配合路径沙箱与 0~1 风险评分,按 deny/block/log 三级处置。适用于自托管 Agent 接入 shell、文件、网络场景。注意:规则属风险降级,关键操作仍需人在环确认与最小权限沙箱兜底。
dsh-guardian is a security guardrail plugin for DeepSeek Harness, built on the Cordis kernel, performing safety review before every agent tool call. It ships five detection engines—dangerous commands, credential access, secret leakage, SSRF targets, and prompt injection/tool poisoning—plus path sandboxing and a 0–1 risk score that triggers deny, block, or log actions. Use it when integrating self-hosted agents with shell, file, or network access. Caveat: rules are risk reducers, not guarantees; human-in-the-loop confirmation and least-privilege sandboxing remain essential.
请帮我了解并安装插件:【dsh-guardian】【https://github.com/cdxiaodong/dsh-guardian】
把上面这条消息直接发给当前会话里的 DSH,让它帮你了解并安装。安装命令不一定准确,发给 DSH 更稳。Send this message to DSH in your current session. CLI install commands may not be accurate across systems — DSH will figure it out for you.
或使用命令行安装(适合开发者)Or use CLI install (for developers)
命令行安装CLI Install
dsh plugin --profile web add github:cdxiaodong/dsh-guardian
把 cdxiaodong/dsh-guardian 加入你的 DSH 配置(web profile)即可启用。
READMEREADME
dsh-guardian
Agent 安全护栏 · 基于 Cordis 时空可组合元内核的 DeepSeek Harness 插件。 在 Agent 每次工具调用前做安全审查,命中危险即拦截或要求人工确认。
🎯 解决什么问题
LLM Agent(Claude Code / DeepSeek Harness)能自主执行 shell、读写文件、发网络请求。一旦被提示注入、工具投毒或模型误判带偏,可能在你不知情时 rm -rf、读取 .ssh/id_rsa、把密钥外泄到远程。本插件是一道运行时安全网:
Agent 想执行工具 → guardian/check 前置审查 → 命中规则 → 拦截 / 人工批准 → 才放行
🛡️ 五大检测引擎
| 引擎 | 检测内容 | 借鉴来源 |
|---|---|---|
| CMD/INJ 危险命令 | rm -rf、dd、mkfs、fork炸弹、反弹shell、管道执行、提权 | Sigma 规则、PayloadsAllTheThings |
| CRED 凭据保护 | 读 .ssh/.aws/.env/kubeconfig、/etc/shadow | mcp-safeguard CRED 系列 |
| SECRET 密钥泄露 | AWS/GitHub/OpenAI/Anthropic/Slack/Stripe 等 25+ 种密钥正则 + Shannon 熵过滤降误报 | gitleaks、trufflehog |
| SSRF 网络目标 | 云 metadata(169.254.169.254)、内网网段、file://、gopher:// | mcp-safeguard SS 系列 |
| PI/TP 提示注入+工具投毒 | ignore previous instructions、DAN越狱、零宽字符、HTML注释藏指令、瞒用户指令 | Rebuff、LLM Guard、Vigil |
外加:
- 路径沙箱(
guardian/path):realpath 解析 + 白名单根目录 + 编码变体解码 + 空字节截断检测——比纯正则可靠 - 风险评分引擎(
risk.ts):多信号并集概率式加权成 0~1 分,按阈值分级处置(deny/block/warn/allow)
🚦 三级处置
| 级别 | 行为 | 例子 |
|---|---|---|
deny |
直接拒绝 | 反弹shell、mkfs、读 /etc/shadow、明文密钥 |
block |
需人工确认(走 guardian/approve) |
rm -rf ~、读 .ssh、curl 上传文件 |
log |
仅记录审计 | 路径穿越、读取 shell history |
📦 安装
dsh plugin --profile web add github:cdxiaodong/dsh-guardian
🚀 用法
import { Context } from 'cordis'
import * as guardian from 'dsh-guardian'
const ctx = new Context()
ctx.plugin(guardian, {
allowedRoots: ['/home/user/workspace'], // 可选:文件访问沙箱白名单
scanSecrets: true, scanSSRF: true, // 开关各引擎
})
// ① 接入人工批准(无此监听器时 block 级默认拒绝)
ctx.on('guardian/approve', async ({ tool, rule, snippet }) => {
const ok = await confirm(`${rule.reason}:${snippet}`) // 你的 UI 弹窗
return { approved: ok }
})
// ② 工具调用前审查(同步短路)
const r = ctx.bail('guardian/check', toolName, args)
if (r && r.intercepted) throw new Error(`已拦截:${r.reason}`)
// ③ 文件访问前校验路径
const v = ctx.bail('guardian/path', filePath)
if (v && v.safe === false) throw new Error(`路径被拦截:${v.reason}`)
// ④ 查审计日志
console.log(ctx.guardian.readAudit(20))
🔧 对应论文机制
| Cordis / 时空可组合概念 | 本插件体现 |
|---|---|
| 响应式协效应(provide/inject) | provide=['guardian'] 对外提供服务;依赖 cordis 事件系统 |
| 可逆效应(Revertible Effects) | ctx.effect(() => () => stream.end()) 注册撤销函数,卸载自动关文件流、零残留 |
| 拦截机制(Intercept) | ctx.bail('guardian/check') 全局短路拦截,不改被保护组件代码 |
| 隔离机制 | 多实例可绑定独立配置/白名单 |
🧪 测试
npm ci && npm test # 19/19 通过
🙏 致谢 / 参考
本插件的规则与架构缝合自以下优秀开源方案:
- gitleaks — 密钥正则库 + 熵过滤
- trufflesecurity/trufflehog — 密钥检测器设计
- protectai/llm-guard — scanner pipeline 架构
- protectai/rebuff — 四层纵深检测思想
- deadbits/vigil-llm — 提示注入签名
- SyedAnas01/mcp-safeguard — TP/PI/SSRF/CRED 规则分类法
- SigmaHQ/sigma — 危险命令检测规则
⚠️ 安全认知:所有正则/启发式护栏都可能被绕过(对抗样本实测可绕过多种护栏)。本插件是 risk reducer,关键操作仍需人在环确认 + 最小权限沙箱,不能替代这两者。
📜 License
MIT
nexu-io/open-design
freestylefly/awesome-gpt-image-2
anywhere-labs/dsh-desktop
walkinglabs/learn-harness-engineering
awesome-dsh-plugin/awesome-dsh-plugin
MemTensor/MemOS