你的 AI Agent 知道你的密码——我如何修复它

发布: (2026年2月17日 GMT+8 00:10)
7 分钟阅读
原文: Dev.to

Source: Dev.to

(请提供您希望翻译的正文内容,我将为您翻译成简体中文。)

概述

当 AI 代理自动化您的浏览器时,它们需要在 上下文窗口 中使用您的登录凭据。
这意味着您的密码会:

  • 发送到云端 LLM 提供商
  • 存储在对话日志中
  • 可能通过提示注入攻击被泄露

我构建了 Cerberus KeyRouter 来解决此问题。

问题

AI 代理如 OpenClawClaude DesktopCursor 能够自动化浏览器——填写表单、点击按钮、导航页面。
当它们打开登录页面时,典型的流程如下:

User:  "帮我登录 GitHub"
User:  "邮箱: jacob@example.com"
User:  "密码: MyS3cretP@ss"
Agent: "正在登录..."

该密码会经过:

  1. LLM 提供商的服务器(Anthropic、OpenAI 等)——被记录、存储,甚至可能用于训练。
  2. API 代理服务——如果使用第三方中继,密码会再经过一个未知的中间人。
  3. 对话历史——以明文形式保存在你的聊天记录中。

Prompt‑injection 风险

恶意网页可以嵌入隐藏指令,诱使 AI 泄露它在先前对话中学到的凭证。

核心理念

  1. AI 使用占位符编写逻辑。
  2. 真实凭证在本地被替换 并直接注入浏览器。
  3. LLM 永远不会看到实际密码。

AI 发送的示例:

{
  "vaultItem": "GitHub",
  "steps": [
    { "action": "fill", "selector": "#login_field", "value": "{{email}}" },
    { "action": "fill", "selector": "#password",   "value": "{{password}}" },
    { "action": "click", "selector": "[type=submit]" }
  ]
}

Cerberus KeyRouter – 在你的机器上运行的 MCP(模型上下文协议)服务器 – 拦截此调用,从本地 Vaultwarden 实例获取真实凭证,替换 {{placeholders}},并通过 Chrome DevTools Protocol (CDP) 执行这些操作。

AI Agent (OpenClaw, Claude Desktop, …)

   │  MCP call: secure_login("GitHub", steps with {{placeholders}})

Login Router (localhost:8899)
   ├─ 通过 Bearer Token 进行身份验证
   ├─ 从 Vaultwarden 获取凭证
   ├─ 将 {{placeholders}} 替换为真实值
   ├─ 通过 Chrome CDP 执行(仅限本地主机)
   ├─ 从内存中清除凭证
   └─ 返回 { status: "ok" }  ← 响应中不包含密码

Vaultwarden(Docker,localhost:8443)提供端到端加密的密码存储。所有操作均在本地运行;密码永不离开你的机器。

安全特性

#功能描述
1Implicit allowlistVaultwarden 仅存储您明确添加的网站凭据。AI 无法登录任意网站。
2URL verification在注入凭据之前,路由器通过 CDP 读取浏览器的实际 URL 并与保险库条目的 URI 进行匹配。钓鱼网站将被拒绝。
3Bearer‑token auth每个 Vaultwarden 账户都有唯一的令牌。没有令牌 → 无法访问。
4Rate limiting每分钟 3 次尝试,每小时每个保险库条目 20 次。连续失败将触发冷却。
5Audit logging每一次登录尝试(成功、失败、受限)都会被记录。密码永不被记录。可在 /audit 查看。
6Human‑in‑the‑loop高风险账户可以在每次登录前要求人工批准(50 秒超时,若未批准则自动拒绝)。

快速开始

git clone https://github.com/DemoJacob/cerberus-keyrouter.git
cd cerberus-keyrouter
cp .env.example .env
# Edit .env and set VW_ADMIN_TOKEN
docker compose up --build -d

您将获得

服务URL目的
Vaultwarden(自托管的 Bitwarden)在此添加您的密码。
Login Router(MCP 服务器 + 管理面板)处理凭证替换和注入。
Admin panel(同一主机)添加您的 Vaultwarden 账户,生成一个持有者令牌。

通过 MCP 连接您的 AI 代理

{
  "mcpServers": {
    "cerberus": {
      "baseUrl": "http://localhost:8899/mcp",
      "headers": {
        "Authorization": "Bearer <your-token>"
      }
    }
  }
}

现在代理可以登录存储在您保险库中的任何站点,且永不看到明文密码

Interaction Patterns

Simple fill

大多数站点使用 fill 操作(设置值并触发事件)。

React / SPA sites

如果站点使用受控组件,请切换为 type(逐键输入,约 50 ms 延迟)。

Multi‑step logins (e.g., banks)

// Step 1: username + next
{
  "vaultItem": "MyBank",
  "steps": [
    { "action": "type",  "selector": "#username", "value": "{{username}}" },
    { "action": "click", "selector": "#next" },
    { "action": "wait",  "selector": "input[type=password]" }
  ]
}

// Step 2: password + submit
{
  "vaultItem": "MyBank",
  "steps": [
    { "action": "type",  "selector": "#password", "value": "{{password}}" },
    { "action": "click", "selector": "#login" }
  ]
}

Real‑world Example

Running with OpenClaw for daily tasks, I logged into zooplus.de to query order history. The AI reported:

“I didn’t touch any plaintext passwords. I only passed the placeholders {{email}} and {{password}}. Cerberus fetched the credentials from my local Vaultwarden vault and filled them directly into the browser.”

  • No password in the LLM context.
  • No password in the logs.
  • No password left my machine.

技术栈

组件技术
登录路由TypeScript / Node.js
浏览器自动化playwright‑core (CDP)
密码存储Vaultwarden (self‑hosted Bitwarden)
传输MCP Protocol – streamable HTTP
持久化SQLite (config + audit log)
加密AES‑256‑GCM (master‑password encryption)
部署Docker Compose (one‑command)
附加功能Cookie 缓存、OpenClaw 快照‑ref ID、多代理框架支持、零知识端到端加密后端的 SaaS 版本

许可证与贡献

The project is open source under AGPL‑3.0.

  • GitHub: (原文中省略链接)
  • Works on macOS and Linux (Docker + Chrome + any MCP‑compatible AI agent).

Feedback, issues, and stars are all welcome!

Come. If you're building AI agents that need to handle authentication, I'd love to hear about your use case.
0 浏览
Back to Blog

相关文章

阅读更多 »

n8n 是纯粹的精彩

!Miguel Valdeshttps://media2.dev.to/dynamic/image/width=50,height=50,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2...