node9-ai/node9-proxy

GitHub: node9-ai/node9-proxy

Node9 Proxy 是一个面向自主 AI Agent 的执行安全代理层,通过拦截和管控 Agent 的 Shell 命令、文件操作与工具调用来防止高危行为并记录完整审计日志。

Stars: 118 | Forks: 12

# 🛡️ Node9 Proxy ### AI Agent 的“Sudo”命令。 [![NPM Version](https://img.shields.io/npm/v/node9-ai.svg)](https://www.npmjs.com/package/node9-ai) [![License: Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![Open in HF Spaces](https://huggingface.co/datasets/huggingface/badges/resolve/main/open-in-hf-spaces-sm.svg)](https://huggingface.co/spaces/Node9ai/node9-security-demo) [![Documentation](https://img.shields.io/badge/docs-node9.ai%2Fdocs-blue)](https://node9.ai/docs) **Node9** 位于您的 AI Agent 与系统之间。每一条 Shell 命令、每一次文件写入和工具调用都会先经过 Node9 —— 根据您的策略被拦截、批准或记录日志。支持 Claude Code、Gemini CLI、Cursor、Codex 以及任何 MCP Server。 📖 **[完整文档 →](https://node9.ai/docs)** ## “顿悟!”时刻 **AI 动作很快。** 让 Agent“发布修复”,它可能不问你直接推送到 Git。

