@dcrays/dsh-security-plugin
v1.3.0
Published
DeepSeek Harness (dsh) 安全防护插件(跨平台 macOS/Linux/Windows):危险命令分级拦截(Unix + PowerShell/cmd)| 敏感信息脱敏 | 安全问题统一话术注入 | 危险文件写入审批 | 操作审计日志。能力与 @dcrays/mobook-security-plugin 对齐。
Keywords
Readme
dsh-security-plugin
DeepSeek Harness(dsh)安全防护插件。v1.1.0 起跨平台:macOS / Linux / Windows(Windows 版 dsh 的 bash 工具经 pwsh -Command 执行,插件已适配 PowerShell/cmd 命令语义与 Windows 路径体系)。为 dsh profile 提供运行时安全闸门:危险命令分级拦截、敏感信息全链路脱敏、数据安全问题统一话术、危险文件写入审批、插件自保护与操作审计。
能力与 @dcrays/mobook-security-plugin(OpenClaw/墨宝版)对齐。
能力
| # | 能力 | 机制 | 说明 |
|---|------|------|------|
| 1 | 危险命令分级拦截 | tools/pre-execute | 66 规则:Unix 30 条 + Windows 36 条(PowerShell/cmd/WMIC:关 Defender、关防火墙、格式化卷、计划任务/注册表持久化、清事件日志、删卷影、凭据窃取、编码命令混淆、下载执行等);CRITICAL/HIGH 拦截,MEDIUM 放行仅告警。v1.3.0 含 /tmp 清理白名单:rm 绝对路径(/tmp/xxx)与 cd /tmp && rm -rf xxx 工作目录模式放行——路径折叠后必须严格位于 /tmp 之下,.. 穿越、变量替换、/tmp 整目录、顶层通配、审计日志目录 /tmp/dsh-security、eval/pushd/子shell 等 cwd 操纵一律维持拦截 |
| 2 | 敏感信息脱敏 | tools/post-execute + llm/stream | 工具结果与模型输出双侧脱敏:身份证(GB11643 校验)、银行卡(Luhn 校验)、手机号、邮箱、API Key(sk-)、AWS AccessKey、GitHub Token、密码/密钥字段、内网 IP |
| 3 | 安全话术条件注入 | systemPrompt.section | 意图命中才注入统一回复规则,未命中零 token 消耗 |
| 4 | 文件写入审批 | tools/pre-execute | 按 ask(弹窗审批)/deny(直接拒绝)两种模式拦截对启动持久化、凭证文件、供应链配置、系统路径的写入;路径归一化防 /private 别名、%VAR%/$env:VAR/../UNC 绕过,Windows 认 .mobook-harness 配置树与 PowerShell profile/启动文件夹/Tasks/hosts;bash 旁路覆盖 PowerShell cmdlet(Add-Content/Set-Content/Out-File/Copy-Item/Move-Item/Remove-Item)与 cmd(copy/move/del/rd)及嵌套包装 |
| 5 | 插件自保护 | tools/pre-execute | 禁止删除/卸载/关闭安全插件(Unix rm 族 + Windows Remove-Item/del/rd 族 + mobookhub CLI)、禁止篡改其目录与 harness 配置(.dsh/ 与 .mobook-harness/ 双锚点) |
| 6 | 审计日志 | — | <logDir>/security.log(全量)+ alerts.log(仅告警) |
失败策略:所有监听器异常一律降级放行(绝不打断 agent 主循环)并记日志。脱敏只做文本替换,绝不重建结构、绝不丢弃 tool-call chunk——保证长任务不断链。
安装
dsh plugin --profile tui add @dcrays/dsh-security-plugin
dsh plugin --profile headless add @dcrays/dsh-security-plugindsh 的 plugin 子命令本质是向 profile 目录转发 pnpm add。
tui/headless换成你实际使用的 profile 名。
配置
插件不写配置也有全量默认值。要显式启用/调整,编辑对应 profile 的 ~/.dsh/profiles/<name>/cordis.patch.yml,追加:
- insert:
- id: dsh-security
name: dsh-security-plugin
config:
enableCommandGuard: true # 危险命令分级拦截
enableSanitizer: true # 敏感信息脱敏
enableReplyGuard: true # 安全话术条件注入
enableSelfProtection: true # 插件自保护
enableFileWriteGuard: true # 危险文件写入审批
fileWriteMode: ask # ask=弹窗审批 | deny=直接拒绝
fileWriteAllowlist: [] # 写入白名单(归一化后的绝对路径)
logDir: /tmp/dsh-security # 审计日志目录改完必须重启 dsh(TUI 直接退出重进),loader 才会重新组装 patch 层。
配置项
| 键 | 默认值 | 说明 |
|---|---|---|
| enableCommandGuard | true | 危险命令拦截开关 |
| enableSanitizer | true | 脱敏开关(工具结果 + 模型输出双侧) |
| enableReplyGuard | true | 安全话术注入开关 |
| enableSelfProtection | true | 自保护开关 |
| enableFileWriteGuard | true | 文件写入审批开关 |
| fileWriteMode | ask | ask:弹窗审批(允许/拒绝);deny:直接拒绝 |
| fileWriteAllowlist | [] | 免审批路径列表,写归一化绝对路径(如 /Users/me/notes/todo.md) |
| logDir | POSIX: /tmp/dsh-securityWindows: %TEMP%\dsh-security | 日志目录,自动创建 |
验证安装
# 1. loader 条目存在
dsh --profile tui --dump-config | grep -A10 dsh-security
# 2. 重启 dsh 后看启动日志
tail -2 /tmp/dsh-security/security.log
# 期望:dsh-security-plugin v1.0.0 启动 | commandGuard=true ...
# 3. 触发一条拦截(在 dsh 会话里让模型执行)
# rm -rf /etc/xxx → 应被 CRITICAL 拦截
# rm -f /tmp/xxx.txt → 放行(v1.2.0 /tmp 清理白名单)
# cd /tmp && rm -rf work && mkdir work → 放行(v1.3.0 cd 工作目录模式)
# cd /tmp && rm -rf ../etc_x → 拦截(路径折叠逃出 /tmp)
# cat ~/.ssh/id_rsa → 应被 HIGH 拦截文件写入审批的类别
| 类别 | 覆盖示例 |
|------|---------|
| 启动持久化 | ~/.zshrc 等 shell rc、/etc/crontab、~/Library/LaunchAgents、.git/hooks/、~/.ssh/;Windows:启动文件夹、Documents\WindowsPowerShell/PowerShell profile、C:\Windows\System32\Tasks、hosts、~/.mobook-harness/cron/ |
| 凭证安全 | ~/.aws/、~/.kube/、~/.gnupg/、~/.docker/config.json、~/.dsh/、~/.azure/;Windows:.mobook-harness/.credentials.yaml、mobook.json、整个 profiles/、DPAPI Protect、Crypto 密钥库 |
| 供应链投毒 / AI 工具链劫持 | ~/.npmrc、~/.pypirc、~/.cargo/config.toml、~/.m2/settings.xml、~/.claude/settings.json、~/.codex/、~/.openclaw/openclaw.json;Windows:.mobook-harness/plugins/(含 snapshot.json)、uv.toml、npm 全局目录 |
| 系统完整性 | /etc/**、/usr/**、/opt/**、/System/**、/Library/** 等;Windows:C:\Windows、C:\Program Files、C:\ProgramData、UNC 系统路径(兜底) |
bash 旁路同样覆盖:重定向写入(echo ... >> ~/.zshrc)、tee、sed -i、cp/mv;PowerShell(Add-Content/Set-Content/Out-File/Copy-Item/Move-Item/Remove-Item 及别名)与 cmd(copy/move/del/rd)、powershell -Command/cmd /c 嵌套包装(≤3 层)均会解析出写目标触发审批。路径归一化展开 ~/$HOME/$env:VAR/%VAR%、折叠 ..、归一 macOS /private 别名与 Windows 盘符大小写/UNC,防止绕过。
日志
<logDir>/security.log— 全量运行日志(启动、放行、脱敏命中)<logDir>/alerts.log— 仅安全事件(拦截、审批、自保护触发)
License
私有包,仅限内部使用(UNLICENSED)。
