Skip to content

feat(plugins): 补齐通用插件 Webhook 入口、Dashboard 服务代理与宿主环境变量注入 - #3830

Merged
deepcoldy merged 9 commits into
masterfrom
wt/botmux-webhook-dashboard
Nov 26, 2026
Merged

deepcoldy merged 9 commits into
masterfrom
wt/botmux-webhook-dashboard

Conversation

@deepcoldy

Copy link
Copy Markdown
Owner

变更说明

为 Botmux 插件体系补齐 3 项完全厂商中立(vendor-neutral)的基础能力,便于官方及第三方插件原生接入外部 Webhook、在远程 HTTPS 隧道下从 Dashboard 安全调用本地插件服务,并摆脱对 ~/.botmux 与 PATH 的硬编码依赖:

  1. 通用插件 Webhook 贡献点(dist/webhooks/index.json)与 POST /webhook/plugin/:pluginId/*

    • 在 src/core/plugins/types.ts、src/core/plugins/convention-scanner.ts、src/core/plugins/materializer.ts 与 src/core/plugins/webhooks/protocol.ts 支持可选的 dist/webhooks/index.json 声明(schemaVersion: 1、路由精确/段边界前缀、可选上游 endpoint 与 maxBodyBytes,默认 1 MiB、硬上限 5 MiB;无声明插件默认不暴露任何 Webhook 路由)。
    • 在 src/dashboard.ts 鉴权中间件与 handleWebhookRoute 之前挂载 src/dashboard/plugin-webhook-routes.ts(同时在 src/dashboard/connector-api.ts 保留 'plugin' connector ID 防冲突):
      • 在 new URL(req.url) 归一化前执行 earlyGuardPluginProxyRequest 预拦截路径穿越、百分号编码前缀绕过与非 origin-form 请求(400 + Connection: close)。
      • 严格校验 POST(405)、rawHeaders HTTP framing(400/501)、已安装与声明路由(404)、按 IP / 插件 / 全局滑动窗口限流(429)与分区并发/内存配额、以及本地插件服务在线与令牌就绪(503 fail-closed)。
      • 逐字节保真转发原始 raw body 与外部请求头(不做 JSON 解析/重序列化,不解压 Content-Encoding),剥离外部 Cookie/x-botmux-*/hop-by-hop 头,注入独立隔离的 Authorization: Bearer <BOTMUX_PLUGIN_WEBHOOK_TOKEN>(外部原始 Authorization 放入 x-botmux-webhook-forwarded-authorization),经 node:http requestLiteralLoopback(agent: false)直连 127.0.0.1:<port> 绕过 Bun $http_proxy 陷阱。
      • 第三方签名验证与防重放完全由插件服务端自主实现,核心不内置任何厂商逻辑。
  2. Dashboard 到插件服务的鉴权代理(/api/plugins/:id/service/*)与 api.serviceFetch

    • 新增 src/dashboard/plugin-service-proxy.ts,挂载在 Dashboard 鉴权与 sessionWriteOriginAllowed 之后(不占用 withPluginServiceLock):
      • 强制管理员身份(canManageHost,401)、拦截文档/iframe 顶层导航(403)、对 POST/PUT/PATCH/DELETE 执行双因子 CSRF(同源 + x-botmux-csrf)、对 GET/HEAD 拦截跨站/同站非同源与非法 Referer 并拒绝携带请求体及 ?t=<activeToken>。
      • 禁止代理至保留内部宿主回调路径(/botmux/*、cardActions.endpoint、commands.endpoint → 403)。
      • 拨号前注册 bindStream 并在响应头到达前复核会话存活与目标进程指纹,Dashboard token 轮换、平台解绑或插件 stop/restart 立即断流;支持 JSON、FormData、二进制与 SSE 流式响应(flushHeaders、no-transform、x-accel-buffering: no)。
      • 响应强制 CSP: default-src 'none'; sandbox、nosniff、CORP: same-origin、安全改写/剥离 Location、剥离 Set-Cookie/Access-Control-*/x-botmux-*,仅对上游实际响应附带 x-botmux-plugin-proxy: 1;在 src/dashboard/web/fetch-auth-guard.ts + app.tsx 精准忽略上游插件 401,避免误弹 Dashboard 重登遮罩。
    • 在 src/dashboard/web/plugin-page.tsx 导出 resolvePluginServiceProxyUrl、createPluginDashboardApi、PluginDashboardApi 并暴露 api.serviceFetch(path, init)(异步 Promise、严格路径校验、自动注入 x-botmux-csrf、强制 credentials: 'same-origin' 与 redirect: 'manual')。
  3. 插件服务宿主环境变量与服务活跃度补齐

    • 在 src/core/botmux-wrapper.ts 新增 resolveBotmuxBin(),兼容 BOTMUX_WRAPPER_BIN、单文件编译二进制(防 /$bunfs/ 与已删除路径)、BOTMUX_CORE_ONLY 与默认 wrapper(含 Windows .cmd)。
    • 在 src/core/plugins/service-manager.ts 强制注入不可伪造的 BOTMUX_DATA_DIR(经 resolveBotmuxDataDir())与 BOTMUX_BIN,首次启动缺 wrapper 时在确保 dataDir 存在后 create-if-absent 补齐(不覆盖已有 wrapper)。
    • 声明 webhooks 时强制固定 port(缺省报 plugin_webhooks_fixed_port_required),分配独立 BOTMUX_PLUGIN_WEBHOOK_TOKEN(private/webhooks.token,0600、O_NOFOLLOW)与 BOTMUX_PLUGIN_CARD_ACTION_TOKEN;任意声明有效 port 的 HTTP 插件服务也会自动分配回环令牌以支持 serviceFetch。
    • 新增 src/core/plugins/webhooks/service-target.ts 并在 src/core/plugins/supervisor-client.ts 暴露 processStart 校验:严格核验 desired.json 期望端口、跨插件端口冲突、进程出生身份(防 PID 复用与僵尸进程)及 forbiddenPorts(排除 Dashboard、在线 daemon ipcPort/proxyPort、活跃会话 webPort/previewTarget)。
    • 同步更新 docs-site/docs/zh/plugins.md 与 docs-site/docs/en/plugins.md。

影响范围评估

  • 跨平台(Linux / macOS / Windows):resolveBotmuxBin() 与 test/helpers/fence-home-env.ts 均处理 POSIX 与 Windows(botmux.cmd、USERPROFILE);O_NOFOLLOW 与 fchmodSync 沿用现有平台条件分支。
  • 跨 CLI / 跨会话类型:未改动 src/adapters/cli/*、src/adapters/backend/*、src/worker.ts、src/core/dashboard-ipc-server.ts、src/services/groups-store.ts 与 src/cli.ts,不影响任何 CLI 适配器、PTY/Tmux 后端或普通/话题/adopt/workflow 会话。
  • 既有插件兼容性:未声明 dist/webhooks/index.json 的插件默认零暴露、扫描结构完全不变;既有 cardActions / commands 固定端口校验与错误码优先级保持一致;新增宿主环境变量通过 serviceConfigHash 在下次重启时自动生效。

安全边界与对抗核验问题清单

提交前针对权限边界、HTTP framing、流式撤销与进程活跃度进行了多轮对抗验证并已全部修复落地:

级别 场景 复现/探针证据 修复方案
Critical 外部未鉴权 Webhook 若共用 BOTMUX_PLUGIN_CARD_ACTION_TOKEN 或前缀路由映射到 / / 内部回调路径,可伪造宿主鉴权的 daemon 回调(cardActions/commands//botmux/inputs/v1) 前缀路由 { path: '/hooks', prefix: true, endpoint: '/' } 可映射至 /botmux/commands/v1 并携带共享 Bearer 令牌 Webhook 独立隔离 BOTMUX_PLUGIN_WEBHOOK_TOKEN(private/webhooks.token);禁止前缀路由 endpoint: '/';安装扫描与运行时双重拒绝与 /botmux/*、cardActions/commands 重叠
High Dashboard 服务代理转发至内部宿主回调路径构成 Confused Deputy 具备 canManageHost 的协管身份可 POST /api/plugins/:id/service/botmux/inputs/v1 借代理自动附加的回环令牌伪造回调 在 plugin-service-proxy.ts 规范化解码匹配并拦截 /botmux/*、cardActions.endpoint、commands.endpoint(403 plugin_internal_endpoint_forbidden)
High service-target.ts 在 desiredPort 缺失或无 supervisor 文件缺 pid/processStart 时 fail-open,且 forbiddenPorts 未含会话 proxyPort/webPort/previewTarget service.json 过期或 PID 复用时可能拨号无关回环服务并泄露令牌 强制要求 desiredPort === port、跨插件端口互斥、proc.processStart 与非 supervisor 模式 pid + processStart 均非空匹配;pluginProxyForbiddenPorts 覆盖在线 daemon 与活跃会话端口
High 流式上传或预响应拨号期间撤销认证会话/停止插件时未及时断流 拨号期间 bindStream 尚未登记导致撤销后上传体仍继续送达上游;仅在 stopPluginServices 前断流会漏掉并发建流 拨号前即注册 bindStream 并在响应头到达前二次复核 isAuthSessionLive 与目标指纹;stop/restart 在停服前后双次 closeSessionStreams
High 首次运行且 resolveBotmuxDataDir() 目录尚未创建时,ensureBotmuxBinWrapperIfAbsent 加文件锁触发 ENOENT 被吞掉 空白隔离 HOME 下 startPluginServices 后 BOTMUX_BIN 文件未生成 加锁前先 mkdirSync(dataDir, { recursive: true }),并兼容 standalone + BOTMUX_WRAPPER_BIN 场景
Medium 205 Reset Content 透传上游非零 Content-Length 后空体结束导致 keep-alive framing 失步;流式上传遇上游提前 413 响应被 EPIPE 截断且未关 keep-alive;detectPluginProxyRawTargetKind 遇 ////.//大小写编码混合路径可绕过;resolvePluginServiceProxyUrl 尾部空格绕过点段校验 Node 24 / Bun 1.4.4 实测 205 客户端挂起、提前 413 收到半截响应、/v1/users/.. 经 WHATWG URL 折叠为 /v1/ 205 规范输出 content-length: 0 并校验上游 framing;未完成上传遇上游提前响应设置 Connection: close 并在 status >= 300 立即 unpipe/pause;统一解码段遍历器覆盖所有变形;resolvePluginServiceProxyUrl 拒绝首尾空白并校验 WHATWG 段数/尾斜杠不变,将 serviceFetch 改为 async 返回 rejected Promise
Medium Webhook 并发/内存池未按 IP 与插件分区、且无条件信任隧道 X-Forwarded-For 单 IP 慢速占满 16 MiB 全局缓冲可饿死其余插件 增加每 IP / 每插件并发与字节子配额、写入上游后立即释放字节配额,并统一遵循 trustedProxyHops

测试与变异验证

  1. 构建、类型检查与仓库审计

    bun run build
    • audit:domains: [domain-audit] no private deployment hostnames found
    • tsc + bun run typecheck + dashboard:bundle + audit-dist + audit-embedded-assets --require-dist: 全部通过。
  2. Vitest 单元与实机 Dashboard 集成测试(16 个套件)

    bunx vitest run --project unit \
      test/plugin-webhooks-protocol.test.ts \
      test/plugin-service-env-injection.test.ts \
      test/plugin-dashboard-service-fetch.test.ts \
      test/plugin-webhook-routes.test.ts \
      test/plugin-service-proxy.test.ts \
      test/plugin-webhook-proxy.integration.test.ts \
      test/plugin-supervisor-state.test.ts \
      test/connector-api.test.ts \
      test/bun-shim-parity.test.ts \
      test/test-hygiene.test.ts \
      test/plugin-manifest-store.test.ts \
      test/plugin-service-link-watch.test.ts \
      test/plugin-service-url-host.test.ts \
      test/plugin-market-final-verification.test.ts \
      test/dashboard-plugin-settings.test.ts \
      test/webhook-routes.test.ts
    • 结果:16 passed (16),335 passed | 2 skipped (337)。
  3. Bun 1.4.4 运行时隔离测试(7 个套件)

    • plugin-webhooks-protocol (33/33)、plugin-service-env-injection (8/8)、plugin-dashboard-service-fetch (33/33)、plugin-webhook-routes (10/10)、plugin-service-proxy (10/10)、plugin-webhook-proxy.integration (1/1)、bun-shim-parity (34/34) 全部通过。
  4. 变异验证(isolate-run)

    • 摘除 14 处核心安全与功能守卫(Webhook/Service 预归一化守卫、内部回调重叠拦阻、Webhook x-botmux-* 剥离、流式 413 上限、回环 Bearer 注入、Dashboard canManageHost 鉴权、CSRF 门禁、Confused Deputy 内部端点拦阻、文档导航拦阻、Location 改写、只读令牌读取防自动签发、BOTMUX_DATA_DIR 注入、resolvePluginServiceProxyUrl 尾空格守卫):14/14 全部咬红(KILLED)。

🤖 Generated with Claude Code

- 新增可选贡献点 `dist/webhooks/index.json`(声明路由路径/段边界前缀、上游 endpoint、body 上限),在安装扫描与运行时双重禁止与 `/botmux/*`、commands/card-actions 回调路径重叠。
- 在 Dashboard 鉴权中间件之前挂载 `POST /webhook/plugin/:pluginId/*`:预归一化路径穿越拦截、strict rawHeaders framing 校验、按 IP/插件/全局限流与分区并发/内存配额、逐字节原始请求体保真转发(不做 JSON 重序列化)、独立回环令牌 `BOTMUX_PLUGIN_WEBHOOK_TOKEN`、通过 `node:http` `requestLiteralLoopback` 绕过 `$http_proxy`。
- 在 Dashboard 鉴权与 CSRF 中间件之后挂载 `/api/plugins/:id/service/*` 反向代理,并在 `pluginDashboardApi` 暴露 `api.serviceFetch(path, init)`:强制管理员身份、阻断文档/iframe 导航、双因子 CSRF、禁止代理至内部宿主回调路径、支持流式/SSE 与认证撤销实时断流,且不占用 `withPluginServiceLock`。
- 在 `service-manager.ts` 注入不可伪造的 `BOTMUX_DATA_DIR`、`BOTMUX_BIN` 与隔离回环令牌(声明 webhooks 或有效 HTTP 端口时自动分配),并在目标解析器中严格校验 `desired.json` 端口、`processStart` 进程出生身份与 `forbiddenPorts`。
- 同步更新中英文插件文档与单测/集成测试。

Co-Authored-By: Claude Code <[email protected]>

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审结论

发现 1 个建议合并前处理的向后兼容回归(原 P3-1 建议提升为 P2);另一条默认 resolveTarget 回退不构成当前生产路径问题,可作为 P3 加固。除此之外,本轮没有发现新的安全阻断项。

1. [P2] 存量 id=plugin 连接器的有效 Webhook URL 会被新路由截获

位置:src/dashboard/plugin-webhook-routes.ts:664-729、src/dashboard.ts:4485-4493、src/dashboard/connector-api.ts:287-288。

升级前 POST /api/connectors 接受调用方显式传入 id: "plugin";本 PR 只是在写入时新增保留 ID 校验,没有处理已经持久化的同类记录。新插件处理器又挂在旧 handleWebhookRoute 前面,并接管 /webhook/plugin 及其子路径,因此存量连接器的两类公开 URL 都会失败:

  • /webhook/plugin/<token>:被解释为插件命名空间,返回 404;
  • /webhook/plugin?token=<token>:同样返回 404;
  • 请求不会进入旧连接器验签和 daemon 投递路径。

使用真实 createPluginWebhookRouteHandler、earlyGuardPluginProxyRequest、handleWebhookRoute 与临时连接器存储做了 HTTP 探针。同一记录在旧处理器单独挂载时,两种 URL 都验签成功并返回 202、调用模拟 daemon;按本 PR 顺序挂载后,两者均返回 404 webhook_route_not_found,daemon 调用数不增加。命令:

bun scripts/fenced-run.ts -- bun /tmp/botmux-pr3830-recheck-0jzTOJ/legacy-connector-collision.ts

现有 test/connector-api.test.ts:84-111 只验证禁止新建保留 ID,未覆盖升级前已有记录。定向运行 bunx vitest run test/connector-api.test.ts test/plugin-webhook-routes.test.ts --maxWorkers=2 为 37/37 通过,无法捕获该回归。

建议不要只加启动告警或发版说明,而是在插件路由接管前保留旧连接器的安全分派,或提供可保持既有 URL 的迁移路径,并补上述两种 Token 携带方式的回归测试。合法插件路由要求非空的第三段子路径(src/core/plugins/webhooks/protocol.ts:416-429),而旧 Token URL 最多只有 /webhook/plugin/<token>,两者可以无歧义分派;实现时同时核对 earlyGuard 和既有大小写变体。

另外,恢复步骤不是“改名”:更新路径把 URL 中的 ID 固定传给 normalizeConnectorInput(src/dashboard/connector-api.ts:542-578),存量保留 ID 的普通 PUT 也会得到 reserved_connector_id。若选择迁移而非兼容分派,通过现有 UI/API 需要删除重建(或手工迁移存储)并更新外部 Webhook URL,迁移文档应明确这一点。

2. [P3] 默认 resolveTarget 未带 forbiddenPorts:当前不阻断,可选收紧构造契约

位置:src/dashboard/plugin-webhook-routes.ts:462-464、src/dashboard/plugin-service-proxy.ts:335。

全仓库构造点已核对:生产唯一的两个实例位于 src/dashboard.ts:3296-3314,都显式注入使用 pluginProxyForbiddenPorts 的 resolver;测试构造也都注入 resolver。因此默认回退目前不会让生产请求绕过禁用端口检查,无需为此阻塞合并。

若顺手加固,相比只加注释,更建议删除未使用的默认回退并要求构造方显式提供 resolver(或把宿主禁用端口视图变成必需依赖),避免未来新调用点无意中削弱 src/core/plugins/webhooks/service-target.ts:59-69 所述 fail-closed 边界。

其它核验

  • 原 PR head 仍为 7a586eb06f1eec34347604b07477d7d34f1062a6;本地等价 rebase 树与最新 origin/master(9ba2e805f7)的 git merge-tree --write-tree 无冲突。
  • 聚焦文件与原 PR head 内容一致;工作树未修改。
  • CI 已完成的 build、二进制、CodeQL 及其余测试分片均通过;发布本结论时 test (1/4)、test (3/4)、bun-test (3/4) 仍显示 pending,未将其计为通过或失败。

新增插件 webhook 网关挂在旧连接器路由之前,会把存量 id=plugin
连接器的 /webhook/plugin 与 /webhook/plugin/<token>(1–2 段形状)
以 404/405/400 吞掉,导致升级后既有外部回调与 GET 异步轮询中断。

- protocol.ts 新增 isLegacyPluginConnectorWebhookTarget:仅当
  origin-form 路径为 /webhook/plugin 或 /webhook/plugin/<token>
  (含百分号编码)且解码后连接器 ID 恰为 plugin 时返回 true;
  3 段及以上仍归插件网关,尾斜杠、大小写变体、穿越形态不放行
- earlyGuard 与插件 handler 在任何插件形状拒绝前对该形状 fall
  through,交回旧连接器路由,由其重新执行 token/HMAC 校验
- resolveTarget 改为必填注入并移除两个未带 forbiddenPorts 的
  默认回退,生产两个构造点与全部测试构造点均已显式注入
- 补纯函数分派测试与路由级 fall-through 回归(含 GET 轮询与
  percent-encoded 形式),变异验证守卫失效即咬红

Co-Authored-By: Claude Fable 5 <[email protected]>
@deepcoldy

Copy link
Copy Markdown
Owner Author

已按复审意见(review #6056303470)追加提交 87ab864,处理 P2 与 P3-2:

P2:存量 id=plugin 连接器 webhook 中断

  • 新增纯函数 isLegacyPluginConnectorWebhookTarget(src/core/plugins/webhooks/protocol.ts):仅当 origin-form 路径为 /webhook/plugin 或 /webhook/plugin/<token>(1–2 段、解码后连接器 ID 恰为 plugin,含百分号编码)时判定为旧连接器形状;3 段及以上仍归插件网关,尾斜杠、大小写变体、穿越形态、absolute-form 均不放行。
  • earlyGuardPluginProxyRequest 与插件 handler 在任何插件形状拒绝之前对该形状 fall through,交回 handleWebhookRoute,由旧路由重新执行 token/HMAC 校验,不绕过任何鉴权。
  • 本地探针按生产挂载顺序复现:修复前 POST 两种 URL 404、GET 异步轮询 405、percent-encoded 400 且旧路由零到达;修复后四种形状全部 202 到达旧路由,合法插件 3 段路由与未知插件 404 行为不变。
  • 新写入仍由 connector-api 拒绝保留 ID,本改动只兼容已持久化记录,PUT 改名受阻问题随之不再构成阻断(旧 URL 可继续投递,迁移不再紧急)。

P3-2:收紧 resolveTarget 注入

  • 两个 handler 的 resolveTarget 改为必填并删除未带 forbiddenPorts 的默认回退;生产两个构造点(dashboard.ts)与全部测试构造点均已显式注入,tsc 验证无遗漏。

验证

  • bun run build(tsc + dashboard bundle + audit)通过
  • vitest 定向 9 套件 170 pass / 2 skip;bun 运行时腿 7 套件 131 pass / 2 skip;另跑 test-hygiene、legacy webhook-routes 等 4 套件 107 pass
  • 变异验证:令 isLegacyPluginConnectorWebhookTarget 恒 false,protocol 与 routes 两文件共 3 个用例咬红,还原后复绿

🤖 Generated with Claude Code

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

新 head 87ab864ddf 复审结论

精确小写 plugin 的投递路径与 resolveTarget 必填注入均已修复,但本轮发现 1 个兼容修复引入的预归一化防护绕过,另有 2 个原兼容性问题的残留分支(大小写变体、存量记录维护)。当前不建议合并。

1. [P2] Legacy fall-through 可在严格路径校验前放行反斜杠穿越

位置:src/core/plugins/webhooks/protocol.ts:447-462、src/dashboard/plugin-webhook-routes.ts:218-223、src/dashboard/plugin-webhook-routes.ts:674-679。

isLegacyPluginConnectorWebhookTarget 只检查段数、尾斜杠和解码后的连接器 ID,没有校验 Token 所在段中的反斜杠或点段。earlyGuardPluginProxyRequest 看到该谓词为 true 后立即返回 false,不再执行 parseRawPluginWebhookRequest / validateStrictPluginHttpPath;随后 Dashboard 的 new URL() 会把反斜杠当路径分隔符并折叠点段,使请求进入其它路由。

使用真实新 head 模块,按 earlyGuard → new URL → /__health → 插件 handler 的生产相对顺序发送原始 HTTP 请求:

POST /webhook/plugin/../../__health
→ 400 invalid_webhook_path(原有防护正常)

POST /webhook/plugin/..\..\__health
→ legacy predicate = true
→ normalized pathname = /__health
→ 200(防护被绕过)

POST /webhook/%70lugin/..\..\__health
→ 同样 200

Bun 与 Node v24.22.2 下均复现;Node 复跑使用本次 bun run build 生成的 dist/,不是仅对纯函数做推断。探针命令:

bun scripts/fenced-run.ts -- bun /tmp/botmux-pr3830-new-head-lGddtl/legacy-traversal.ts
bun scripts/fenced-run.ts -- node /tmp/botmux-pr3830-new-head-lGddtl/legacy-traversal-node.mjs

建议在 legacy fall-through 之前校验完整 raw path,至少拒绝原始/编码反斜杠、原始/编码点段和分隔符伪装;也可复用现有 strict path validator,同时确认需要兼容的旧 Token 字符集。必须增加经过 earlyGuard + new URL 的原始 HTTP 回归用例,仅测试谓词的布尔结果无法钉住该归一化边界。

2. [P2] 存量大小写变体连接器仍被 400 截断

位置:src/core/plugins/webhooks/protocol.ts:453-461、test/plugin-webhooks-protocol.test.ts:403-404。

旧版 API 同样接受 id: "PLUGIN"、id: "Plugin",旧连接器存储和路由按精确大小写查找,因此这些都是可正常投递的存量记录。新谓词要求 connectorId === 'plugin',而 detectPluginProxyRawTargetKind 又按大小写不敏感方式识别插件前缀;结果是大小写变体不会 fall through,随后被严格插件解析以 400 拒绝。

真实 handleWebhookRoute + 临时连接器存储的对照探针:

POST /webhook/PLUGIN/upper-secret
  旧路由:202,到达模拟 daemon
  新顺序:400 invalid_webhook_path,daemon 调用数不增加

POST /webhook/Plugin?token=mixed-secret
  旧路由:202,到达模拟 daemon
  新顺序:400 invalid_webhook_path,daemon 调用数不增加

POST /webhook/%50lugin/mixed-secret
  旧路由:202,到达模拟 daemon
  新顺序:400 invalid_webhook_path,daemon 调用数不增加

这与新写入校验按大小写不敏感保留 plugin 的策略也不一致。探针命令:

bun scripts/fenced-run.ts -- bun /tmp/botmux-pr3830-new-head-lGddtl/legacy-case-matrix.ts

建议在完成上述路径安全校验后,对 1–2 段旧连接器形状按大小写不敏感识别保留 ID,让旧路由继续按存储中的精确 ID 验签;相应更新目前把大小写变体钉为 false 的测试。

3. [P2] 存量保留 ID 恢复投递后仍无法通过 PUT 维护或轮换密钥

位置:src/dashboard/connector-api.ts:287-288、src/dashboard/connector-api.ts:542-583。

保留 ID 校验在创建与更新之间没有区分。存量记录即使恢复了 Webhook 投递,普通 PUT 修改名称/目标以及 rotateSecret: true 仍会在 preflight 返回 reserved_connector_id。这使受影响连接器无法继续正常维护,尤其无法在凭据需要轮换时完成原地修复。

真实 handleConnectorApi + 临时连接器存储探针结果:

PUT /api/connectors/plugin  {"name":"After"}
→ 400 reserved_connector_id,持久化名称仍为 Before

PUT /api/connectors/plugin  {"rotateSecret":true}
→ 400 reserved_connector_id

命令:

bun scripts/fenced-run.ts -- bun /tmp/botmux-pr3830-new-head-lGddtl/legacy-maintenance.ts

建议把保留 ID 拒绝限定在新建;对已存在且 URL 固定沿用同一 ID 的记录允许更新,并覆盖名称/目标修改及密钥轮换测试。若有意要求删除重建,则需要明确迁移流程,但那不再是透明的路由兼容修复。

已确认修复/未回归部分

  • /webhook/plugin/<token>、/webhook/plugin?token=…、/webhook/%70lugin/<token> 均已恢复为 202 并到达旧连接器;GET 轮询也进入旧路由并完成 Token 验签。
  • 合法插件 /webhook/plugin/demo/events 仍返回 202;未知插件三段路由仍由插件网关返回 404,未泄漏到旧连接器。
  • 两个工厂的 resolveTarget 均已改为必填,未带 forbiddenPorts 的默认回退已删除;生产与测试构造点完整,原 P3 可关闭。
  • 本地 bun run build 通过;5 个定向 vitest 套件共 117/117 通过。上述负例说明还需补充覆盖,而不是现有测试失败。
  • 与最新 origin/master(b5eaeedc83)做 git merge-tree --write-tree 无冲突;工作树保持干净。

第二轮复审发现的三个 P2:

1. fall-through 反斜杠穿越绕过预归一化防护:
   isLegacyPluginConnectorWebhookTarget 此前只看段数与连接器 ID,
   /webhook/plugin/..\..\__health 经 earlyGuard 放行后被 new URL
   归一化到 /__health 返回 200(普通斜杠对照为 400)。现在 fall-through
   前对完整 raw path 跑 validateStrictPluginHttpPath,反斜杠、点段、
   编码分隔符、控制字符全部拒绝,并补经 earlyGuard+new URL 的原始
   HTTP 回归。

2. 存量大小写变体连接器仍被 400 截断:保留 ID 识别改为大小写不敏感
   (PLUGIN/Plugin/百分号编码),交旧路由按存储中的精确 ID 查找并
   重新验签,新建拦截仍按大小写不敏感生效。

3. 存量记录无法 PUT 维护或轮换密钥:reserved_connector_id 校验区分
   新建/改名与同 ID 存量更新——prior 存在且 prior.id === id 时放行
   PUT(改名、目标编辑、rotateSecret),POST 新建与改名到保留 ID
   仍然拒绝。

变异验证:摘除严格路径守卫、大小写改回精确匹配、关闭存量 PUT 豁免
三处分别咬红(M10/M11/M12),还原后复绿。Node 24 + dist 编译产物
跨运行时探针通过。

Co-Authored-By: Claude Fable 5 <[email protected]>
@deepcoldy

Copy link
Copy Markdown
Owner Author

第二轮复审(review #6056918540)的三个 P2 已逐个独立复现并修复,追加提交 22a94a1(fast-forward,未改既有提交):

P2-1:fall-through 反斜杠穿越绕过预归一化防护(复现成立)

  • 我按 earlyGuard → new URL → /__health 生产顺序搭真实 HTTP 探针:/webhook/plugin/..\..\__health 与 /webhook/%70lugin/..\..\__health 修复前均 200 命中 /__health,普通斜杠 /webhook/plugin/../../__health 对照为 400;Bun 与 Node 24 行为一致。
  • 修复:isLegacyPluginConnectorWebhookTarget 在返回 true 前对完整 raw path 跑 validateStrictPluginHttpPath,反斜杠、点段、编码分隔符(%2f/%5c)、控制字符、尾斜杠全部拒绝,再谈 fall-through。

P2-2:存量大小写变体连接器被 400 截断(复现成立)

  • PLUGIN、Plugin、%50lugin 修复前全部 400、旧路由零到达。
  • 修复:保留 ID 识别改为大小写不敏感;旧连接器路由仍按存储中的精确 ID 查找并重新执行 token/HMAC 验签,新建拦截继续按大小写不敏感生效。

P2-3:存量记录无法 PUT 维护或轮换密钥(复现成立)

  • 修复:normalizeConnectorInput 区分新建/改名与同 ID 存量更新——prior 存在且 prior.id === id 时放行 PUT(改名、目标编辑、rotateSecret);POST 新建与改名到保留 ID 仍返回 reserved_connector_id。PUT 的 id 恒取 URL 段,无法借 body 绕过。

验证

  • 修复后探针:3 个穿越形状全 400,3 个大小写变体与精确小写共 4 个 legacy 形状全部 202 到达旧路由,合法插件路由 202、未知插件 404 对照组不变
  • 新增经 earlyGuard+new URL 的原始 HTTP 穿越回归、大小写 fall-through 回归、connector PUT 维护/轮换/大写 ID/新建仍拒回归
  • bun run build 绿;vitest 9 套件 172 pass/2 skip;bun 腿 132 pass/2 skip;另 4 套件 107 pass
  • 变异 M10(摘严格路径守卫)、M11(大小写改回精确)、M12(关存量 PUT 豁免)分别咬红,还原复绿
  • Node v24.22.2 直接 import 本次 dist 编译产物,纯函数矩阵 8 例全过

🤖 Generated with Claude Code

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

22a94a1032 复审结论

上一轮三项 P2(反斜杠穿越、大小写变体、存量 PUT 维护)均已复验关闭,但发现 1 个同一路径上的剩余兼容性回归。当前仍不建议合并;除此之外没有新增阻断项。

[P2] 完整复用插件 strict validator 会拒绝旧 API 支持的不透明 path Token

位置:src/core/plugins/webhooks/protocol.ts:453-480,尤其是 :464;对应测试当前把这两个形状钉为 false:test/plugin-webhooks-protocol.test.ts:410-411。

旧 Connector API 接受任意非空自定义 secret,publicWebhookUrl 使用 encodeURIComponent(token) 生成路径(src/dashboard/connector-api.ts:437-450)。因此 secret 含 / 或 \ 时,既有公开 URL 分别包含 %2F / %5C;旧 handleWebhookRoute 解码路径 Token 后能正常验签。新 legacy 判定复用插件 strict validator 后,这两个编码会被拒绝,earlyGuard 随后返回 400,旧连接器收不到请求。

使用真实 handleConnectorApi 生成 URL,再对比真实旧路由与生产挂载顺序:

secret = a/b
生成路径:/webhook/plugin/a%2Fb
旧路由:202,到达模拟 daemon
新顺序:400 invalid_webhook_path
改用 ?token=a%2Fb:202(说明只是路径 Token 兼容回归)

secret = a\b
生成路径:/webhook/plugin/a%5Cb
旧路由:202,到达模拟 daemon
新顺序:400 invalid_webhook_path
改用 ?token=a%5Cb:202

探针命令:

bun scripts/fenced-run.ts -- bun /tmp/botmux-pr3830-new-head-lGddtl/legacy-opaque-token.ts

这里不能简单摘掉安全校验,否则反斜杠穿越会复发。建议为不透明 legacy Token 保留旧解码语义,只排除会改变路由归一化结果的形状:例如校验 new URL(...) 后的 pathname 与原 rawPath 不变,并/或显式拒绝原始反斜杠及原始/编码的完整 . / .. 段;%2F、%5C 在不透明 Token 段中不会被 WHATWG URL 解码成路径分隔符,可以交旧路由自行解码和验签。请增加自定义 a/b、a\b 经 API 生成 URL 后的端到端回归,同时保留本轮四种穿越 400 的测试。

已复验通过的部分

  • 四种普通/编码反斜杠与点段穿越均为 400;Node 24 直接加载本次 dist/ 复跑也为 400。
  • 精确小写、编码小写、PLUGIN、Plugin、编码大写的合法旧请求均为 202 并到达旧连接器;合法插件 202、未知插件三段路由 404。
  • 存量保留 ID 的 PUT 改名与 rotateSecret 均为 200;新建保留 ID 仍拒绝,同 ID 豁免不能被 body 改名绕过。
  • 两个 handler 的 resolveTarget 必填加固保持有效。
  • bun run build 通过;聚焦 vitest 5 套件 119/119 通过,另跑 hygiene / Bun parity / service-env 3 套件为 70 pass、2 skip;两个适用的 Bun 套件分进程运行分别为 34/34、12/12。
  • 与当前 master c6445c13ed 的 merge-tree 无冲突,工作树干净。
  • 完整 CI 尚未全部出现/完成,本结论只覆盖代码与上述本地验证。

第三轮复审 P2:自定义 secret 含 / 或 \ 时,publicWebhookUrl 经
encodeURIComponent 生成的公开 URL(token 段含 %2F/%5C)被上一轮
复用的插件 strict validator 以 400 拒绝,旧路由本可解码验签,
破坏公开 URL 的透明兼容。

- 不再对 legacy 形状套用插件 strict path validator,改由三层可达
  守卫保证安全:①new URL 归一化不变性(pathname 必须与 rawPath
  逐字节相同,原始反斜杠、原始/编码完整点段、双斜杠等一切会被
  WHATWG URL 改写的形状全部拒绝);②单段线格式(编码 token 不会
  在解析中分裂);③畸形百分号编码与控制字符拒绝
- token 段的 %2F/%5C 作为不透明内容放行,交旧路由解码后仅做
  签名比对;完整 . / .. 段已被不变性守卫全覆盖,删除不可达的
  冗余解码后检查(变异存活证实)
- 补 a/b、a\b 经 encodeURIComponent 生成 URL 的端到端 fall-through
  用例并断言旧路由收到逐字解码的 token;穿越 400 用例补编码完整
  点段与编码空字节

变异:摘不变性守卫(M13)与摘控制字符守卫(M14)均咬红,还原
复绿;Node v24.22.2 import dist 产物 14 例矩阵全过。

Co-Authored-By: Claude Fable 5 <[email protected]>
@deepcoldy

Copy link
Copy Markdown
Owner Author

第三轮复审(review #6057291279)的 P2 已独立复现并修复,追加提交 379514d(fast-forward,未改既有提交):

问题复现
自定义 secret a/b、a\b 经 publicWebhookUrl 的 encodeURIComponent 生成 /webhook/plugin/a%2Fb、/webhook/plugin/a%5Cb;上一轮复用插件 strict validator 后两者均 400,旧路由本可解码验签(query token 形式仍 202,证明仅路径形态被误拒)。

修复思路(按复审建议,不删安全校验,改为 legacy 专用语义)

  1. 不再对 legacy 形状套用插件 strict path validator,安全由三层可达守卫提供:
    • 归一化不变性:new URL(rawPath).pathname 必须与 rawPath 逐字节相同——实测 WHATWG URL 会保留 %2F/%5C(不改变段数),但把原始反斜杠、原始/编码完整点段、双斜杠改写成别的 pathname,后者一律拒绝;
    • 单段线格式:编码 token 在解析中不可能分裂成多段;
    • 畸形百分号编码(decode 抛错)与控制字符(如 %00)拒绝。
  2. token 段的 %2F/%5C 作为不透明内容放行,交旧连接器路由解码后仅做签名比对,不参与任何路径操作。
  3. 完整 . / .. 段已被不变性守卫全覆盖;解码后的冗余点段检查经变异证实不可达,按死守卫原则删除。

验证

  • 探针:a%2Fb/a%5Cb/混合编码均 202 到达旧路由且解码值逐字为 a/b、a\b;反斜杠穿越、点段穿越、编码完整点段、编码空字节全部仍 400;大小写变体与插件对照组不变
  • 新增 a/b、a\b 经 API 同款 encodeURIComponent 路径的端到端用例(断言旧路由收到解码 token),穿越用例补 %2e%2e/%2e/%00
  • bun run build 绿;vitest 9 套件 172 pass/2 skip;Bun 运行时腿 57 pass;Node v24.22.2 直接 import dist 产物 14 例矩阵全过
  • 变异 M13(摘不变性守卫)、M14(摘控制字符守卫)分别咬红;冗余点段检查的变异存活,证实其不可达后删除

🤖 Generated with Claude Code

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

379514deb5 复审结论:代码层面通过,无剩余阻断项

上一轮不透明 path Token 的兼容性回归已修复;本轮复跑此前全部历史探针,没有发现新的正确性或安全问题。合并仍以该 head 的完整 CI 通过为准。

本轮修复核验

  • 通过真实 Connector API 设置 secret=a/b、secret=a\b,取得的 publicWebhookUrl 分别为 /webhook/plugin/a%2Fb、/webhook/plugin/a%5Cb;两种 URL 在新生产分派顺序下均恢复 202 并到达旧连接器,与旧路由单独挂载的结果一致。
  • 新增判定保持 new URL(...).pathname === rawPath:原始斜杠穿越、原始反斜杠穿越、编码完整 . / .. 段均返回 400,不再进入 /__health;%00、畸形及截断百分号编码也为 400。
  • %2F / %5C 位于不透明 Token 段时 pathname 逐字不变,只在旧路由中解码并参与凭据比较,不会拆成额外路由段。独立探针中的 404 仅发生在未配置对应旧连接器的 fixture;配置真实记录后为 202,未命中健康检查。
  • 默认 Base64URL Token 与查询参数 Token 保持可用;GET 轮询仍进入旧路由并重新验签;大小写/百分号编码连接器 ID 均正常。

历史回归项复验

  • 精确小写、编码小写、PLUGIN、Plugin、编码大写均为 202;合法插件三段路由仍为 202,未知插件仍为 404。
  • 存量保留 ID 的 PUT 改名与 rotateSecret 均为 200;新建保留 ID 仍拒绝,同 ID 更新豁免未被放宽成 body 改名。
  • 两个 handler 的 resolveTarget 必填与 forbiddenPorts 显式注入保持不变。

本地验证

  • bun run build:通过。
  • 聚焦 vitest 9 套件(协议、两类路由、Connector API、目标解析、Dashboard 接入与环境注入):173/173 通过。
  • Bun 按每文件独立进程运行 6 个适用插件套件:合计 98/98 通过。含 vi.hoisted / vi.resetModules 的 vitest-only 文件按仓库规则不纳入 Bun 腿,已由上述 vitest 覆盖。
  • Node v24.22.2 加载本次 dist/:13 个合法形状 + 13 个拒绝形状全部符合预期;普通斜杠与反斜杠原始 HTTP 穿越对照均为 400。
  • git merge-tree --write-tree HEAD origin/master:与当前 master c6445c13ed 无冲突;工作树干净。
  • 发布本结论时,GitHub 仅显示该 head 的三个 CodeQL 检查仍在队列中,完整 CI 尚未出现/完成,未将其计为通过。

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

更正:补充 1 个 P2,撤回 379514deb5 的代码层面通过结论

在跨文件核对共享进程读取器时确认了一个原 PR 引入的生命周期回归。此前关于 legacy Webhook 三项修复均已通过的结论不变,但当前 head 仍不建议合并。

[P2] 进程身份暂时不可读会被共享读取器误判为 stopped,放行卸载/更新

位置:src/core/plugins/supervisor-client.ts:45-55,消费方 src/core/plugins/service-manager.ts:280-291。

原 PR 将共享 readPluginProcesses() 的存活条件从单纯的 PID 存活改为同时要求 processStart 匹配:

const alive = pidAlive(proc.pid)
  && !isLinuxZombie(proc.pid)
  && (!proc.processStart || readDurableProcessIdentity(proc.pid) === proc.processStart);

readDurableProcessIdentity() 在身份暂时不可读时返回 undefined。此时即使 PID 对应的真实插件进程仍然存活,共享读取器也会删除 PID、把 online 改成 stopped。assertPluginServiceStopped() 又把“无 PID 且 stopped”当作可继续执行,因而可能放行插件更新/卸载;启动路径也可能把身份未知的现有进程当成非 online,再发起一次 start。

使用真实 readPluginProcesses() 与 assertPluginServiceStopped() 做受控探针,仅替换进程身份读取器,使用当前存活的测试进程 PID:

身份读取匹配 birth:
  readPluginProcesses → online + 当前 PID
  assertPluginServiceStopped('demo', 'uninstall') → 抛错(保护生效)

同一存活 PID,身份读取返回 undefined:
  readPluginProcesses → stopped,无 PID
  assertPluginServiceStopped('demo', 'uninstall') → 不抛错(保护失效)

临时 vitest 探针的上述对照断言全部执行成功;文件已删除,工作树干净。这证明的是当前行为序列,不是新增回归测试已经合入。

代理目标解析需要身份 unknown/mismatch 时 fail closed,但共享生命周期读取器不能把 unknown 降格为 stopped。建议将 processStart 核验留在 resolveRunningPluginServiceTarget()(代理侧 503),恢复共享读取器对既有生命周期调用方的安全语义;或者引入保留 PID 的 unknown/错误态,并确保卸载、更新和 start 均不会把它当成 stopped。需要覆盖“PID 存活 + 身份读取 undefined”下卸载仍拒绝、代理仍 503 的成对回归测试。

其余已发布验证仍有效:opaque Token %2F/%5C 恢复 202;路径穿越保持 400;大小写、PUT 维护、插件对照均正常;build、9 个 vitest 套件 173/173 和适用的 Bun 套件通过。远端完整 CI 仍未完成。

readPluginProcesses 此前把"存活 PID 但 processStart 暂时不可读或
不匹配"也归入 stopped 并删除 PID,使 assertPluginServiceStopped
放行卸载/更新,可能在真实插件进程仍存活时继续执行;start 路径也
可能据此误判。

- 三态化进程投影:kill(0) 失败或僵尸才是 stopped(丢 PID);存活
  且身份匹配保留 online(含 PID/processStart);存活但身份不可读
  或不匹配(PID 复用候选、/proc 抖动)投影为 unknown,保留活 PID、
  不带 processStart
- isStoppedService 同时要求无 PID 与终态,unknown 因持有活 PID 天然
  fail-closed,卸载/更新/start 不再把它当 stopped
- 代理目标解析层不变:service-target 的 supervisor 分支仍要求
  online + processStart 严格匹配,unknown 一律 503
- supervisor 进程自身的 owner lock 与 reapOrphans 身份保护本就防止
  双开与误杀 recycled PID,本次只修正 dashboard/CLI 侧状态投影
- 补成对测试:存活 PID+身份不可读/不匹配时卸载拒绝且代理 503、
  身份恢复后回到 online;变异令 unknown 塌回 stopped 即咬红

Co-Authored-By: Claude Fable 5 <[email protected]>
@deepcoldy

Copy link
Copy Markdown
Owner Author

第四轮复审(review #6057906971)撤回通过后提出的 P2 已独立复现并修复,追加提交 9e9a849(fast-forward,未改既有提交):

问题复现(成立)
readPluginProcesses 把"kill(0) 存活但 readDurableProcessIdentity 暂时返回 undefined(/proc 抖动、boot_id 不可读、权限瞬断)或 processStart 不匹配(PID 复用)"也判成 stopped 并删掉 PID;isStoppedService 随之放行,assertPluginServiceStopped 不抛错,卸载/更新可在真实进程仍存活时继续。

修复:进程投影三态化

  • dead:kill(0) 失败或僵尸 → stopped,丢 PID(原语义保留)
  • verified:存活且(无记录出生身份,或身份匹配)→ 保留 supervisor 原 status + PID + processStart
  • unknown:存活但身份不可读/不匹配 → status=unknown,保留活 PID、不带 processStart
  • isStoppedService 本就要求 pid===undefined 且终态,unknown 持有活 PID 后天然 fail-closed,卸载/更新/start 不再误判
  • 代理层不变:service-target supervisor 分支仍要求 online + processStart 严格匹配,unknown 一律 503(与身份不可读时的对外行为一致)
  • supervisor 进程自身的 owner lock 与 reapOrphans(身份不可读即抛错、不匹配跳过不发信号)本就防止双开和误杀 recycled PID,本次只修正 dashboard/CLI 侧的状态投影,不改 supervisor 协调

成对测试(Kimi 要求的"卸载拒绝 + 代理 503")

  • 存活 PID + 身份读取 undefined:投影 unknown、保 PID;assertPluginServiceStopped('uninstall') 抛错;身份恢复后回到 online
  • 存活 PID + processStart 不匹配:unknown、保 PID;assertPluginServiceStopped('update') 抛错
  • service-target fail-closed 矩阵新增 unknown proc → 503 用例
  • 变异 M15(令 unknown 塌回 stopped)两个生命周期用例咬红,还原复绿

验证

  • bun run build 绿;vitest 9 套件 173 pass/2 skip;Bun 适用 7 套件 132 pass/2 skip(plugin-supervisor-state 含 vi.hoisted 属 vitest-only,按仓库规则不跑 Bun 腿,改动前即如此)

🤖 Generated with Claude Code

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

9e9a849e1d 复审结论:代码层面通过,无剩余行为阻断项

上一轮“存活但身份不可读/不匹配被误判 stopped”的 P2 已修复;此前所有 Webhook 兼容与路径安全修复保持有效。合并仍以该 head 的完整 CI 通过为准。

生命周期修复核验

使用真实 readPluginProcesses() 与 assertPluginServiceStopped(),以当前存活的测试进程做受控身份对照:

  • 身份匹配:online,保留 PID/processStart,卸载保护正常抛错。
  • 身份返回 undefined:unknown,保留活 PID、不带 processStart,卸载仍抛错。
  • 身份不匹配:unknown + 活 PID,更新仍抛错。
  • 身份恢复匹配:重新投影为 online 并恢复 processStart。

临时探针执行通过后已删除,工作树干净。所有 readPluginProcesses() 消费方也已核对:

  • assertPluginServiceStopped 要求无 PID 且处于终态,unknown 不会落入可卸载/可更新分支。
  • 手动服务快照会把带活 PID 的 unknown 纳入恢复,不会漏掉仍运行的 manual 服务。
  • 显式 start 最终仍经同一个 supervisor 的 revision 协调;owner lock 与 reapOrphans 的身份保护不因 Dashboard 投影改变。
  • 代理目标解析继续要求 online + processStart,unknown 一律 503。

历史回归项

  • a%2Fb、a%5Cb 等不透明 path Token 均实际恢复 202 并到达旧连接器。
  • 精确/编码小写及大小写变体旧连接器均正常;合法插件 202、未知插件三段路由 404。
  • 原始反斜杠、普通/编码完整点段、空字节、畸形编码保持 400;编码但路径不变的 Token 不会进入健康检查。
  • 存量保留 ID 的 PUT 改名与 rotateSecret 均为 200;新建保留 ID 仍拒绝。
  • resolveTarget 必填与 forbidden-port 显式注入保持不变。

本地验证

  • bun run build:通过。
  • 9 个相关 vitest 套件:174/174 通过。
  • 6 个 Bun 适用插件套件按独立进程执行:合计 98/98 通过;含 vi.hoisted / vi.resetModules 的 vitest-only 文件由上述 vitest 覆盖。
  • Node v24.22.2 加载本次 dist:13 个合法 + 13 个拒绝形状全部符合预期,原始 HTTP 穿越对照均为 400。
  • 与当前 master 8285bd89b0 的 merge-tree 无冲突,工作树干净。
  • 发布时该 head 的 CodeQL 检查仍在排队/执行,完整 CI 尚未完成,未计为通过。

非阻断格式项:test/plugin-supervisor-state.test.ts:146 有一行行尾空格,git diff --check 9e9a849e1d^ 9e9a849e1d 会报 trailing whitespace;可顺手删除,不影响上述行为结论。

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

补充更正:9e9a849e1d 仍有 1 个 P2,先前通过结论作废

三态投影与卸载/更新保护本身已修复,但“身份恢复后代理恢复”的链路仍被陈旧持久状态阻断。当前 head 暂不建议合并。

[P2] 瞬时 unknown 落入 service.json 后,代理可能在身份恢复后仍持续 503

位置:src/core/plugins/service-manager.ts:569-580、src/core/plugins/webhooks/service-target.ts:78-82、:118-130。

可达序列:

  1. 插件进程仍存活,但 /proc 短暂不可读;实时投影为 unknown。
  2. 一次 Dashboard 状态查询调用 listPluginServiceStatus(),经 writeServiceState() 把 status: unknown 持久化到 service.json。
  3. 身份读取恢复,readPluginProcesses() 已重新返回 online + processStart。
  4. resolveRunningPluginServiceTarget() 却在读取实时进程之前先要求持久化的 serviceState.status === 'online',因此直接返回 503。只要没有再次状态查询或生命周期操作刷新文件,后续 Webhook / serviceFetch 都会继续失败。

使用真实 resolver、临时落盘 service.json 和固定的“实时 online + 已验证身份”进程投影复现:

persisted=unknown, liveProcess=online+verified
→ 503 plugin_service_unavailable

仅把 persisted 改为 online,实时进程与 desired/token/端口完全不变
→ ok:true,解析到 127.0.0.1:44199 + 已验证 PID/processStart

探针命令:

bun scripts/fenced-run.ts -- bun /tmp/botmux-pr3830-new-head-lGddtl/stale-service-state.ts

建议在 supervisor 分支中以当前已验证的 desired + 进程状态为准,不要用过期的持久化 status 阻止读取恢复后的实时进程;端口仍须与 desired 一致,PID/processStart、禁用端口、跨插件冲突和令牌校验保持 fail-closed。无 supervisor 的旧分支可继续使用持久身份校验。若选择恢复时刷新持久状态,则需要保证该刷新在代理路径上必然发生且可观察,不能只依赖下一次人工状态查询。

请增加成对端到端回归:

  • 持久状态 unknown + 实时 unknown → 503;
  • 持久状态 unknown + 实时已验证 online → 成功恢复,不再依赖另一次状态写入。

本轮其它结论不变:三态卸载/更新保护、opaque Token、大小写、PUT、路径穿越与插件对照均通过;build、9 个 vitest 套件 174/174、6 个 Bun 适用套件 98/98 和 Node dist 矩阵均通过。test/plugin-supervisor-state.test.ts:146 仍有一处非阻断行尾空格。远端完整 CI 尚未完成。

resolveRunningPluginServiceTarget 此前在进入 supervisor/非 supervisor
分支前,先要求持久化 service.json 的 status 严格等于 online。
/proc 短暂不可读会让状态投影瞬时变成 unknown 并被 listPluginServiceStatus
落盘;身份恢复、实时进程表已回到 online+processStart 后,该入口检查
仍持续返回 503,使 webhook 与 serviceFetch 在缓存被刷新前一直失败。

- 区分两种证据模式:存在 supervisor 文件时,权威输入是宿主写的
  desired(running、PORT)与实时进程表(pid+出生身份),service.json
  只是 dashboard 状态投影,不再参与判定;无 supervisor 文件时
  service.json 是唯一持久证据,保留 online+活非僵尸 pid+身份匹配的
  全部严格校验,行为不变
- 端口、PID/processStart、禁用端口、跨插件冲突、令牌校验在 supervisor
  模式继续 fail-closed;desired 缺 PORT 仍拒绝,实时 unknown 仍 503
- 补成对测试:持久 unknown+实时已验证 online 恢复成功、持久 unknown+
  实时 unknown 仍 503、desired 端口权威于陈旧缓存;变异恢复旧入口
  status 硬门即咬红(M16)
- 顺手清掉测试文件行尾空格

Co-Authored-By: Claude Fable 5 <[email protected]>
@deepcoldy

Copy link
Copy Markdown
Owner Author

第五轮复审(review #6058443530)撤回通过后提出的 P2 已独立复现并修复,追加提交 f9a1247(fast-forward,未改既有提交):

问题复现(成立)
真实 resolver 探针:service.json 被瞬时 /proc 抖动写成 status: unknown 后,即使实时 readPluginProcesses() 已恢复 online + processStart,入口处对持久状态的 status === 'online' 硬检查仍返回 503;仅把持久状态改回 online(其它不变)即成功——陈旧缓存阻塞了代理恢复。

修复:按证据来源分两种模式

  • 有 supervisor 文件:权威输入改为宿主写的 desired(running、PORT)与实时进程表(pid + 出生身份);service.json 仅作为 dashboard 状态投影,不再参与判定,因此瞬时 unknown 落盘不影响恢复。
  • 无 supervisor 文件:service.json 是唯一持久证据,保留原全部严格校验(online + 活非僵尸 pid + 出生身份匹配),行为不变。
  • supervisor 模式下端口/PID/processStart/禁用端口/跨插件冲突/令牌校验全部继续 fail-closed:desired 缺 PORT 拒绝、实时 proc 仍 unknown 仍 503。

成对测试(按复审要求)

  • 持久 unknown + 实时 unknown → 503
  • 持久 unknown + 实时已验证 online → 恢复成功(返回 desired 端口)
  • 另加:desired 端口权威于陈旧缓存(缓存写 55555、desired 44199 时拨 44199);原"端口漂移即 503"用例编码的是旧语义,已由该权威用例取代
  • 非 supervisor 模式对缓存 unknown 仍严格拒绝(Node dist 三场景矩阵验证)
  • 变异 M16(恢复旧入口 status 硬门)恢复用例咬红,还原复绿
  • 顺手清理指出的 test/plugin-supervisor-state.test.ts 行尾空格

验证

  • bun run build 绿;vitest 9 套件 173 pass/2 skip;Bun 适用 7 套件 132 pass/2 skip;回归 3 套件 77 pass;Node v24.22.2 import dist 三场景全过

🤖 Generated with Claude Code

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f9a1247dc7 复审:1 个 P2

陈旧 status 阻塞恢复已修复,但将 desired 端口提升为权威后,还缺少“实时进程属于该 desired 配置代际”的校验。当前不建议合并。

[P2] 端口更新窗口会把旧进程身份与新端口拼成代理目标

位置:src/core/plugins/webhooks/service-target.ts:97-138,尤其是实时进程检查 :118-132 与 port = desiredPort :134。

当前 supervisor 分支要求实时进程 online + processStart,但没有比较 proc.configHash 与 desiredEntry.spec.external.configHash。服务更新 PORT 时存在如下窗口:

  1. 旧进程仍存活并监听旧端口,进程表携带旧 configHash;
  2. desired.json 已写入新 PORT 和新 configHash,supervisor 尚未完成旧进程退出/新配置启动;
  3. 旧 PID 的出生身份仍匹配,因而通过现有实时检查;
  4. resolver 返回旧 PID/processStart + 新 desired 端口,错误地认为新配置已经就绪。

真实 resolver 受控探针:

desired:PORT=44200, configHash=new-config
实时进程:旧 PORT=44199, configHash=old-config, 原 PID/processStart
结果:ok:true, port=44200, 返回旧 PID/processStart

仅把实时 configHash 改为 new-config
结果:ok:true(对照)

命令:

bun scripts/fenced-run.ts -- bun /tmp/botmux-pr3830-new-head-lGddtl/stale-config-generation.ts

这通常会在重启窗口造成 502;若新端口已有其它监听器,还会把宿主注入的插件 Bearer Token 发往错误服务。上一轮旧实现要求缓存端口与 desired 一致,恰好挡住了这个窗口;本轮移除该关系后,需要用配置代际校验替代,而不是仅依赖进程出生身份。

建议在放行前要求实时进程的 configHash 与 desired spec 的 configHash 明确匹配(生产 desired 缺少有效 hash 时应 fail closed,或采用等价的 supervisor 已确认 revision + 当前进程配置校验)。同时保留陈旧 status 恢复能力:

  • 持久 unknown + 实时 verified online + configHash 匹配 desired → 成功;
  • 实时 online 但 configHash 为旧值/缺失 → 503;
  • 实时 unknown → 继续 503;
  • 非 supervisor 分支不变。

需要明确旧记录缺少 configHash 时的升级策略,避免无意识长期拒绝;但不能让 undefined===undefined 成为生产放行条件。

已验证保持不变的部分

  • 持久 unknown 不再阻塞已验证实时进程恢复;
  • 三态卸载/更新保护、desired running/PORT、跨插件冲突、禁用端口与令牌校验保持;
  • 所有 Webhook 历史探针通过;
  • bun run build、9 个 vitest 套件 174/174、6 个 Bun 适用套件 98/98、Node dist 矩阵均通过;
  • 完整 patch 的 git diff --check 通过,工作树干净,与当前 master 无合并冲突。
  • 远端 CI 尚未全部完成,本结论不依赖其状态。

desired 端口成为权威后,resolver 只验证实时进程 online+processStart,
未比较 configHash。配置更新窗口内 desired 已切到新 hash/新端口、
supervisor 尚未完成旧进程退出时,会组合出"旧进程+新端口"并返回旧
PID,可能把宿主注入的插件 Bearer Token 发给新端口上的错误监听器。

- supervisor 分支放行前要求 desired spec 与实时 proc 都携带非空
  configHash 且严格相等;任一侧缺失即 fail-closed,杜绝
  undefined === undefined 放行;生产链路 serviceConfigHash 恒为
  sha256 非空串,supervisor freshProc 同步写入 proc 行
- 非 supervisor 分支不经过该检查,service.json 唯一证据语义不变
- 补代际用例:hash 匹配恢复成功、旧 hash/ proc 缺 hash/ desired
  缺 hash 均 503、实时 unknown 仍 503;矩阵夹具统一带匹配 hash
- 变异 M17(摘除 hash 比较)代际用例咬红,还原复绿

Co-Authored-By: Claude Fable 5 <[email protected]>
@deepcoldy

Copy link
Copy Markdown
Owner Author

第六轮复审(review #6058886172)的 P2 已独立复现并修复,追加提交 f3559d9(fast-forward,未改既有提交):

问题复现(成立)
真实 resolver 探针:desired 已切到 PORT=44200 + configHash=new-config,而实时进程仍是旧 PID/processStart + configHash=old-config 时,resolver 返回 ok:true 并把新端口与旧 PID 组合;两侧 hash 都缺失时也靠 undefined===undefined 放行。配置更新窗口期可能把宿主 Bearer Token 发给新端口上的错误监听器。

修复:代际一致性硬校验

  • supervisor 分支放行前要求 desired spec 与实时 proc 都携带非空 configHash 且严格相等;任一侧缺失即 503,杜绝 undefined===undefined。
  • 生产链路 serviceConfigHash 恒为 sha256 非空串(service-manager),supervisor freshProc 同步写入 proc 行(fleet-supervisor),所以正常运行不会被该检查误伤。
  • 非 supervisor 分支不经过此检查,service.json 唯一证据的语义完全不变。
  • 端口/PID/processStart/禁用端口/跨插件冲突/令牌/unknown proc 等既有 fail-closed 全部保留。

测试(按复审四点要求)

  • 持久 unknown + 实时 verified online + hash 匹配 → 成功(上一轮 1b 保留)
  • 实时 online 但 hash 为旧值 → 503;proc 缺 hash → 503;desired 缺 hash → 503
  • 实时 unknown → 继续 503
  • 非 supervisor 分支行为不变(既有严格矩阵原样通过)
  • 变异 M17(摘除 hash 比较)代际用例咬红,还原复绿
  • Node v24.22.2 import dist 五场景矩阵全过

验证:bun run build 绿;vitest 9 套件 173 pass/2 skip;Bun 适用 7 套件 132 pass/2 skip。

🤖 Generated with Claude Code

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f3559d95d2 复审结论(本地代码验证)

上一轮 configHash 代际问题已修复,陈旧 status 恢复与实时 unknown 拒绝同时成立;此前 Webhook 兼容、路径安全和生命周期保护均未回归。本地未发现新的行为阻断项。合并仍以该 head 的完整远端 CI 通过为准。

代际与恢复探针

真实 resolver 受控复验结果:

  • desired=PORT=44200,new-config,实时进程仍为 old-config:503,不再组合“新端口 + 旧 PID”。
  • desired 与实时进程均为非空 new-config:成功解析到新端口和已验证 PID/processStart。
  • desired 与实时进程都缺 hash:503,不存在 undefined===undefined 放行。
  • 实时进程为 unknown:继续 503。
  • 持久 service.json=unknown + 实时 verified online + 两侧生产 hash 匹配:恢复成功;持久 online 对照同样成功。旧探针夹具已按生产契约补齐 configHash。
  • 非 supervisor 分支不经过 configHash 检查,原有持久 online + 活非僵尸 PID + 身份匹配语义不变。

生产传播链也已核对:serviceConfigHash 始终生成非空 SHA-256,FleetSupervisor 在新进程行中同步记录该 hash;三态读取器只保留该字段,不会将 unknown 误当 verified。

历史回归与本地验证

  • 所有 Webhook 历史探针通过:opaque Token、大小写/编码大小写、查询 Token、PUT 改名与 rotateSecret、合法插件和未知插件对照。
  • 原始反斜杠、普通/编码完整点段、空字节和畸形编码保持 400;路径不变的不透明编码 Token 正常交旧路由。
  • bun run build:通过。
  • 9 个相关 vitest 套件:174/174 通过。
  • 6 个 Bun 适用插件套件按独立进程执行:合计 98/98 通过;vitest-only 文件由上述 vitest 覆盖。
  • Node v24.22.2 加载本次 dist:13 个合法 + 13 个拒绝形状全部符合预期,原始 HTTP 穿越对照均为 400。
  • 完整 patch 的 git diff --check 通过,工作树干净;与当前 master 749fb2d600 的 merge-tree 无冲突。
  • 远端 CI 尚需全部完成后方可合并;本结论只覆盖上述代码与本地实测。

@deepcoldy

Copy link
Copy Markdown
Owner Author

按维护者决定(不放宽 G4 例外口径),已在作者分支普通 merge 最新 origin/master 生成新 head fdf00bc058(非 force-push;merge 父母 f3559d95d2 分支侧 + 81a9938b1a master 侧),请复审合并增量。

合并事实

  • git merge-tree --write-tree 无冲突;本地落地 tree 7f19a783d6 与 merge-tree 预测逐字一致(三点一线),GitHub 报 MERGEABLE
  • 整段 delta 与最新 master 仅交集 src/dashboard.ts;merge 未改动本 PR 任何核心文件(protocol/service-target/supervisor-client/plugin-webhook-routes/plugin-service-proxy/connector-api 逐字保留),交集文件由 git 自动合并双方区段
  • bun install --frozen-lockfile 无依赖漂移

合并树本地验证(tree 7f19a783d6)

  • bun run build(tsc + dashboard bundle + audit)绿
  • PR 定向 vitest 9 套件 173 pass/2 skip;Bun 适用 7 套件 132 pass/2 skip;交集邻近回归(legacy webhook-routes、dashboard-plugin-settings、test-hygiene)77 pass
  • 此前各轮变异 M1–M17 结论在该树上仍由同一批测试钉住

新 head 的完整 CI 已派单(run 45672377501 / 45672387709),首跑结果出来后再合入。

🤖 Generated with Claude Code

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fdf00bc058 合并增量复核:代码层面通过,未发现合并回归

合并事实

  • 远端 head 与本地均为 fdf00bc0583c94f9cc5f8991d8b925bc13089bae。
  • 父母确认为分支 f3559d95d2 与 master 81a9938b1a;实际 tree 为 7f19a783d6,与重新执行 git merge-tree --write-tree 的预测完全一致。
  • 以共同祖先 502c250981 分别计算双方文件集,真正交集只有 src/dashboard.ts。
  • protocol.ts、service-target.ts、service-manager.ts、supervisor-client.ts、plugin-webhook-routes.ts、plugin-service-proxy.ts 六个核心文件在 merge 前后逐字一致。

Dashboard 交集共存

合并树同时保留双方行为:

  • src/dashboard.ts:4367:earlyGuard 仍在 new URL() 之前;
  • :4394:master 新增的 oncall capability 路由保留,且拥有自己的随机遇票校验;
  • :4490-4494:插件 webhook 仍先于旧 connector 路由,legacy fall-through 可继续工作;
  • :4746-4749:service proxy 仍位于 Dashboard 身份与全局写来源/CSRF 检查之后;
  • forbidden-port 聚合、stop/restart 的认证流撤销 teardown 均保留。

未发现自动文本合并导致的路由覆盖、鉴权顺序颠倒或 master 路由丢失。

合并树实测

  • bun run build:通过。
  • 9 个插件相关套件 + oncall-sidebar:178/178 通过。
  • 6 个 Bun 适用插件套件按独立进程执行:98/98 通过。
  • 全部历史探针通过:opaque Token、大小写、PUT 维护、路径穿越、configHash 代际、陈旧 status 恢复、实时 unknown 拒绝及插件对照。
  • Node 24 加载合并树 dist:13 个合法 + 13 个拒绝形状通过,原始 HTTP 穿越对照均为 400。
  • 最终 PR 相对新 master 的 delta 通过 git diff --check;package.json 与 bun.lock 在该 delta 中无变化;工作树干净。
  • 远端完整 CI 已派单,但发布时仍在队列中,未将其计为通过。合并/ squash 仍以 CI 最终全绿为条件。

deepcoldy added a commit to botmux-ai/botmux-plugin-github that referenced this pull request Nov 25, 2026
- [P1 #1] Defer webhook knownPrs commits until after action succeeds; refuse committing knownPrs on synchronize when it would mask undiscovered PRs, draft->ready, closed->open, or incomplete groups, and invalidate repo ETag for poll recovery
- [P1 #2] Add cross-process per-PR exclusive lockfile around HostBridge group orchestration, persist createAttempt.outcomeUnknown so dropped IPC responses fail closed rather than switching to CLI fallback, and gate CLI/settings in-process fallback strictly on ECONNREFUSED/unreachable (never ECONNRESET on POST mutations)
- [P2 #3] Align dist/webhooks/index.json with deepcoldy/botmux#3830 (mount-relative path "/events" -> endpoint "/webhooks/github", maxBodyBytes 1048576) and enforce isolated BOTMUX_PLUGIN_WEBHOOK_TOKEN Bearer auth
- [P2 #4] Prevent ETag advancement on single-PR close lookup failures, validate multi-page (>100 PR) repositories across all pages with per-page ETags and legacy cold-restart page-count inference, and invalidate repo ETag on webhook/openPr mutations
- [P2 #5] Implement explicit reopen lifecycle transitions with lifecycleGeneration-scoped dedup keys and idempotent closed state landing across poll and webhook paths (including onPrClosed=false and creating groups)
- [P2 #6] Keep PR groups in creating state until kickoff readback verification, top-notice pinning, and optional share-link posting complete, allowing poll and manual openPr to resume only unfinished steps
- [P2 #7] Add generation counter + AbortSignal propagation across active->dormant hot-reloads and per-PR handlers so stale polls/webhooks immediately halt without further pagination or state writes
- [P2 #8] Bound DeliveryDedupCache in-flight count/TTL and PerPrSerialQueue global pending cap with cancellable per-task timeouts, synchronously returning retryable HTTP 429/503 instead of fake 202
- [P2 #9] Pre-validate candidate clients in reloadConfig before mutating state/timers, commit config/hash in runner.ts only after reload succeeds, return HTTP 500 ok:false on error, and preserve auto-retry
- [P2 #10] Fold --repo access verification and slug validation into testAuth top-level ok and CLI exit code
- [P2 #11] Enforce <=100 code-point bounded canonical group name prefixes for max-length owner/repo names while preserving anchored GET /api/groups deduplication
- [P3 #12] Reject non-immediate ancestor symlinks below trusted OS roots in src/security/fs.ts (and recover empty/truncated lockfiles via staleMs), and restore deepcoldy/botmux links in README.md

Co-Authored-By: Claude Code <[email protected]>
@deepcoldy

Copy link
Copy Markdown
Owner Author

CI 分片超时根治 PR #3853 已合入 master(squash 40c96b6,test job timeout 30→45 分钟,双审+首跑 16/16 全绿)。本分支已再次普通 merge 最新 master,新 head f5324118d0(非 force-push;merge 父母 fdf00bc058 + 40c96b6686),请复核第二次合并增量。

合并事实

合并树验证(tree 850f0a736e)

  • bun run build 绿
  • PR 定向 vitest 9 套件 173 pass/2 skip;Bun 适用 7 套件 132 pass/2 skip;交集邻近回归(legacy webhook-routes、dashboard-plugin-settings、test-hygiene)77 pass
  • 新 head 完整 CI 已派单(run 45719390206 / 45719396250),本次 test 分片在 45 分钟预算内运行

🤖 Generated with Claude Code

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f5324118d0 第二次合并增量复核:代码层面通过,未发现合并回归

合并事实与文件交集

  • 父母为 fdf00bc058 与 40c96b6686,实际 tree 为 850f0a736e,与重新执行 merge-tree 的结果一致。
  • master 侧为 8 个提交、68 个变更文件。
  • 按共同祖先 81a9938b1a 分别计算双方变更集,精确文件交集为 src/dashboard.ts 一项,而非 23 项;直接比较 fdf..40c 两棵树会把 PR 自身新增文件显示为删除,不能当成 master 侧改动。该计数差异不影响下述行为结论。
  • 六个核心插件实现文件在 merge 前后逐字一致;.github/workflows/ci.yml 与 40c96b6686 一致,test 分片保持 45 分钟;最终 delta 未改 package.json / bun.lock。

Dashboard 与行为验证

master 侧 Dashboard 增量集中于群组创建与 members-display,和插件挂载区段不重叠。合并树仍保持:

  • earlyGuard → URL 解析;
  • oncall capability 路由;
  • 插件 webhook → legacy connector;
  • Dashboard 身份/写来源/CSRF → service proxy;
  • 群组创建新逻辑及其错误处理。

合并树实测:

  • bun run build:通过。
  • 插件、oncall、群组路由与 CI 分片约束共 15 个 vitest 套件:215/215 通过。
  • 6 个 Bun 适用插件套件:98/98 通过。
  • 全部历史探针通过:opaque Token、大小写、PUT 维护、路径穿越、configHash 代际、陈旧 status 恢复及插件对照。
  • Node 24 加载合并树 dist:13 个合法 + 13 个拒绝形状通过,原始 HTTP 穿越对照均为 400。
  • 最终 PR delta 通过 git diff --check,工作树干净。

发布时 build、部分 CodeQL 与 bun-binary 已通过,其余 test/bun-test/binary/CodeQL 检查尚未全部完成;squash 仍以首跑全绿为条件。

@github-actions

Copy link
Copy Markdown

🚀 Released in v3.59.34

deepcoldy added a commit to botmux-ai/botmux-plugin-github that referenced this pull request Nov 26, 2026
* feat: implement @botmux-ai/plugin-github PR watcher and automated review group plugin

- Add self-contained esbuild ESM build pipeline (Node 22+ and standalone Bun binary compatible, zero runtime dependencies, atomic dist swap + dist/botmux-build/stamp)
- Implement dormant-by-default background service with PAT, GitHub App RS256 JWT (GHES-ready), and in-memory gh auth token fallback, ETag 304 zero-quota polling, per-resource core/search <10% throttling, 429/403 1m->1h monotonic backoff, fail-closed proxy + HTTP CONNECT TLS tunneling, and dual-layer secret redaction
- Implement dual-source event ingestion (authoritative poller with first-run baseline snapshot + optional 127.0.0.1 HMAC-SHA256 webhook receiver) feeding a shared FIFO per-PR serial queue
- Implement anti-injection <untrusted_pr_metadata> XML escaping with isFork/maintainerCanModify flags and Feishu <at>/@ALL neutralization
- Implement crash-safe dual-core HostBridge (node:http loopback IPC bypassing Bun $http_proxy 403, creating lock, anchored GET /api/groups dedup, POST /api/groups/create with current-core/CLI fallbacks, kickoff readback verification, dual-path Feishu/Lark top-notice, idempotent PR share-link comment, onNewCommit/onPrClosed notifications)
- Add Dashboard UI (#/plugins/github using api.react + api.listBots + dual-path serviceFetch/getSettings), write-only 0600 server/settings.js adapter, 4 CLI commands (github:status, github:sync, github:open-pr, github:test-auth), docs/plugin-market-entry.json, bilingual README, and 34 unit/integration/packaging tests

Co-Authored-By: Claude Code <[email protected]>

* fix: address all PR #1 independent review findings (2x P1, 9x P2, 2x P3)

- [P1 #1] Defer webhook knownPrs commits until after action succeeds; refuse committing knownPrs on synchronize when it would mask undiscovered PRs, draft->ready, closed->open, or incomplete groups, and invalidate repo ETag for poll recovery
- [P1 #2] Add cross-process per-PR exclusive lockfile around HostBridge group orchestration, persist createAttempt.outcomeUnknown so dropped IPC responses fail closed rather than switching to CLI fallback, and gate CLI/settings in-process fallback strictly on ECONNREFUSED/unreachable (never ECONNRESET on POST mutations)
- [P2 #3] Align dist/webhooks/index.json with deepcoldy/botmux#3830 (mount-relative path "/events" -> endpoint "/webhooks/github", maxBodyBytes 1048576) and enforce isolated BOTMUX_PLUGIN_WEBHOOK_TOKEN Bearer auth
- [P2 #4] Prevent ETag advancement on single-PR close lookup failures, validate multi-page (>100 PR) repositories across all pages with per-page ETags and legacy cold-restart page-count inference, and invalidate repo ETag on webhook/openPr mutations
- [P2 #5] Implement explicit reopen lifecycle transitions with lifecycleGeneration-scoped dedup keys and idempotent closed state landing across poll and webhook paths (including onPrClosed=false and creating groups)
- [P2 #6] Keep PR groups in creating state until kickoff readback verification, top-notice pinning, and optional share-link posting complete, allowing poll and manual openPr to resume only unfinished steps
- [P2 #7] Add generation counter + AbortSignal propagation across active->dormant hot-reloads and per-PR handlers so stale polls/webhooks immediately halt without further pagination or state writes
- [P2 #8] Bound DeliveryDedupCache in-flight count/TTL and PerPrSerialQueue global pending cap with cancellable per-task timeouts, synchronously returning retryable HTTP 429/503 instead of fake 202
- [P2 #9] Pre-validate candidate clients in reloadConfig before mutating state/timers, commit config/hash in runner.ts only after reload succeeds, return HTTP 500 ok:false on error, and preserve auto-retry
- [P2 #10] Fold --repo access verification and slug validation into testAuth top-level ok and CLI exit code
- [P2 #11] Enforce <=100 code-point bounded canonical group name prefixes for max-length owner/repo names while preserving anchored GET /api/groups deduplication
- [P3 #12] Reject non-immediate ancestor symlinks below trusted OS roots in src/security/fs.ts (and recover empty/truncated lockfiles via staleMs), and restore deepcoldy/botmux links in README.md

Co-Authored-By: Claude Code <[email protected]>

* fix: address all PR #1 round-2 review findings (5x P1, 7x P2, 1x P3)

- [P1-1] Keep createAttempt.outcomeUnknown fail-closed across empty GET /api/groups responses until unknownOutcomeSettleMs elapses (while immediately adopting delayed chats once visible), fail closed on malformed GET /api/groups or invalid/future startedAt, and forward idempotencyKey on create
- [P1-2] Explicitly parse boolean CLI flags (--dry-run=true/false/1/0, --json) and reject invalid boolean values, unknown flags, and unexpected positional arguments with exit code 1
- [P1-3] Defer knownPrs cursor and ETag advancement whenever a PR hits skip_rate_limited (hourly creation cap on poll or opened/ready_for_review/reopened webhook) so deferred PRs automatically retry after cap expiry
- [P1-4] Fail closed in loadExistingConfigStrict() and normalizeAndValidateConfig() on corrupt, non-object, wrong-typed, or symlinked config.json instead of overwriting PATs and rules with defaults
- [P1-5] Preserve and migrate credentials stored only in proxy.url userinfo across redacted Dashboard saves while allowing explicit clearPassword, password rotation, and username edits
- [P2-1] Fail closed with StateCorruptError on corrupt or wrong-typed state.json (returning empty state only on ENOENT) without overwriting the original file
- [P2-2] Re-resolve live rule/enabled after waiting on in-flight polls (using a while loop) and before each repo in sync()
- [P2-3] Paginate all issue comment pages with early-stop marker matching and persisted shareLinkCommentId verification for postShareLinkToPr idempotency
- [P2-4] Validate PR numbers with strict /^\d+$/ + Number.isSafeInteger and valid owner/repo slugs across Dashboard, CLI parsePrSpec, watcher.openPr, and runner /api/open-pr
- [P2-5] Prevent live-PID per-PR locks from expiring by wall-clock age alone; keep the exclusive FileHandle open for inode-verified in-place utimes() lease renewal serialized with release() plus pre-create fencing
- [P2-6] Clear createAttempt.outcomeUnknown only for deterministic pre-create CLI validation failures (structured chatCreated:false/definitelyNotCreated, ENOENT/EACCES, or anchored pre-create errors with zero chatId in stdout/stderr and non-killed exit), keeping ambiguous CLI failures fail-closed
- [P2-7] Preserve already-202-accepted queued webhooks across active->active reloads using live repo rules while still aborting cleanly on active->dormant or repo disable
- [P3] Do not count empty terminal pages in persisted pageCount and accurately mark per-page hasNonEmptyNextPage so exact-100/200-PR repos stop polling empty trailing pages

Co-Authored-By: Claude Code <[email protected]>

* fix: close all 6 PR #1 round-3 review boundary findings (2x P1, 4x P2)

- [P1 #1] Strictly validate all existing config and incoming patch field types (especially repo rule boolean/array/enum/number fields, nested objects, null scalars, and secret patches) before normalization so wrong-typed configs/patches fail closed without overwriting stored settings
- [P1 #2] Distinguish maxPages-capped pagination ('unknown_capped') from verified terminal pages ('verified_terminal') using explicit 1-based page numbers, separate skipCacheWrite (dryRun only) from bypassEtag, sync persistedEtag/previousTruncated, and handle single-page 304 Link transitions so 304 never flips truncated true->false
- [P2 #3] Align CLI pre-create error classifier with real Botmux core production stderr formats (EN & ZH --working-dir, --bot, --chat-mode, --kickoff-bot 与/未匹配到/匹配到多个, and assertTurnTransportOrExit) and test against real production strings
- [P2 #4] Fail closed with StateCorruptError on non-string values inside processedEvents/processedDeliveries as well as invalid schemaVersion, repos/prGroups entries, and wrong-typed service.* fields
- [P2 #5] Record and verify durable process-start + Linux boot_id identity (including PID 1 in containers, zombie/dead state detection, and transient probe safety) in lockfile payloads so PID-reused orphan locks are reclaimed while genuine live owners remain protected
- [P2 #6] Add per-repo lifecycle epochs incremented on disable/removal/re-enable (and preserved across active->active reloads and rolled back on reload failure) to prevent pre-disable queued webhooks from running after disable -> re-enable

Co-Authored-By: Claude Code <[email protected]>

* fix: treat any multi-page/capped 304 -> explicit terminal Link transition as modified and evict stale trailing pages

- Treat any cached has_next / unknown_capped / multi-page / trailing-cache -> explicit terminal Link transition on 304 (for both page 1 and page 2+) as anyPageModified=true so watcher reconciles and closes disappeared trailing-page PRs instead of returning notModified:true early
- Evict all stale cached pages beyond terminal pageCount on shrinks (2->1, 3->2, 3->1) so subsequent steady-state 304 polls cleanly return notModified:true without hitting dead pages
- Add end-to-end regressions covering 2->1 watcher close reconcile + steady-state 304, 3->2 via page-2 304 terminal Link, 3->1 via page-1 304 terminal Link, and maxPages=1 capped->terminal->steady-state 304

Co-Authored-By: Claude Code <[email protected]>

---------

Co-authored-by: Claude Code <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant