cdxiaodong / dsh-guardian

Listed

The upstream repository does not provide a description.

mainModel View source

Installation

npx -y @deepseek-ai/dsh plugin --profile web add github:cdxiaodong/dsh-guardian

This installation command is an unverified starting point generated from the GitHub repository address.

README

Maintainer-authored documentation snapshot.

View on GitHub ↗
Commit c667e06Synced Aug 18, 2026

dsh-guardian

Agent 安全护栏 · 基于 Cordis 时空可组合元内核的 DeepSeek Harness 插件。 在 Agent 每次工具调用前做安全审查,命中危险即拦截或要求人工确认。

CI


🎯 解决什么问题

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/shadowmcp-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/approverm -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 通过

🙏 致谢 / 参考

本插件的规则与架构缝合自以下优秀开源方案:

⚠️ 安全认知:所有正则/启发式护栏都可能被绕过(对抗样本实测可绕过多种护栏)。本插件是 risk reducer,关键操作仍需人在环确认 + 最小权限沙箱,不能替代这两者。

📜 License

MIT

Project files and signals

Shown items are public repository signals detected in the directory snapshot.

TestsDetected

Repository information

Language
TypeScript
License
Not reported
Latest release
v0.1.1
Last updated
Aug 15, 2026, 7:23 PM

Install deliberately

Review source code, permissions, lifecycle hooks, dependencies and network access. Test untrusted plugins in an isolated environment.