OpenAlice HTTP 端点清单与攻击面分析:从端口挂载图谱到红队攻击优先级

原创2026-10-08 15:30:082,130 阅读

OpenAlice HTTP 端点清单与攻击面分析:从端口挂载图谱到红队攻击优先级

本文面向安全研究者与红队 agent,基于 OpenAlice 仓库 safe/knowledge/endpoints.md 的端点清单(Endpoint Inventory),逐路由梳理 Alice 与 UTA 两个进程的 HTTP 攻击面、认证意图与信任边界,并结合 src/webui/plugin.ts 等源码确认真实挂载关系与当前认证实现状态。读完本文,你将掌握 OpenAlice 的全部对外/对内 HTTP 路由、哪些端点涉及真实资金侧写(broker 下单)、健康探针为何刻意免认证,以及有限时间内应该优先攻击哪些目标。

背景:端点清单所在的进程布局与信任边界

端点清单是 OpenAlice 安全知识库的一部分(safe/knowledge/architecture.md 提供了配套的运行形态),服务于红队演练。系统在操作者机器上运行三个常驻进程:

[Guardian supervisor (scripts/guardian/dev.ts or prod.mjs)]
       │
       │ spawns + supervises
       │
       ├─→ [UTA process]    bind 127.0.0.1:47333
       │       services/uta/src/main.ts
       │       Holds: broker connections, Trading-as-Git state, FX, snapshots
       │
       └─→ [Alice process]  bind by config (default localhost:47331)
               src/main.ts
               Holds: agent runtime, UI server, BFF to UTA, all user-facing surfaces

   (dev only) [Vite dev server]  bind 0.0.0.0:5173
                  ui/ vite + proxy /api/* → Alice

信任边界(Trust boundaries)决定了每个端点的实际暴露面:

调用方 → 被调方 信任假设
Browser → Vite Vite 仅 dev 模式存在,暴露一切
Browser → Alice(:47331) 这是最值得关注的认证边界
Alice → UTA(127.0.0.1:47333) 当前:完全信任(同主机、同用户)
Alice → MCP(localhost:47332) 与 UTA 相同——完全信任
Workspace agent CLI → MCP 完全信任(loopback)
任意 → data/ 目录 完全信任(仅宿主机文件权限)

端点清单原文(撰写于 2026-05-23 认证落地之前)给出的结论是"认证列只反映意图,当时没有任何端点真正校验认证"。该状态在后续提交中已经变化:当前 src/webui/plugin.ts 已挂载 /api/auth 路由并在所有常规路由前安装了 createAuthMiddleware(实现见 src/webui/middleware/auth.ts)。下文表格保留原始认证意图分类,同时在"认证中间件的当前实现"一节给出源码级的最新事实。

Alice 端点(localhost:47331)

源码依据:路由在 src/webui/plugin.ts 中逐个 app.route(...) 挂载,端点清单声明其 source of truth 正是该文件及其导入的路由模块。以下表格完整继承自 safe/knowledge/endpoints.md,认证 列为意图标注(认证落地前的设计约定)。

公开端点(认证落地后亦无需认证)

Method Path Purpose
POST /api/auth/login (规划中)接收 admin token,设置 session cookie
POST /api/auth/logout (规划中)使当前会话失效
GET /api/version 构建版本 + 更新检查(无危害)
GET /login (规划中)登录页 HTML
GET /favicon.ico、/assets/* 来自 ui/dist/ 的静态资源

当前实现补充:认证中间件的公开白名单(src/webui/middleware/auth.ts)实际放行 /api/auth/login、/api/auth/logout、/api/auth/status、/api/version 以及 /login、/favicon、/assets/、/mcp 前缀——与上表意图完全一致。/api/version 路由实现于 src/webui/routes/version.ts,支持 GET /(currentOnly=1 时只返回当前版本)与 POST /check(强制刷新远端发布清单,供已认证 UI 使用)。

需认证端点(落地后应要求有效会话)

Chat 与会话

Method Path Purpose
GET/POST /api/chat/* 会话感知的 chat(多个子路由)
GET/POST /api/channels/* 子频道 SSE / 订阅
GET /api/media/:id 附件获取

源码佐证:/api/channels 由 createChannelsRoutes 挂载并持有 SSE 客户端集合(sseByChannel 按 channel ID 分组),/api/media 由 createMediaRoutes() 挂载。注意当前挂载前缀为 /api/channels(legacy web channels 的兼容边界),Workspace Chat 走的是 /api/workspaces 系列 API。

配置(broker + AI + connectors)

Method Path Purpose
GET /api/config 读取合并后的配置
PUT/POST /api/config/* 变更配置(AI provider、connectors)
GET /api/trading/config UTA 账户列表
POST /api/trading/config/uta 创建 UTA
PUT /api/trading/config/uta/:id 编辑 UTA
DELETE /api/trading/config/uta/:id 删除 UTA
POST /api/trading/config/test-connection BFF → UTA test-connection
GET /api/trading/config/broker-presets 预设目录

源码佐证(src/webui/routes/trading-config.ts):实际路由文件比清单更丰富——除 GET /(读取时对 key|secret|password|token 命名字段做 **** 掩码)、POST /uta(由 preset 指纹推导确定性 id,Mock 预设自动铸造 _instanceId,重复创建返回 409)、PUT /uta/:id(掩码凭据回填、支持凭据轮换)、DELETE /uta/:id(ephemeral UTA 会连带擦除交易数据)外,还有 GET/POST /broker-packs 与 POST /broker-packs/:engine/install(Broker Pack 安装,见 docs/broker-packs.md)。所有写操作都会触发 triggerUTARestart(),由 Guardian 在后台重启 UTA 进程。

交易域(BFF proxy → UTA)

这些端点由 src/webui/routes/trading-proxy.ts 原样转发到 UTA;在 UTA 侧对应 services/uta/src/http/routes-trading.ts。

Method Path Purpose
GET /api/trading/uta 列出已注册的 UTA
GET /api/trading/equity 汇总 USD 权益
GET /api/trading/contracts/search broker 合约搜索
POST /api/trading/test-connection broker 探测
GET /api/trading/fx-rates 汇率表
POST /api/trading/uta/:id/sync 强制 broker 同步
POST /api/trading/uta/:id/simulate-price 假设性 PnL
POST /api/trading/uta/:id/contracts/details 下钻合约
POST /api/trading/uta/:id/reconnect 重连单个 UTA
GET /api/trading/uta/:id/account 账户信息
GET /api/trading/uta/:id/positions 未平仓持仓
GET /api/trading/uta/:id/orders 未成交/指定订单
GET /api/trading/uta/:id/market-clock 市场开/收盘
GET /api/trading/uta/:id/quote/:symbol 按 symbol 报价
POST /api/trading/uta/:id/quote 按 Contract+aliceId 报价
GET /api/trading/uta/:id/wallet/log git log
GET /api/trading/uta/:id/wallet/show/:hash git show
GET /api/trading/uta/:id/wallet/status git status
POST /api/trading/uta/:id/wallet/commit commit 暂存
POST /api/trading/uta/:id/wallet/push 执行(broker 侧写入)
POST /api/trading/uta/:id/wallet/reject 拒绝 pending
POST /api/trading/uta/:id/wallet/stage-place-order 暂存买/卖
POST /api/trading/uta/:id/wallet/stage-modify-order 修改暂存
POST /api/trading/uta/:id/wallet/stage-close-position 平仓暂存
POST /api/trading/uta/:id/wallet/stage-cancel-order 撤单暂存
POST /api/trading/uta/:id/wallet/place-order 一次性 stage+commit+push
POST /api/trading/uta/:id/wallet/close-position 一次性平仓
POST /api/trading/uta/:id/wallet/cancel-order 一次性撤单
GET /api/trading/uta/:id/snapshots 快照列表
DELETE /api/trading/uta/:id/snapshots 清空快照
GET /api/trading/snapshots/equity-curve 权益曲线聚合

⚠️ POST /api/trading/uta/:id/wallet/push 是价值最高的攻击目标——它向 broker 发送真实订单。

实现细节(从源码确认):BFF 代理转发逻辑见 src/webui/routes/trading-proxy.ts——它把 c.req.path 连同 mount 前缀原样拼接 UTA baseUrl(${base}${c.req.path}${search}),透传白名单请求头,并用 30 秒 AbortController 兜底(PROXY_TIMEOUT_MS)。readonly 模式保护:isVenueMutation() 会对 /wallet/push、/wallet/place-order、/wallet/close-position、/wallet/cancel-order、/simulate-price 以及所有 /simulator* 路径在 trading mode 为 readonly 时直接返回 403。push 端点本身在 services/uta/src/http/routes-trading.ts 实现:要求存在 pendingMessage 且必须携带 expectedPendingHash(缺少即返回 PENDING_HASH_REQUIRED 409,hash 冲突返回 PENDING_HASH_CONFLICT 409)——Trading-as-Git 的状态机约束是 push 前的最后防线,注释明确"AI tool 被掏空,只有人类可以 push"。

模拟器(BFF → UTA)

Method Path Purpose
GET /api/simulator/utas 列出 MockBroker UTA
GET /api/simulator/uta/:id/state mock 状态快照
POST /api/simulator/uta/:id/mark-price 设置 mark price(撮合)
POST /api/simulator/uta/:id/tick-price 百分比波动
POST /api/simulator/uta/:id/orders/:orderId/fill 手动成交
POST /api/simulator/uta/:id/orders/:orderId/cancel 撤单
POST /api/simulator/uta/:id/external-deposit 模拟入金
POST /api/simulator/uta/:id/external-withdraw 模拟出金
POST /api/simulator/uta/:id/external-trade 模拟外部订单

源码佐证:UTA 侧实现于 services/uta/src/http/routes-simulator.ts,与 trading 路由共用 UTAEngineContext(只有 utaManager / fxService / snapshotService 三个依赖被暴露给路由层);Alice 侧由 createTradingProxyRoutes 以同样的转发逻辑挂载于 /api/simulator(src/webui/plugin.ts)。

其他 workspace 与基础设施

Method Path Purpose
GET/POST /api/workspaces/* workspace 启动器(PTY、MCP)
GET/POST /api/events/* 事件日志 + producer
GET /api/topology listener registry 检查
GET/POST /api/cron/* cron 任务 CRUD
GET/POST /api/heartbeat/* 心跳调度
GET /api/dev/* 仅开发用工具端点
GET /api/tools tool registry 检查
GET /api/agent-status/* 运行中 agent 状态
GET /api/news/* 新闻归档
GET /api/market/* 聚合行情搜索
GET /api/notifications 通知存储
GET/POST /api/inbox/* workspace 收件箱
GET/POST /api/market-data/* 行情数据包装

从 src/webui/plugin.ts 的实际挂载看,当前 Alice 路由前缀比清单记录更广,还包括 /api/connectors、/api/preferences、/api/ui-layout、/api/bars、/api/reference、/api/alice-project、/api/updates、/api/harness-surfaces、/api/agent-runtimes、/api/headless、/api/agent-conversations、/api/agent-runtime、/api/office、/api/schedule、/api/issues、/api/inquiries、/api/entities、/api/wikilink、/api/market-data-v1(兼容挂载)等。清单是 2026-05-23 时的快照,以 plugin.ts 为准。

MCP

Method Path Purpose
* /mcp 全局 MCP server(完整工具目录)
* /mcp/:wsId 按 workspace 的 MCP server

UTA 端点(127.0.0.1:47333)

UTA 从宿主机外部不可直接触达,但对 Alice 的成功攻击会经 BFF 代理获得访问 UTA 的能力。因此攻击目标应理解为"UTA 到底服务了什么"——知道它能告诉你下游有什么。

UTA 挂载(services/uta/src/main.ts):

  • /api/trading/* — 见上文表格
  • /api/simulator/* — 见上文表格
  • /__uta/health — 进程健康 + 账户数量(信息性)

源码细节:GET /__uta/health 返回 { ok: true, startedAt, utas: utaManager.listUTAs().length },被 Guardian 的就绪门控与 Alice BFF supervisor 轮询使用(probeOptionalCarrier 以 1 秒超时探测)。UTA 绑定仅 127.0.0.1:47333(端口冲突时取下一个空闲端口),且服务端硬编码 hostname: '127.0.0.1'——任何反向代理或 BFF 都无法改变这一点,设计上只有同主机同用户的 Alice 能触达 UTA。

健康/探测端点

Path Process Auth needed?
/api/version Alice 否(有意为之——供更新检查)
/__uta/health UTA 否(有意为之——Guardian 轮询它)

这两个端点被刻意设计为免认证:它们只暴露版本字符串与账户计数,不泄露任何秘密。/api/version 之所以公开,是因为 UI 的更新横幅需要匿名读取当前版本与最新发布版本(响应依赖 CDN manifest 的服务端缓存,成本很低)。

清单之外:不存在的攻击面

原文档明确列出"这里没有的东西",这本身就是防御性结论:

  • 没有 /admin、/console、/debug 这类魔法端点
  • 没有裸文件系统浏览器
  • 没有 SQL——系统没有数据库
  • 没有可写出 workspace 目录之外的上传端点

配套事实(来自 safe/knowledge/architecture.md):数据层完全是 JSON 文件(data/config/accounts.json、data/config/ai-provider-manager.json、data/config/connectors.json、data/control/restart-uta.flag、data/workspaces/<wsId>/ 等),没有 Postgres/SQLite/Redis;认证落地前没有密码哈希、没有 CSRF 中间件、没有限流器、没有 CORS allowlist(Hono 默认宽松)、没有 CSP/安全响应头。

攻击优先级排序(红队视角)

有限时间内按以下顺序投入:

  1. POST /api/trading/uta/:id/wallet/push — 真实 broker 副作用
  2. POST /api/trading/config/test-connection — 喂入 broker 凭据
  3. POST /api/config/* — 修改全局配置(含 AI provider 密钥)
  4. POST /api/workspaces/* — 文件系统写入、PTY 派生
  5. /api/auth/login — 认证面本身(落地后)
  6. POST /api/trading/uta/:id/wallet/reject — 破坏 pending 状态
  7. 其余一切

注意攻击优先级中多个目标受当前代码的二次保护:wallet/push 与 wallet/reject 都要求 expectedPendingHash(对抗竞态与重放);test-connection 在 lite 模式直接 503;trading BFF 在 readonly 模式拒绝所有 venue 写入类方法(403);/api/workspaces/* 的 PTY 与文件写入能力集中在 workspace 隔离目录(data/workspaces/<wsId>/)。

认证中间件的当前实现(快照之后的变化)

端点清单撰写于认证实现之前,本文基于当前仓库给出最新事实。认证门卫现位于 src/webui/middleware/auth.ts,安装位置在 src/webui/plugin.ts,请求处理顺序为:

  1. 公开白名单 — /api/auth/*、/api/version、静态资源、/mcp 前缀(MCP 有自身保护模型)
  2. Localhost 信任 — 未配置 OPENALICE_TRUSTED_PROXIES 时,真实 loopback 套接字地址(IPv4 127.0.0.0/8、IPv6 ::1、::ffff:127.x.x.x 均识别,见 isLoopbackIp/normalizeIp)且 Origin 为可信本地源(localhost/127.0.0.1/<a href="https://link.gitcode.com/i/7409cc968756832fce1110b0f3f926ea" target="_blank">::1]/app://openalice)时直通;配置了可信代理后此旁路失效,防止 X-Forwarded-For 伪造(对应 [safe/playbooks/03-localhost-spoofing.md)
  3. Session cookie — 从 Cookie 头提取 alice_session(空串视为无会话,见 safe/playbooks/01-auth-bypass.md),查 sessions.json、校验过期并滑动窗口(validateAndTouch)
  4. CSRF Origin 检查 — POST/PUT/DELETE/PATCH 若携带 Origin 头,必须与 Host 同源或命中 OPENALICE_CSRF_TRUSTED_ORIGINS 白名单,否则 403(对应 safe/playbooks/02-csrf-cross-origin.md);不带 Origin 的非浏览器调用(curl、Telegram bot)仍放行以保留 CLI 场景

配套的还有启动期安全网:首次启动会生成 admin token 打印到控制台(提示删除 data/config/auth.json 可轮换);若 OPENALICE_BIND_HOST 被设为非 loopback 地址且未配置 token、未显式设置 OPENALICE_DISABLE_AUTH=1,Alice 会拒绝启动,防止"为测试开了 0.0.0.0 却忘了认证"的失误(src/webui/plugin.ts)。这使原始文档中"认证落地前所有攻击都应成功"的基线描述不再成立,安全评估应以当前代码与 safe/playbooks 系列的可测试契约为准。

维护与使用建议

登录后查看全文
OpenAlice