openclaw security 提供安全审计和可选的自动修复功能。

audit 命令

openclaw security audit           # 冷路径:仅读取配置/文件系统
openclaw security audit --deep    # 包含 Gateway 实时探测和插件安全收集器
openclaw security audit --fix     # 应用安全修复
openclaw security audit --json    # 机器可读输出,适合 CI

审计检测范围

  • DM 共享会话:多个 DM 发送者共享主 session 时,建议启用 session.dmScope="per-channel-peer"
  • 小模型风险:<=300B 模型未沙箱化且启用 web/browser 工具时告警
  • Webhook 安全:检测 hooks.token 复用 Gateway token、路径为 /、allowedAgentIds 无限制等
  • 沙箱配置:Docker 网络模式 host/container:*、缺失 cdpSourceRange 等
  • 插件工具:npm 插件未固定版本、完整性元数据缺失、版本漂移
  • 认证模式:gateway.auth.mode="none" 时 HTTP API 无保护
  • mDNS 泄露:discovery.mdns.mode="full" 会通过 TXT 记录泄露元数据

JSON 输出用于 CI

openclaw security audit --json | jq '.summary'
openclaw security audit --deep --json | jq '.findings[] | select(.severity=="critical") | .checkId'
openclaw security audit --fix --json | jq '{fix: .fix.ok, summary: .report.summary}'

—fix 修复内容

--fix 执行安全、确定性的修复:

  • 将 groupPolicy="open" 改为 "allowlist"
  • 将 logging.redactSensitive 从 "off" 改为 "tools"
  • 收紧 state/config 及敏感文件权限(credentials/*.json、auth-profiles.json、sessions.json)
  • POSIX 使用 chmod,Windows 使用 icacls

--fix 不会:轮换 token/密码/API key、禁用工具、修改 gateway 网络暴露配置。

SecretRef 行为

  • security audit 以只读模式解析 SecretRef
  • SecretRef 不可用时,audit 继续并报告 secretDiagnostics,不会崩溃
  • --token 和 --password 仅对当次命令生效,不修改配置

相关链接

  • cli-secrets — Secrets 管理命令
  • docs/gateway/security — 安全配置指南