---
name: runtime-security-guard
version: 2.1.0
description: 企业级 AI 运行时安全防护技能 v2.1。提供 406+ 条安全规则，支持跨平台检测（Windows/macOS/Linux），检测 9 大类安全威胁。完全本地运行，无云端 API，无配额限制。配备现代化 Web 监控界面和自动化测试系统。
keywords:
  - security
  - runtime-protection
  - prompt-injection
  - data-exfiltration
  - threat-detection
  - enterprise-security
  - ai-safety
  - web-monitor
  - automated-testing
author: nanlin@outlook.com
license: MIT
homepage: https://github.com/nanlin300624/runtime-security-guard
repository: https://github.com/nanlin300624/runtime-security-guard
---

# Runtime Security Guard - 企业级 AI 运行时安全防护

🛡️ **406+ 条安全规则 | 10 大类威胁检测 + OpenClaw 特定威胁 + IM 机器人安全 | Web 监控界面 | 自动化测试 | 完全本地运行**

**v2.1.0 新增 (2026-03-26):** 
- 14 条 OpenClaw 配置级安全检测规则（新增 openclaw-100 至 openclaw-113）
- 增强 OpenClaw 2026.3.x 版本特定威胁检测
- 新增 Control UI 认证、速率限制、多用户隔离等关键配置检测
- 优化 ACP 运行时、Canvas A2UI、模型覆盖等新功能监控

**v2.0.0 已有：**
- 32 条 OpenClaw 特定威胁检测规则（基于 MITRE ATLAS 框架）
- 33 条 IM 机器人插件安全规则（QQBot/Telegram/WhatsApp/Discord）

---

## 🎯 功能特性

### 核心安全能力

- ✅ **提示注入检测** - 26 条规则，识别越狱、隐藏指令、系统提示窃取
- ✅ **数据外泄防护** - 22 条规则，阻止敏感数据传输、记忆访问
- ✅ **恶意命令拦截** - 24 条规则，检测删除、下载执行、反向 Shell
- ✅ **敏感数据保护** - 24 条规则，识别 API 密钥、密码、个人信息
- ✅ **社会工程学防御** - 23 条规则，识别紧急操控、权威冒充
- ✅ **供应链攻击检测** - 25 条规则，检测恶意依赖、构建脚本注入
- ✅ **零日漏洞识别** - 20 条规则，识别内存破坏、代码执行漏洞
- ✅ **APT 攻击检测** - 30 条规则，检测侦察、持久化、横向移动
- ✅ **内部威胁识别** - 27 条规则，识别异常访问、权限滥用

### 技术优势

- ✅ **完全本地运行** - 无需云端 API，数据不出本地
- ✅ **零配额限制** - 无检测次数限制，随意使用
- ✅ **高性能** - 平均检测延迟 < 20ms，缓存命中 < 1ms
- ✅ **Web 监控界面** - 实时监控告警、性能、配置管理
- ✅ **自动化测试** - 35+ 测试用例，100% 通过率
- ✅ **易于集成** - OpenClaw 原生技能，开箱即用

---

## 📦 安装方法

### 方法 1：从 ClawHub 安装（推荐）

```bash
# 搜索技能
clawhub search runtime-security-guard

# 安装技能
clawhub install runtime-security-guard

# 验证安装
openclaw skills list | grep runtime-security
```

### 方法 2：无 sudo 快速安装（推荐）

```bash
# 下载并运行安装脚本
curl -fsSL https://raw.githubusercontent.com/nanlin300624/runtime-security-guard/main/install-no-sudo.sh | bash

# 或者手动下载
wget https://raw.githubusercontent.com/nanlin300624/runtime-security-guard/main/install-no-sudo.sh
chmod +x install-no-sudo.sh
./install-no-sudo.sh
```

**特点：**
- ✅ 无需 sudo 权限
- ✅ 用户级安装
- ✅ 自动检测环境
- ✅ 支持多种下载方式（Git/curl/wget）
- ✅ 自动配置环境变量

### 方法 3：从源码安装

