dsh-plugin-mcp-guard:MCP 服务器配置静态审计

前言

在 DSH(DeepSeek Harness)中接入 MCP(Model Context Protocol)服务器后,配置会快速积累:有的用 http://,有的 permissions: ["*"],有的用 bash -c 做测试。这些设置容易在不经意间引入风险。dsh-plugin-mcp-guard 对已配置的 MCP 服务器做只读审计,在本地内存中检查风险项,不发起任何网络连接、不执行命令、不写入文件。

是什么

dsh-plugin-mcp-guard 是一个 DSH 插件,由维护者 SSHOOTING 提供,归类为 admin-security。它读取 DSH profile 中已有的 mcpServers 配置对象,按预设规则生成评分报告,只输出风险标记和分数,不与任何 MCP 服务通信、不生成子进程、不访问文件系统。

安装与启用

在 PowerShell 中执行:

dsh plugin --profile web add dsh-plugin-mcp-guard

插件依赖 DSH >=0.2.0-rc.2 <0.3.0 和 Node ^22.19.0 || >=24。

使用方法

  1. 在 profile 的 bundle row 中添加 MCP 服务器配置(见下方示例)。
  2. 在任意 DSH 会话中执行 /mcp-guard。
  3. 得到包含评分与风险标记的报告:
[mcp-guard] 2/3 audited server(s) flagged · 4 finding(s) · 1 skipped · score 0/100 · RISK
  local-dev  [http://localhost:3000]
    HIGH   insecure-url            URL uses plain http:// instead of https://
    HIGH   wildcard-auto-approve   autoApprove entry contains a wildcard: *
  shell-tool  [stdio: bash]
    HIGH   shell-invocation        command invokes a shell with -c (arbitrary command execution)
  clean-one  [https://example.com]  OK
  legacy  DISABLED (skipped)
Fix: review the flags above; prefer HTTPS, avoid wildcard permissions/autoApprove, and drop shell -c wrappers.

若需要机器可读输出,使用 /mcp-guard --json,返回的 JSON 中只包含已知字段,敏感信息会被脱敏。

配置

在 profile 的 cordis.patch.yml 中补全 mcpServers 映射。示例:

- id: dsh-plugin-mcp-guard
  name: dsh-plugin-mcp-guard
  config:
    mcpServers:
      local-dev:
        url: http://localhost:3000
        autoApprove: ['*']
      shell-tool:
        command: bash
        args: ['-c', 'echo hi']
      clean-one:
        url: https://example.com
        permissions: [read]
      legacy:
        command: node
        args: [server.js]
        disabled: true

配置项说明:

Key Type 默认值 含义
mcpServers object {} 服务器名称到配置对象的映射。
mcpServers.<name>.url string — HTTP(S) 端点,以 http:// 开头会被标记。
mcpServers.<name>.command string — stdio 可执行程序,与 url 同时缺失会被标记。
mcpServers.<name>.args string[] [] 参数,用于检测 -c / /c,不会打印。
mcpServers.<name>.permissions string[] [] 包含 * 或 all 时会被标记。
mcpServers.<name>.autoApprove boolean 或 string[] false true、包含 * 或 all/admin/root/execute 等会被标记。
mcpServers.<name>.disabled boolean false 设为 true 时跳过审计。

未知字段会被忽略,不序列化;格式错误的值会被归为空默认值,不抛出异常。

审计规则与评分

Code 严重性 触发条件
insecure-url high url 以 http:// 开头(非 https://)。
missing-endpoint low 既没有可用 url 也没有 command。
wildcard-auto-approve high autoApprove: true 或包含 *。
broad-auto-approve medium autoApprove 包含 all/admin/root/execute 等。
wildcard-permission high permissions 包含 * 或 all。
shell-invocation high cmd/sh/bash(包括 .exe 和完整路径)在参数中出现 -c 或 /c。

每条发现扣分:high 25,medium 15,low 10,分数上限 100。若存在 high 严重性发现,结论为 risk;若存在任何发现但无 high,为 review;否则为 clean。同一服务器每条代码最多出现一次。禁用的服务器会被跳过,不影响评分。

隐私与安全

  • 只读取内存中的 mcpServers 对象,不导入文件系统或进程 API。
  • 不向任何 MCP 服务器发起网络连接。
  • 不执行命令或生成子进程,command/args 仅作为字符串处理。
  • 不写入文件或发送遥测。
  • 只序列化已知字段,所有输出字符串均经过脱敏(凭证、查询参数中的密钥、CLI 标志中的密钥、URL userinfo)。

兼容性

组件 支持
DSH >=0.2.0-rc.2 <0.3.0
Node ^22.19.0 \|\| >=24.0.0
Cordis >=4.0.0 <5
Surface headless 和 web(仅命令注册)

常见问题

症状 原因 修复
/mcp-guard 未找到 bundle row 未安装 重新执行 dsh plugin --profile web add dsh-plugin-mcp-guard 并重启 DSH。
no MCP servers configured mcpServers 为空或未在 row 配置中 在 profile 的 cordis.patch.yml 中添加该映射;安装的 patch 只会初始化为空对象 {}。
某服务器显示 DISABLED (skipped) 该服务器设置了 disabled: true(或字符串 "true") 若需审计,移除该字段。
标记与预期不符 profile 的 cordis.patch.yml 覆盖了 bundle row 的配置 最后写入生效;编辑 profile 行后重启。
--json 输出为空 输出是同一份报告的格式化 JSON 使用 JSON 解析器处理;顶层字段为 servers、total、audited、skipped、flagged、findings、score、verdict。

开发与测试

npm install
npm test
npm pack --dry-run

测试完全离线:使用合成配置 fixture,不依赖模型、网络或子进程。

许可证

MIT。

总结

dsh-plugin-mcp-guard 在本地对 DSH profile 中的 MCP 服务器配置做静态审计,输出风险评分与标记,不涉及网络、命令执行或文件写入。适合需要在部署前检查配置安全性的 DSH 用户。

羽毛球分组比赛记分
小程序二维码

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

小夜