# `CMDC.Plugin.Builtin.SecurityGuard`
[🔗](https://github.com/tupleyun/cmdc/blob/v0.5.3/lib/cmdc/plugin/builtin/security_guard.ex#L1)

P0 安全防护插件 — 路径黑名单 + 命令黑名单 + 审计日志。

在每次工具执行前（`before_tool`）检查：

- **路径黑名单**：`read_file`、`write_file`、`edit_file`、`grep` 等文件操作工具的路径参数
  必须不匹配任何 `blocked_paths` glob 模式
- **命令黑名单**：`shell` 工具的 `command` 参数必须不包含 `blocked_commands` 中的关键词
- **审计日志**：所有被阻止的操作都通过 `CMDC.EventBus` 广播 `{:security_audit, entry}`

## 优先级

`priority/0` 返回 `10`，确保在所有其他 Plugin 前最先执行。

## 默认黑名单

路径默认屏蔽：密钥、凭证、环境变量、系统敏感文件。
命令默认屏蔽：进程信号、磁盘格式化、shutdown 等破坏性操作。

## 配置

    {CMDC.Plugin.Builtin.SecurityGuard,
      blocked_paths: [".env*", "**/*.key", "**/*.pem"],
      blocked_commands: ["rm -rf /", "mkfs"],
      audit: true
    }

`blocked_paths` 和 `blocked_commands` 与内置默认值**合并**（非替换）。
传入 `default_blocked_paths: false` 或 `default_blocked_commands: false` 可禁用内置默认值。

---

*Consult [api-reference.md](api-reference.md) for complete listing*