```bash
# 克隆仓库
git clone https://github.com/nanlin300624/runtime-security-guard.git
cd runtime-security-guard

# 安装依赖
npm install

# 构建项目
npm run build

# 复制到 OpenClaw 技能目录
cp -r . ~/.openclaw/workspace/skills/runtime-security-guard/
```

### 方法 3：直接复制

```bash
# 下载技能包
wget https://github.com/nanlin300624/runtime-security-guard/releases/latest/download/runtime-security-guard.zip

# 解压到技能目录
unzip runtime-security-guard.zip -d ~/.openclaw/workspace/skills/
```

---

## 🚀 快速开始

### 基本使用

技能安装后自动运行，无需额外配置：

```typescript
// 在 OpenClaw 中自动拦截和检测
// 所有文件读取、工具结果、用户输入都会被检测
```

### 启动 Web 监控

```bash
# 启动 Web 服务器（默认端口 3000）
npm run web

# 访问监控界面
# http://localhost:3000
```

### 运行测试

```bash
# 运行快速功能测试
npm run test:quick

# 运行单元测试
npm test

# 运行所有测试
npm run test:all
```

---

## 📊 监控界面功能

### 实时监控仪表盘

- 📊 总告警数
- 🚨 CRITICAL 级别告警
- ⚠️  HIGH 级别告警
- ⏱️  平均检测延迟
- 💾 缓存命中率
- ✅ 健康状态

### 告警可视化

- 告警类型分布（9 大类）
- 严重程度分布（CRITICAL/HIGH/MEDIUM/LOW）
- 最近告警列表（时间、事件、类型、严重程度、操作）

### 性能指标

- P95 延迟
- P99 延迟
- 最大延迟
- 内存使用

### 配置管理

- 检测阈值（0.0-1.0）
- 缓存 TTL（秒）
- 在线保存配置

---

## 🔌 API 接口

### 获取统计信息

```bash
curl http://localhost:3000/api/stats
```

**响应示例：**
```json
{
  "total": 156,
  "byType": {
    "PROMPT_INJECTION": 45,
    "DATA_EXFILTRATION": 32
  },
  "bySeverity": {
    "CRITICAL": 12,
    "HIGH": 54,
    "MEDIUM": 67,
    "LOW": 23
  },
  "timeRange": {
    "start": "2026-03-07T12:00:00.000Z",
    "end": "2026-03-07T13:30:00.000Z"
  }
}
```

### 获取告警列表

```bash
curl http://localhost:3000/api/alerts?limit=50
```

### 获取性能指标

```bash
curl http://localhost:3000/api/performance
```

### 健康检查

```bash
curl http://localhost:3000/api/health
```

---

## ⚙️ 配置选项

### 检测阈值

```typescript
// 风险阈值（0.0-1.0）
// 默认：0.6
// 低于此值的内容不会被标记为风险
```

### 缓存配置

```typescript
// 缓存 TTL（毫秒）
// 默认：60000（60 秒）
// 缓存内容超过此时长后过期

// 最大缓存条目
// 默认：1000 条
```

### 性能优化

```typescript
// 预编译正则 - 启动时自动编译所有规则
// 双层缓存 - RuleEngine + DetectorManager
// 优先级执行 - CRITICAL → HIGH → MEDIUM → LOW
// 快速失败 - CRITICAL 规则命中立即返回
```

---

## 🧪 测试系统

### 测试类型

| 测试类型 | 测试数 | 通过率 |
|----------|--------|--------|
| 单元测试 | 29 | 100% ✅ |
| 功能测试 | 6 | 100% ✅ |
| 压力测试 | 4 场景 | 优秀 ✅ |
| 覆盖率测试 | 21 | 100% ✅ |

### 运行测试

```bash
# 快速功能测试
npm run test:quick

# 单元测试
npm test

# 压力测试
npm run test:stress

# 覆盖率测试
npm run test:coverage

# 所有测试
npm run test:all
```

---

## 📈 性能基准

### 检测延迟

| 场景 | 目标 | 实际 |
|------|------|------|
| 单次检测 | < 50ms | **0.01ms** ✅ |
| 缓存命中 | < 5ms | **< 1ms** ✅ |
| CRITICAL 规则 | < 20ms | **~10ms** ✅ |
| 批量检测 (100 次) | < 5000ms | **~1500ms** ✅ |

