@dcrays/dsh-security-plugin 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +96 -0
- package/package.json +3 -2
package/README.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# dsh-security-plugin
|
|
2
|
+
|
|
3
|
+
DeepSeek Harness(dsh)安全防护插件。为 dsh profile 提供运行时安全闸门:危险命令分级拦截、敏感信息全链路脱敏、数据安全问题统一话术、危险文件写入审批、插件自保护与操作审计。
|
|
4
|
+
|
|
5
|
+
能力与 [@dcrays/mobook-security-plugin](https://www.npmjs.com/package/@dcrays/mobook-security-plugin)(OpenClaw/墨宝版)对齐。
|
|
6
|
+
|
|
7
|
+
## 能力
|
|
8
|
+
|
|
9
|
+
| # | 能力 | 机制 | 说明 |
|
|
10
|
+
|---|------|------|------|
|
|
11
|
+
| 1 | **危险命令分级拦截** | `tools/pre-execute` | 30+ 规则覆盖破坏性命令、权限提升、反弹 Shell、数据外传、关闭安全服务、清除历史/日志、挖矿程序;CRITICAL/HIGH 拦截,MEDIUM 放行仅告警 |
|
|
12
|
+
| 2 | **敏感信息脱敏** | `tools/post-execute` + `llm/stream` | 工具结果与模型输出双侧脱敏:身份证(GB11643 校验)、银行卡(Luhn 校验)、手机号、邮箱、API Key(sk-)、AWS AccessKey、GitHub Token、密码/密钥字段、内网 IP |
|
|
13
|
+
| 3 | **安全话术条件注入** | `systemPrompt.section` | 意图命中才注入统一回复规则,未命中零 token 消耗 |
|
|
14
|
+
| 4 | **文件写入审批** | `tools/pre-execute` | 按 `ask`(弹窗审批)/`deny`(直接拒绝)两种模式拦截对启动持久化、凭证文件、供应链配置、系统路径的写入;路径归一化防 `/private` 等别名绕过,支持白名单 |
|
|
15
|
+
| 5 | **插件自保护** | `tools/pre-execute` | 禁止删除/卸载/关闭安全插件、禁止篡改其 loader 配置 |
|
|
16
|
+
| 6 | **审计日志** | — | `<logDir>/security.log`(全量)+ `alerts.log`(仅告警) |
|
|
17
|
+
|
|
18
|
+
**失败策略**:所有监听器异常一律降级放行(绝不打断 agent 主循环)并记日志。脱敏只做文本替换,绝不重建结构、绝不丢弃 tool-call chunk——保证长任务不断链。
|
|
19
|
+
|
|
20
|
+
## 安装
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
dsh plugin --profile tui add @dcrays/dsh-security-plugin
|
|
24
|
+
dsh plugin --profile headless add @dcrays/dsh-security-plugin
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
> dsh 的 plugin 子命令本质是向 profile 目录转发 pnpm add。`tui`/`headless` 换成你实际使用的 profile 名。
|
|
28
|
+
|
|
29
|
+
## 配置
|
|
30
|
+
|
|
31
|
+
插件不写配置也有全量默认值。要显式启用/调整,编辑对应 profile 的 `~/.dsh/profiles/<name>/cordis.patch.yml`,追加:
|
|
32
|
+
|
|
33
|
+
```yaml
|
|
34
|
+
- insert:
|
|
35
|
+
- id: dsh-security
|
|
36
|
+
name: dsh-security-plugin
|
|
37
|
+
config:
|
|
38
|
+
enableCommandGuard: true # 危险命令分级拦截
|
|
39
|
+
enableSanitizer: true # 敏感信息脱敏
|
|
40
|
+
enableReplyGuard: true # 安全话术条件注入
|
|
41
|
+
enableSelfProtection: true # 插件自保护
|
|
42
|
+
enableFileWriteGuard: true # 危险文件写入审批
|
|
43
|
+
fileWriteMode: ask # ask=弹窗审批 | deny=直接拒绝
|
|
44
|
+
fileWriteAllowlist: [] # 写入白名单(归一化后的绝对路径)
|
|
45
|
+
logDir: /tmp/dsh-security # 审计日志目录
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**改完必须重启 dsh**(TUI 直接退出重进),loader 才会重新组装 patch 层。
|
|
49
|
+
|
|
50
|
+
## 配置项
|
|
51
|
+
|
|
52
|
+
| 键 | 默认值 | 说明 |
|
|
53
|
+
|---|---|---|
|
|
54
|
+
| `enableCommandGuard` | `true` | 危险命令拦截开关 |
|
|
55
|
+
| `enableSanitizer` | `true` | 脱敏开关(工具结果 + 模型输出双侧) |
|
|
56
|
+
| `enableReplyGuard` | `true` | 安全话术注入开关 |
|
|
57
|
+
| `enableSelfProtection` | `true` | 自保护开关 |
|
|
58
|
+
| `enableFileWriteGuard` | `true` | 文件写入审批开关 |
|
|
59
|
+
| `fileWriteMode` | `ask` | `ask`:弹窗审批(允许/拒绝);`deny`:直接拒绝 |
|
|
60
|
+
| `fileWriteAllowlist` | `[]` | 免审批路径列表,写归一化绝对路径(如 `/Users/me/notes/todo.md`) |
|
|
61
|
+
| `logDir` | `/tmp/dsh-security` | 日志目录,自动创建 |
|
|
62
|
+
|
|
63
|
+
## 验证安装
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
# 1. loader 条目存在
|
|
67
|
+
dsh --profile tui --dump-config | grep -A10 dsh-security
|
|
68
|
+
|
|
69
|
+
# 2. 重启 dsh 后看启动日志
|
|
70
|
+
tail -2 /tmp/dsh-security/security.log
|
|
71
|
+
# 期望:dsh-security-plugin v1.0.0 启动 | commandGuard=true ...
|
|
72
|
+
|
|
73
|
+
# 3. 触发一条拦截(在 dsh 会话里让模型执行)
|
|
74
|
+
# rm -rf /tmp/xxx → 应被 CRITICAL 拦截
|
|
75
|
+
# cat ~/.ssh/id_rsa → 应被 HIGH 拦截
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## 文件写入审批的类别
|
|
79
|
+
|
|
80
|
+
| 类别 | 覆盖示例 |
|
|
81
|
+
|------|---------|
|
|
82
|
+
| 启动持久化 | `~/.zshrc`、`~/.bash_profile` 等 shell rc 文件、`/etc/crontab`、`/etc/cron.*`、`~/Library/LaunchAgents`、`.git/hooks/`、`~/.ssh/`(写入即后门落点) |
|
|
83
|
+
| 凭证安全 | `~/.aws/`、`~/.kube/`、`~/.gnupg/`、`~/.docker/config.json`、`~/.dsh/settings.yaml`、`.credentials.yaml`、整个 `~/.dsh/profiles/`(dsh 配置即模型入口) |
|
|
84
|
+
| 供应链投毒 / AI 工具链劫持 | `~/.npmrc`、`~/.pypirc`、`~/.cargo/config.toml`、`~/.m2/settings.xml`、`~/.claude/settings.json`、`~/.codex/config.toml`、`~/.codex/auth.json`、`~/.openclaw/openclaw.json` |
|
|
85
|
+
| 系统完整性 | `/etc/**`、`/usr/**`、`/bin/**`、`/sbin/**`、`/boot/**`、`/opt/**`、`/System/**`、`/Library/**` 等(兜底) |
|
|
86
|
+
|
|
87
|
+
bash 旁路同样覆盖:重定向写入(`echo ... >> ~/.zshrc`)、`tee`、`sed -i`、`cp`/`mv` 目标为受保护路径时均会触发审批。路径归一化会展开 `~`/`$HOME`、折叠 `..`、展开 macOS `/private` 别名,防止绕过。
|
|
88
|
+
|
|
89
|
+
## 日志
|
|
90
|
+
|
|
91
|
+
- `<logDir>/security.log` — 全量运行日志(启动、放行、脱敏命中)
|
|
92
|
+
- `<logDir>/alerts.log` — 仅安全事件(拦截、审批、自保护触发)
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
私有包,仅限内部使用(UNLICENSED)。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcrays/dsh-security-plugin",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "DeepSeek Harness (dsh) 安全防护插件:危险命令分级拦截 | 敏感信息脱敏 | 安全问题统一话术注入 | 操作审计日志。能力与 @dcrays/mobook-security-plugin 对齐。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"./package.json": "./package.json"
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
12
|
-
"lib"
|
|
12
|
+
"lib",
|
|
13
|
+
"README.md"
|
|
13
14
|
],
|
|
14
15
|
"scripts": {
|
|
15
16
|
"test": "node test/unit.test.mjs"
|