Back to home@TARS-snail

dsh-guard-sensitive-paths

Approval guard for DeepSeek Harness: write/edit/editor/bash calls touching sensitive paths (.env, .git, SSH keys, .pem) become an approval ask.

Stars
0
Language
TypeScript
Created
Sep 2, 2026
Updated
Sep 2, 2026
GitHub repo

Introduction

dsh-guard-sensitive-paths

一个 DeepSeek Harness(DSH)插件(bundle):宿主侧前置注册 tools/pre-execute 策略,把指向敏感路径的 write / edit / str_replace_editor / bash 调用,以及 read密钥类文件(SSH 私钥、.pem 证书)的读取,拦截为审批询问(ask)——命中时调用不会直接执行,而是请求用户批准;没有审批通道的自动化按失败关闭。

本插件是纯审批策略:不修改任何会话行为,只把命中敏感目标的调用变成一次审批交换。grep / glob 对同一敏感集合的搜索排除由搜索层(@deepseek-ai/dsh-tool-fs-search)始终开启地完成,与该插件的配置无关。

保护范围

类别匹配规则示例
环境变量文件路径段以 .env 开头.env.env.local
Git 元数据路径段等于 .git.git/config
SSH 私钥文件名为 id_rsa / id_ed25519(可带点号后缀)id_rsaid_ed25519.pub
证书文件名以 .pem 结尾server.pem
SSH 目录路径段等于 .ssh.ssh/id_ed25519
  • write / edit 检查 file_pathstr_replace_editor 检查 path,统一按路径段匹配(先归一化反斜杠)。
  • read 检查 file_path,但只对密钥类文件(SSH 私钥、.pem 证书)触发询问;读取 .env / .git / .ssh/config 等保持放行——把环境文件载入工具属常见合法操作,且这些路径始终被搜索层从 glob/grep 结果中排除。
  • bash命令文本按同一集合做子串扫描:命令里只要出现 .env.git/id_rsaid_ed25519*.pem.ssh/ 等名字就会触发询问。
  • 其余工具原样放行。

安装

本包符合 DSH bundle 规范:package.json 声明 dsh.bundle.patch,指向随包发布的 cordis.patch.yml(注册 id: sensitive-paths)。dsh plugin 检测到 dsh.bundle 后会自动把它追加进该 profile 的 dsh.profile.bundles 层列表,重启该 profile(如 dsh web)后生效。

从 GitHub 安装

dsh plugin --profile web add github:TARS-snail/dsh-guard-sensitive-paths

从本地目录安装(开发/自用)

dsh plugin --profile web add /path/to/dsh-guard-sensitive-paths

验证

dsh --profile web --dump-config
# 生效的配置里应能看到 id 为 sensitive-paths 的一行(name: dsh-guard-sensitive-paths)

配置

默认零配置即开启。在 profile 的 cordis.patch.yml(用户层)中按 id 覆盖:

- id: sensitive-paths
  name: dsh-guard-sensitive-paths
  config:
    sensitivePaths: false
字段类型默认说明
sensitivePathsbooleantruefalse 时守卫整体关闭:不注册任何监听器,成为空操作

工作原理

  • 守卫以 PREPEND 方式注册在监听链最前,先于任何权限授予等其它 tools/pre-execute 监听执行;命中敏感目标(含读取密钥材料)即返回 ask 决策,理由为「<tool> targets the sensitive path <target>; approval is required because it matches the sensitive-path policy」。
  • 未命中的调用经 next() 原样委托,不产生任何延迟或副作用。
  • 写/改类工具按完整敏感集(.env.git.ssh、SSH 私钥、.pem)匹配,read密钥子集(SSH 私钥、.pem)匹配,两者共享同一套 basename 规则。
  • 导出的 SENSITIVE_PATH_GLOBS 常量与搜索层的排除 globs 互为镜像,两处各自独立实现、互不依赖(守卫匹配用分段规则,搜索层匹配用 glob 排除 + 路径二次过滤)。

开发与维护

  • src/ 为源(仅类型导入 cordis / dsh-tools;运行时仅依赖 schemastery 的 z,由宿主提供)。
  • lib/ 为构建产物(tsc 输出 + 打包入口),随包发布;修改 src/ 后需重新构建并同步 lib/
  • 测试在 tests/sensitive-paths.spec.tsisSensitivePath 单测 + 真实组合下 pre-execute 返回 ask 的行为测试)。

许可证

MIT