安全配置
OpenClaw 提供多层安全机制,保护你的数据和系统安全。
安全模式
沙盒模式(推荐新手)
沙盒模式限制 OpenClaw 的系统访问权限:
json
{
"security": {
"mode": "sandbox",
"allowedPaths": [
"~/Documents",
"~/Projects"
],
"allowedCommands": [
"ls",
"cat",
"git",
"npm"
]
}
}特点:
- 只能访问指定目录
- 只能执行允许的命令
- 敏感操作需要确认
- 适合新手使用
完全访问模式
完全访问模式允许 OpenClaw 完全访问系统:
json
{
"security": {
"mode": "full"
}
}警告
完全访问模式具有较高权限,请确保在受信任的环境中使用。恶意提示词可能导致数据丢失或系统损坏。
权限控制
文件系统权限
json
{
"security": {
"filesystem": {
"enabled": true,
"rules": [
{
"path": "~/Documents",
"operations": ["read", "write"],
"maxFileSize": 10485760
},
{
"path": "~/System",
"operations": [],
"deny": true
}
]
}
}
}命令执行权限
json
{
"security": {
"commands": {
"enabled": true,
"allow": [
"ls",
"cat",
"grep",
"git",
"npm",
"node"
],
"deny": [
"rm -rf /",
"sudo",
"chmod 777",
"dd if="
],
"requireConfirmation": [
"rm",
"mv",
"chmod"
]
}
}
}网络权限
json
{
"security": {
"network": {
"enabled": true,
"allowedDomains": [
"api.anthropic.com",
"api.openai.com",
"github.com"
],
"blockedDomains": [
"malicious-site.com"
],
"allowedPorts": [80, 443],
"maxRequestSize": 10485760
}
}
}敏感信息保护
API Key 管理
最佳实践:
- 使用环境变量:
bash
export OPENCLAW_MODEL_API_KEY=your-api-key- 不要硬编码:
json
// ❌ 不推荐
{
"model": {
"apiKey": "sk-ant-xxx" // 不要直接写在配置文件中
}
}
// ✅ 推荐
{
"model": {
"apiKey": "${OPENCLAW_MODEL_API_KEY}" // 使用环境变量
}
}- 使用密钥管理服务:
bash
openclaw secrets set model.apiKey日志脱敏
OpenClaw 自动对敏感信息脱敏:
json
{
"logging": {
"redaction": {
"enabled": true,
"patterns": [
"sk-[a-zA-Z0-9]+",
"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}",
"\\d{16,19}"
]
}
}
}配置快照
配置快照中的敏感信息会自动脱敏:
bash
openclaw config snapshot安全审计
操作日志
记录所有关键操作:
json
{
"audit": {
"enabled": true,
"logFile": "~/.openclaw/audit.log",
"events": [
"file.read",
"file.write",
"command.execute",
"network.request",
"skill.install"
]
}
}查看审计日志
bash
# 查看所有操作
openclaw audit logs
# 过滤特定事件
openclaw audit logs --filter "file.write"
# 导出日志
openclaw audit export --format json安全报告
生成安全报告:
bash
openclaw security report会话安全
会话超时
json
{
"session": {
"timeout": 3600,
"maxAge": 86400,
"cleanup": {
"enabled": true,
"interval": 3600
}
}
}会话隔离
不同用户/渠道的会话相互隔离:
json
{
"session": {
"isolation": true,
"strictMode": true
}
}HTTPS 配置
启用 HTTPS
json
{
"server": {
"https": {
"enabled": true,
"cert": "/path/to/cert.pem",
"key": "/path/to/key.pem"
}
}
}使用 Let's Encrypt
bash
openclaw ssl apply --domain your-domain.com安全标头
2026.2.23 版本新增 HTTP 安全标头:
json
{
"server": {
"securityHeaders": {
"strictTransportSecurity": true,
"contentSecurityPolicy": true,
"xFrameOptions": "DENY",
"xContentTypeOptions": true
}
}
}技能安全
技能权限审核
安装技能前审核其权限:
bash
openclaw skills audit <skill-name>可信技能源
配置可信的技能来源:
json
{
"skills": {
"trustedSources": [
"clawhub.ai",
"github.com/openclaw"
],
"allowUnverified": false
}
}技能沙盒
在沙盒环境中运行不受信任的技能:
json
{
"skills": {
"sandbox": {
"enabled": true,
"limits": {
"memory": "512M",
"cpu": "50%",
"timeout": 30000
}
}
}
}浏览器安全
SSRF 防护
2026.2.23 版本优化了 SSRF 防护:
json
{
"browser": {
"ssrf": {
"mode": "trusted-network",
"allowedIPs": [],
"blockedIPs": [
"127.0.0.0/8",
"10.0.0.0/8",
"172.16.0.0/12",
"192.168.0.0/16"
]
}
}
}迁移旧配置
bash
openclaw doctor --fix磁盘配额
防止存储溢出:
json
{
"storage": {
"quota": {
"enabled": true,
"maxSize": "10GB",
"maxFiles": 100000,
"cleanup": {
"enabled": true,
"maxAge": 2592000
}
}
}
}安全检查清单
定期运行安全检查:
bash
openclaw security check检查项目:
- [ ] 是否使用 HTTPS
- [ ] API Key 是否安全存储
- [ ] 是否有未授权的技能
- [ ] 权限配置是否合理
- [ ] 日志是否定期清理
- [ ] 是否启用审计
安全最佳实践
1. 最小权限原则
只授予必要的权限:
json
{
"security": {
"mode": "sandbox",
"allowedPaths": ["~/Documents"],
"allowedCommands": ["ls", "cat"]
}
}2. 定期更新
保持 OpenClaw 和技能最新:
bash
npm update -g openclaw
openclaw skills update3. 监控异常
关注异常操作:
bash
openclaw logs --level warn4. 备份数据
定期备份配置和数据:
bash
openclaw backup create5. 安全意识
- 不要执行不信任的提示词
- 不要安装来源不明的技能
- 定期检查权限设置