### 并发性能

| 负载 | 并发数 | QPS | 平均延迟 |
|------|--------|-----|----------|
| 低负载 | 1 | ~65 | ~15ms |
| 中负载 | 5 | ~145 | ~7ms |
| 高负载 | 10 | ~200 | ~5ms |
| 超高负载 | 20 | ~250 | ~4ms |

### 内存使用

| 指标 | 目标 | 实际 |
|------|------|------|
| 峰值内存 | < 150MB | **~100MB** ✅ |
| 平均内存 | < 100MB | **~80MB** ✅ |

---

## 🛠️ 开发指南

### 添加新规则

1. 在 `src/rules/patterns/` 创建或编辑规则文件
2. 在 `src/rules/rule-engine.ts` 导入新规则
3. 运行测试验证
4. 更新覆盖率测试

### 自定义告警

```typescript
import { plugin } from './runtime-security-guard';

// 获取告警统计
const stats = await plugin.getStats();

// 健康检查
const health = plugin.healthCheck();

// 性能报告
const report = plugin.getPerformanceReport();
```

### 集成到监控系统

```typescript
import { RuntimeSecurityGuard } from './runtime-security-guard';

const guard = new RuntimeSecurityGuard();

// 启动 Web 监控
await guard.startWebServer(3000);

// 实时监控告警
guard.alerter.startMonitoring((alert) => {
  console.log('新告警:', alert);
});
```

---

## 📚 文档

| 文档 | 说明 |
|------|------|
| [SKILL.md](SKILL.md) | 技能说明 |
| [README.md](README.md) | 使用指南 |
| [RELEASE.md](RELEASE.md) | 发布说明 |
| [PUBLISH-GUIDE.md](docs/PUBLISH-GUIDE.md) | 发布指南 |
| [WEB-MONITOR.md](docs/WEB-MONITOR.md) | Web 监控使用 |
| [AUTO-TEST.md](docs/AUTO-TEST.md) | 自动化测试 |
| [ALERT-VIEWER.md](docs/ALERT-VIEWER.md) | 告警查看 |
| [PERFORMANCE-OPTIMIZATION.md](docs/PERFORMANCE-OPTIMIZATION.md) | 性能优化 |

---

## 🤝 支持

### 问题反馈

- GitHub Issues: https://github.com/nanlin300624/runtime-security-guard/issues
- 邮箱：nanlin@outlook.com

### 社区

- Discord: https://discord.gg/clawd
- OpenClaw 论坛：https://forum.openclaw.ai

---

## 📝 更新日志

### v1.1.0 (2026-03-07)

**新增功能：**
- ✅ Web 监控配置管理界面
- ✅ 告警查看器（命令行 + API）
- ✅ 自动化测试系统（35+ 测试）
- ✅ 性能监控和健康检查
- ✅ 压力测试和覆盖率测试

**性能优化：**
- ✅ 预编译正则缓存（221 条规则）
- ✅ 按严重程度分组执行
- ✅ 双层缓存机制
- ✅ 快速失败机制

**测试覆盖：**
- ✅ 单元测试 29 个（100% 通过）
- ✅ 功能测试 6 个（100% 通过）
- ✅ 压力测试 4 个场景
- ✅ 覆盖率测试 21 个（100% 通过）

### v1.0.0 (2026-03-07)

**初始发布：**
- ✅ 221 条安全规则
- ✅ 9 大类威胁检测
- ✅ 完全本地运行
- ✅ 零配额限制

---

## 📄 许可证

MIT License - 详见 [LICENSE](LICENSE)

---

## 🎉 致谢

感谢以下项目提供的灵感：

- [OpenClaw](https://openclaw.ai) - AI 助手框架
- [OpenGuardrails](https://openguardrails.com) - 安全监控理念
- [MITRE ATT&CK](https://attack.mitre.org) - 威胁分类参考

---

**Made with ❤️ by nanlin@outlook.com**

**安全使用 AI，从 Runtime Security Guard 开始！** 🦞🛡️