有了 Node9: 1. **AI 尝试:** `Bash("git push origin main")` 2. **Node9 拦截:** 立即弹出操作系统原生弹窗 3. **你将其阻止** —— 只需点击一下 4. **AI 转换策略:** _“我会创建一个 PR 供审查”_ ## 立即试用 —— 无需安装 看看 Node9 能在你现有的 Claude Code、Gemini CLI 和 Codex 历史记录中发现什么: ``` npx node9-ai scan ``` 无需账号,无需守护进程,无需配置。读取 `~/.claude/projects/`、`~/.gemini/tmp/` 和 `~/.codex/`,运行完整的策略引擎,并显示所有会被阻止或标记的操作。 ``` 🔍 Scanning your AI history — what would node9 have caught? 47 risky operations found — none were blocked 🛑 Would have blocked 2 operations stopped before execution 👁 Would have flagged 44 sent to you for approval 🔑 Credential leak 1 secret detected in tool call ────────────────────────────────────────────────────────────────── bash-safe · 12 findings → node9 shield enable bash-safe 🛑 block-pipe-to-shell ×8 — Pipe-to-shell is a common supply-chain attack vector 👁 review-eval ×4 — eval of dynamic content requires human approval ⚡ 47 operations ran unprotected. node9 would have caught them. ``` ## 安装 ``` # macOS / Linux brew tap node9-ai/node9 && brew install node9 # or via npm npm install -g node9-ai ``` ``` node9 init # auto-detects Claude Code, Gemini CLI, Cursor, Codex node9 doctor # verify everything is wired correctly ``` ## 护盾 —— 每个服务一条命令 为你的 Agent 接触的基础设施启用专家级的保护: ``` node9 shield enable postgres # blocks DROP TABLE, TRUNCATE, DROP COLUMN node9 shield enable mongodb # blocks dropDatabase, drop(), deleteMany({}) node9 shield enable redis # blocks FLUSHALL, FLUSHDB node9 shield enable aws # blocks S3 delete, EC2 terminate, IAM changes node9 shield enable k8s # blocks namespace delete, helm uninstall node9 shield enable docker # blocks system prune, volume prune, rm -f node9 shield enable github # blocks gh repo delete, remote branch deletion node9 shield enable bash-safe # blocks curl|bash, base64|sh, rm -rf / node9 shield enable filesystem # reviews chmod 777, writes to /etc/ node9 shield list # see all shields and their status ``` ## MCP Gateway —— 保护任何 MCP Server 透明地封装任何 MCP Server。AI 看到的仍然是同一个 Server —— Node9 会拦截每一次工具调用: ``` { "mcpServers": { "postgres": { "command": "node9", "args": ["mcp", "--upstream", "npx -y @modelcontextprotocol/server-postgres postgresql://..."] } } } ``` 或者使用 `node9 init` —— 它会自动封装现有的 MCP Server。 ### MCP 工具锁定 —— 防御 Rug Pull 攻击 MCP Server 可以在会话之间更改其工具定义。遭到入侵或恶意的 Server 可能在初始信任后静默地添加、删除或修改工具 —— 这是一种 **Rug Pull** 攻击。 Node9 通过在首次使用时**锁定(pinning)**工具定义来防御此类攻击: 1. **首次连接** —— Gateway 会记录所有工具定义的 SHA-256 哈希值 2. **后续连接** —— 对比哈希值;如果工具发生改变,会话将被**隔离**,并且所有工具调用将被阻止,直到人工审核并批准该更改 3. **损坏的锁定状态** —— 会安全失效(阻止),绝不静默重新信任 ``` node9 mcp pin list # show all pinned servers and hashes node9 mcp pin update # remove pin, re-pin on next connection node9 mcp pin reset # clear all pins (re-pin on next connection) ``` 这是自动进行的 —— 无需配置。Gateway 会在首次 `tools/list` 时锁定,并在后续的每个会话中执行强制检查。 ### Skills 锁定 —— 已安装插件的偏移检测 位于 `~/.claude/plugins/marketplaces/` 的 Marketplace 插件来自注册中心而非你的工作区 —— `git status` 永远看不到它们。每个已安装的插件都有自己的锁定 Pin(模型与 MCP Server 锁定相同):安装新插件会静默创建新的锁定;只有对已锁定插件的更改才会触发偏移警报。通过 `policy.skillPinning.enabled: true` 选择启用;使用 `mode: 'block'` 进行严格强制执行。用户编辑的文件**不**在默认范围内。可通过 `policy.skillPinning.roots` 进行扩展。 ## Python SDK —— 管控任何 Python Agent ``` from node9 import configure configure(agent_name="my-agent", policy="require_approval") # Your existing agent code runs unchanged — Node9 intercepts tool calls ``` **[Python SDK →](https://github.com/node9-ai/node9-python)** · **[受管控 Agent 示例 →](https://github.com/node9-ai/governed-agent)** ## 始终开启的功能(无需配置) - **Git:** 阻止 `git push --force`、`git reset --hard`、`git clean -fd` - **SQL:** 阻止没有 `WHERE` 的 `DELETE`/`UPDATE`,以及 `DROP TABLE`、`TRUNCATE` - **Shell:** 阻止 `curl | bash`、`sudo` 命令 - **DLP:** 阻止在任何工具调用参数中出现 AWS 密钥、GitHub Token、Stripe 密钥、PEM 私钥 - **响应 DLP:** 后台扫描程序每小时读取 Claude 的 JSONL 历史记录,如果 Claude 的_响应文本_(不仅是工具参数)中出现密钥,会向您发出警报 —— 参见 [`node9 dlp`](#node9-dlp--response-secret-scanner) - **自动撤销:** 在 AI 每次编辑文件前进行 Git 快照 → `node9 undo` 即可还原 - **Skills 锁定:** 在会话之间对 Agent Skill 文件进行 SHA-256 验证;发生偏移时进行隔离(AST 02 + AST 07 —— 供应链与更新偏移) ## 可观测性 AI Agent 发起的每一次工具调用都会被记录下来 —— 包括命令、参数、结果和成本估算。Node9 为您提供四种方式来查看 Agent 正在做什么。 ### 实时 HUD(状态栏) Node9 在 Claude Code 中接入实时状态栏,实时向您展示正在发生的事情: ``` 🛡 node9 | standard | [bash-safe] | ✅ 12 allowed 🛑 2 blocked 🚨 0 dlp | ~$0.43 | ⚡ no-force-push 📊 claude-opus-4-6 | ctx [████████░░░░░░░] 54% | 5h [██░░░░░░░░░░░░░] 12% | 7d [█░░░░░░░░░░░░░░] 7% 🗂 2 CLAUDE.md | 8 rules | 3 MCPs | 4 hooks ``` **第 1 行 —— 安全状态:** 激活模式、已启用的护盾、会话总计(允许/阻止/DLP 命中)、预估成本、最后触发的规则。 **第 2 行 —— 上下文与速率限制:** 模型名称、上下文窗口使用情况、5 小时和 7 天的 Token 速率限制进度条 —— 让你可以直观地看到 Agent 何时正在大量消耗配额。 **第 3 行 —— 环境:** 当前项目中有多少个 CLAUDE.md 文件、规则、MCP Server 和 Hook 处于激活状态。 HUD 由 `node9 init` 自动接入。完整的会话日志会保存在 `~/.node9/audit.log` 中。 ### `node9 scan` —— 标记 ``` node9 scan # last 90 days node9 scan --all # all time node9 scan --drill-down # full commands + session IDs ``` ### `node9 tail` —— 实时流 在每次工具调用发生时进行流式传输。当你派发一个 Agent 去工作并想监视它的行为时非常有用: ``` node9 tail # stream tool calls for the active session node9 tail --all # include all projects ``` 每一行显示工具名称、其参数摘要以及决定结果(允许/阻止/DLP 命中)。 启动时,`tail` 会打印一行上下文摘要: ``` ctx: 34% (68k/200k out 2k · claude-sonnet-4-6) ``` 这显示了上下文窗口的占用情况、生成了多少输出 Token 以及正在运行的模型。颜色编码:青色 < 50%,黄色 50–79%,红色 ≥ 80%。 ### `node9 report` —— 安全面板 在会话结束后运行,以获取允许、阻止、DLP 命中、成本和每日活动的摘要: ``` $ node9 report --period 7d 🛡 node9 Report · Last 7 Days Apr 8 – Apr 14 2,255 events ────────────────────────────────────────────────────────────────────────────── ✅ 1,746 allowed 🛑 509 blocked 🚨 70 DLP hits 23% block rate 💰 $82.91 Top Tools Top Blocks ───────────────────────────────────── ───────────────────────────────────── Bash ██████ 1,595 timeout ██████ 281 Read █░░░░░ 196 smart-rule-block ██░░░░ 79 Edit █░░░░░ 118 observe-mode-dlp-would… █░░░░░ 69 drop_resource █░░░░░ 69 persistent-deny █░░░░░ 69 Grep █░░░░░ 35 local-decision █░░░░░ 5 Daily Activity ────────────────────────────────────────────────────────────────────────────── Apr 9 ██████████████████████████████ 833 216 blocked Apr 10 █████░░░░░░░░░░░░░░░░░░░░░░░░░ 145 24 blocked Apr 11 ██████████████████████░░░░░░░░ 617 139 blocked ``` 报告还包含一个 **Token** 部分,显示输入、输出、缓存写入和缓存读取 Token 的详细分类以及缓存命中率百分比 —— 这有助于找出那些大量消耗 Token 却未命中缓存的会话。 时间段:`today`、`7d`(默认)、`30d`、`month`。成本数据从 `~/.claude/projects/` 读取 —— 无需 API 调用,完全离线。 如果响应 DLP 扫描程序在此期间发现了密钥,报告会在顶部显示一个 `⚠️ DLP ALERT` 横幅,以及一个专门的 **Response DLP** 部分,列出每次发现的模式名称、掩码样本和来源项目。 ### `node9 sessions` —— 会话历史 跨会话查看你的 AI Agent 做了什么 —— 提示词、工具调用、成本、修改的文件以及是否进行了快照。当你交接任务并回来复查发生的情况时非常有用: ``` $ node9 sessions --all 📋 node9 sessions — what your AI agent did 7 sessions $178.93 total 2379 tool calls 122 files modified avg $25.56 /session 7 of 7 sessions had snapshots Tool breakdown: Bash ████████████████████ 1165 (49%) Read ███████████░░░░░░░░░ 613 (26%) Edit ██████░░░░░░░░░░░░░░ 367 (15%) Other ███░░░░░░░░░░░░░░░░░ 203 (9%) Write █░░░░░░░░░░░░░░░░░░░ 31 (1%) ─── Apr 15 ~/node9 14:47 implement delegated sessions feature 919 tools $74.45 📸 00ac39e2 12:47 ok, it seems you crash and we have a bug… 95 tools $6.40 📸 5a4e7fab ``` 深入查看任何会话以获取完整的工具追踪记录: ``` $ node9 sessions --detail 4812594b Session 4812594b-c93f-4a26-91f0-44aa2e324918 Prompt can you push node9-proxy to git dev? Project ~/node9 When Apr 9, 2026, 20:49 Cost ~$2.06 Snapshot ✓ taken Tool calls (54): 20:49 Bash git status && git branch -a 20:52 Write /home/nadav/node9/node9-proxy/.git/hooks/pre-commit 20:56 Edit /home/nadav/node9/node9-proxy/src/cli/commands/check.ts ... Files modified (3): /home/nadav/node9/node9-proxy/.git/hooks/pre-commit /home/nadav/node9/node9-proxy/src/cli/commands/check.ts /home/nadav/node9/node9-proxy/src/cli/hud.ts ``` ``` node9 sessions # last 7 days node9 sessions --all # all time node9 sessions --days 30 # last 30 days node9 sessions --detail # full tool trace (prefix match on session ID) ``` 目前支持 Claude Code。其他 Agent 的支持将随着它们开放会话历史而推出。 ### `node9 dlp` —— 响应密钥扫描程序 Node9 的工具调用 DLP 会在密钥_离开_你的机器之前将其阻止。但 Claude 也可以将密钥写入其**响应文本**中 —— 一个带有真实 Token 的 curl 示例,或者一个包含活动密钥的配置代码片段 —— 而这些文本完全绕过了工具调用拦截。 **响应 DLP 扫描程序**作为后台守护进程运行。它以增量方式(增量扫描 —— 仅扫描自上次检查以来的新字节)读取 Claude 的 JSONL 对话历史记录,在 Assistant 的响应文本中寻找密钥模式,并在发现密钥的瞬间触发桌面通知。 ``` ⚠️ node9 DLP alert AWS Access Key found in Claude response text. Sample: AKIA****MPLE — run: node9 dlp ``` ``` node9 dlp # show all open findings with pattern, sample, project, date node9 dlp resolve # acknowledge all current findings (clears the banner) ``` `node9 dlp` 命令会显示一个引导式的修复工作流: ``` 🔐 node9 dlp — secrets found in Claude response text ⚠️ 1 open finding These secrets were included in Claude's response text — NOT blocked. Rotate each affected key immediately. ● AWS Access Key ID Apr 14, 2026 Sample: AKIA****MPLE Project: ~/node9 Next steps: 1. Rotate any exposed keys shown above 2. Run node9 dlp resolve to acknowledge 3. Run node9 report for full audit history ``` 在执行 `node9 dlp resolve` 后,发现的结果将不再重复显示。扫描程序将已解决的密钥存储在 `~/.node9/dlp-resolved.json` 中,因此只会提示真正新出现的密钥。 ## 📖 完整文档 其他所有内容 —— 配置参考、智能规则、有状态规则、受信任的主机、审批模式、CLI 参考 —— 都在 **[node9.ai/docs](https://node9.ai/docs)**。 ## 相关项目 - [node9-python](https://github.com/node9-ai/node9-python) —— Python SDK - [governed-agent](https://github.com/node9-ai/governed-agent) —— 参考受管控 Agent(CI 代码审查修复器) ## 企业版 Node9 Pro 提供治理锁定、SAML/SSO 和 VPC 部署。访问 [node9.ai](https://node9.ai)。
标签:AI安全, Chat Copilot, Claude Code, Codex, Cursor, Cutter, Gemini CLI, Git操作控制, GNU通用公共许可证, MCP服务器, MITM代理, Node.js, NPM包, OSV-Scalibr, OS原生弹窗, RASP, Shell监控, Zero Trust, 人机协同, 命令拦截, 大模型安全, 审计日志, 执行安全层, 权限治理, 策略引擎, 系统加固, 网关代理, 网络安全, 网络安全挑战, 网络安全研究, 自主代理, 自动化攻击, 隐私保护