Skip to content

[PR] fix: incremental lane marker divert no longer bypasses /__acp/* management plane via forged loopback identity (#3343) | [PR] fix: 增量车道 marker divert 不再以伪造回环身份绕行 /__acp/* 管理面(#3343) - #3349

Merged
ranxianglei merged 6 commits into
masterfrom
2026-10-16_incremental-divert-admin-authz
Oct 17, 2026

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Oct 16, 2026 •

Copy link
Copy Markdown
Owner

Fixes #3343

问题:增量压缩车道(#3248)的 marker divert 会把发往 /__acp/* 管理路径的请求劫进车道重放,而重放请求的源地址被写死成 127.0.0.1、Host 取调用方自己填的头——管理面的三道闸门(反隧道/回环/trusted-origin)全部被绕过。在 rollout pluginIncrementalTurns 开启且代理绑定非回环地址时,局域网内任意客户端可凭两个头对任意 conversationId 执行 /__acp/* 管理操作。默认配置(rollout=0%、仅回环监听)不受影响,故此前是休眠状态。

修法 — commit 1 cd6db9251(两处最小改动):

  1. src/server/handle.ts:marker divert 放行条件增加 /__acp/ 前缀排除——与既有的 /__bili/ 排除对齐。这些路径回到 handleAdminRoute,由闸门按调用方真实 socket 判定(回环照常,远程得到标准 403)。
  2. src/incremental-lane.ts:合成重放不再伪造 remoteAddress,透传真实调用方地址。本地部署看到的值和以前完全一致(本来就是 127.0.0.1/::1);远程调用方降级为普通非回环流量,顺带堵住了重放链路上其他按 socket 判信任的点(transcript-resume 头等)。

修法 — commit 2 e2216e399(补全 #3343 边界,落实 issue 建议修法第 1 条):
commit 1 之后仍有第三重后果未堵:非回环 peer 仍可把增量形状 body(conversationId = 任意已知会话)POST 到普通模型路径——divert 无源地址闸门,applyTurn 会替它写 canonical 状态(resync 覆盖受害者历史;空 delta + sticky system 持久化注入的系统提示词,且按 sticky 语义存活于受害者自己的 resync 恢复)。本 commit 在 divert 入口对增量形状的 turn 应用 adminGateDenial(回环 + 反隧道 + trusted-origin,与直连 /__bili/plugin/turn 入口同一套闸门):

  • 非回环/隧道/不可信源对 shaped turn 一律 403(模型路径与管理路径一致拒绝);marker 盖着的 full-resend body 仍从任意来源走正常管线(body shape 对模型路径仍是最终判词);
  • 抽出共享谓词 isManagementPath()(src/server/admin.ts),handleAdminRoute 与 divert 共用一处定义;
  • 合成 forward 直接透传 req.socket(替代逐字段拷贝 + ?? "127.0.0.1" 兜底——兜底会把 remoteAddress 为 undefined 的 peer(如 unix socket)重新伪造回环);
  • PLUGIN.md(en/zh):marker divert 一节写明信任级。

这不是新的产品决定:直连 turn 端点本就回环门控(lane 写入面早已是回环级),divert 只是漏了执行同一标准;正常远程宿主不受影响——其 GET 探针本来就 403,因此不会发 delta。

行为变更披露(旧值 → 新值 + 原因):

  • 非回环调用方发 marker + 增量形状 body 到模型路径:旧 = 车道照常处理(在自报 conversationId 下写 canonical 状态,即漏洞本身);新 = 403。回环调用方在所有情形零变化。
  • 子情形:rollout 关闭时,非回环 + shaped body 由 503 变 403(源闸门先于功能开关判定)——拒绝更严但语义更准(是授权失败,不是功能未开)。

回归测试(两文件共 9 例;A/B 已验证:安全断言在修复前树全部失败、可用性例通过):

  • tests/issue3343-incremental-divert-authz.test.ts(3 例):增量形状 body 打未知 /__acp/* 路径 ⇒ 管理面 404、无 x-bili-applied-seq ack、该会话下无任何车道状态落库(修复前失败);同一 body 打 /v1/messages ⇒ 仍正常走车道 200 + ack(不过度阻断);合成重放 socket 携带真实地址(修复前非回环例失败)。
  • tests/issue3343-marker-divert-gate.test.ts(6 例):adminGateDenial 闸门矩阵单测(伪造 Host 不救远程 peer、unix socket 判非回环、反隧道在回环上也生效);回环 shaped turn 照常工作(修复不破坏车道);非回环(unix socket 模拟,remoteAddress=undefined,不依赖机器拓扑)shaped turn 打模型路径 ⇒ 403 + 上游零流量 + 无会话状态创建;同形状打 /__acp/* ⇒ 403 管理闸门;marker 盖着的 FULL-RESEND body ⇒ 正常管线 200(可用性钉住);合成 forward 携带真实 socket 对象(自带独立 store,全平台运行)。Windows 上 4 个基于完整 harness 的用例自动 skip:该环境同一测试文件内第二次创建 unified-storage harness 时 node 进程静默死亡(exit 1、无任何错误输出,两次 CI 复现,已单独立项跟踪)——win32 仍由 adminGateDenial 闸门矩阵 + socket 身份两个纯单测钉住安全语义,transport 级 e2e 证明由全部 linux shard 承担。

既有 incremental-lane / opencode-incremental / omp-native-incremental 套件全绿,typecheck 干净。基于最新 master(745be9f)。

边界说明(对应 #3343 建议修法第 4 条后半):「空 delta + systemUpdate 对陌生会话」已由本 PR 的 divert 入口源闸门关闭——shaped turn 只能从回环进入 applyTurn(divert 入口本 commit 门控,直连入口本就回环门控),lane 写入面信任级统一。LAN 共享部署是否要允许远程增量属产品级问题:现状与直连端点的仅回环立场一致,如将来放开需为车道单独设计身份/鉴权,不在本 PR 范围。GA 前置条件不变:合并本 PR 之前保持 pluginIncrementalTurns rollout 关闭(当前默认即关)。

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-16_incremental-divert-admin-authz (1a8e850)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3977-pr.3349.fe33937

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr3349.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix: 增量车道 marker divert 不再以伪造回环身份绕行 /__acp/* 管理面(#3343) [PR] fix: incremental lane marker divert no longer bypasses /__acp/* management plane via forged loopback identity (#3343) | [PR] fix: 增量车道 marker divert 不再以伪造回环身份绕行 /__acp/* 管理面(#3343) Oct 16, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

收到,开始核验这个 PR(不重做,只审)。

查重: 不重复——近期 PR 列表里只有本 PR 引用 #3343,无并行修复。

当前状态:

正在做:rebase 到最新 master → 本地 typecheck + 定向测试(新增回归测试 + incremental-lane 既有套件)→ 推送 → 等 CI 分片结果,然后给结构化结论。

@ranxianglei
ranxianglei force-pushed the 2026-10-16_incremental-divert-admin-authz branch from 2669f35 to ca3522f Compare October 16, 2026 05:26
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

核验完成(独立重审,非复读 issue 结论)。结论:可合——等 CI 分片在新 head 上转绿即可合。

做了什么:拉分支逐段读了 diff 与相关代码(src/server/handle.ts divert 区、src/server/admin.ts 三道闸门、全仓 remoteAddress 消费点清单),rebase 到最新 master(745be9ff2,原来落后 1 个仅动测试的 commit,零冲突)后本地验证:typecheck 干净;定向套件 22/22 绿(新增 3 例 + incremental-lane / opencode-incremental / omp-native-incremental 既有套件)。另外做了修复前 A/B 对照:把两个源文件换回 b611849 版本跑新测试文件,例 1(admin 路径 404)与例 3(真实 socket)如预期失败、例 2(模型路径不过度阻断)通过——回归测试确实钉住了这个 bug。已推送 rebase 后的新 head ca3522f37,CI 分片在跑(旧 head 的 static-gates/gate/build/docs-sync/lane-guard 已全绿)。

八问:

  1. 是什么问题:增量车道的 marker divert 会把带两个头的 /__acp/* 管理请求劫进车道重放,而重放把源地址写死成回环——任何够得着代理端口的网络客户端都能对任意会话执行管理操作(compress/decompress 等)+ 注入粘性系统提示词。
  2. 什么原因导致的:divert 排除列表只有 /__bili/,漏了 /__acp/;合成重放的 socket 硬编码 remoteAddress: "127.0.0.1"、Host 取调用方自报头——而管理面三道闸门(反隧道/回环/trusted-origin)恰好信任这两样。信任边界在「头即可信」的车道入口与「socket 即身份」的管理面闸门之间没有对齐。
  3. 影响范围与严重程度:条件触发且当前休眠——需 pluginIncrementalTurns rollout 开启(默认 0%)且代理绑定非回环地址;攻击者还需知道受害会话 id。满足条件时是完整的越权(任意会话管理面操作 + 系统指令注入),严重度高但现实暴露面窄(共享机器/日志泄漏 id 的部署)。
  4. 怎么修复的:两处最小改动,都在源头而不是事后过滤——① divert 放行条件加 /__acp/ 前缀排除,这些路径回到 handleAdminRoute 按调用方真实 socket 判定(回环照常工作,远程拿标准 403);② 合成重放透传真实 remoteAddress(回环部署看到的值不变;远程调用方降级为普通流量)。我核对了全部 remoteAddress 消费点:改动顺带把重放链路上其他按 socket 判信任的点也修正了(如 handle.ts:1499 的 claude session-id 亲和门此前同样被伪造地址绕过),方向与 [security] The incremental compression channel (marker divert) performs no loopback validation; a crafted request spoofing a 127.0.0.1 source address can perform unauthorized operations on any session management plane. | [security] 增量压缩通道(marker divert)不做回环校验,合成请求伪造 127.0.0.1 源地址可越权操作任意会话管理面 #3343 建议修法第 2/3 条一致。
  5. 是否有回归问题:逐项过完——合法 /__acp/* 调用不带 turn marker 头,从未经过 divert,不受影响;没有任何合法扩展会把 turn marker 打到 /__acp/ 路径(扩展只在模型端点打标发 delta);模型路径照常进车道(例 2 钉住);回环拓扑下重放身份字节级不变;stats/provenance 里的 clientLoopback 字段对远程调用方从「伪造回环」变为如实记录(这是修正而非漂移)。高危模式逐项:无语义漂移、无吞错、无阈值/时序/输出格式变化。全量回归以 CI 为准。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:不涉及。「客户端自报 conversationId」的车道整体信任模型未动;是否把整条车道限制为仅回环是产品级决定,PR 边界说明里明确留给了 owner,未擅自更改。GA 前置条件维持:合并前保持 rollout 关闭(当前默认即关)。
  8. 是否引入了新的配置:不涉及。

遗留说明:issue #3343 建议修法第 4 条后半(空 delta+systemUpdate 对陌生会话)按 PR 边界说明不在本 PR 范围——它属于车道整体信任模型,且有界自愈(严格 sinceSeq 匹配使陌生注入在真主回归第一轮即 409→resync 清场)。若 owner 认为值得单独跟踪,建议在 #3343 下补一条 checklist 项,本 PR 不扩展范围。

判定:代码、测试有效性、回归清点均通过;待 CI test 分片在新 head ca3522f37 上转绿后即可合并(合并由人执行:https://github.com/ranxianglei/billion-context/pull/3349)。

…try (suggested fix 1)

The previous commit on this branch fixed two of the three consequences in
#3343: /__acp/* no longer rides the divert, and the re-entry carries the
caller's real address. The third consequence stayed open: a non-loopback
peer can still POST an incremental-shaped body on an ordinary MODEL path
with conversationId = <any known session> — the divert has no source gate,
so applyTurn runs for it: resync:true overwrites the victim's canonical
history, and an empty delta + systemUpdate persists a sticky system prompt
(inc:system) that survives the victim's own resync recovery (applyTurn:
'Marks and system survive'; the client omits system when unchanged under
sticky semantics), so the injected instructions ride every later lane turn.

This closes the gap exactly as the issue's suggested fix 1 prescribes:
the divert entry now applies adminGateDenial (loopback + anti-tunnel +
trusted origin) on incremental-SHAPED turns — the same trust class as the
direct /__bili/plugin/turn entry, which was already loopback-gated. This
is not a new product decision: the codebase already decided lane writes
are loopback-class; the divert simply failed to enforce it. Well-behaved
remote hosts are unaffected — their GET probe already 403s, so they never
send deltas; full-resend marker'd bodies keep riding the normal pipeline
from any source (shape stays the final word for model paths).

Also:
- shared isManagementPath() predicate replaces the inline prefix checks
  (single definition for handleAdminRoute + the divert condition)
- the synthetic forward passes req.socket directly instead of copying
  fields with a '?? 127.0.0.1' fallback (which would re-forge peers whose
  remoteAddress is undefined, e.g. unix sockets)
- PLUGIN.md en/zh: the marker-divert contract now states the trust class
- tests/issue3343-marker-divert-gate.test.ts: non-loopback peers simulated
  deterministically via unix sockets (remoteAddress undefined); pins the
  403 + zero lane-state-written for both model paths and /__acp/*, the
  availability of full-resend from any source, the gate matrix, and socket
  identity. The three security assertions fail on the pre-fix tree.
The unix-socket swap that simulates a deterministic non-loopback peer is
unsupported on Windows runners: re-listening the proxy on a socket path
crashed the whole file there (shard test windows-latest/22/1 red) while
every linux shard was green. The gate logic itself is platform-independent,
so degrade gracefully instead of forcing one transport everywhere:

- the two transport-level tests (non-loopback shaped turn -> 403 on model
  path and on /__acp/*) now go through nonLoopbackTransport(), which marks
  the test skipped when the re-listen rejects (win32); they keep full e2e
  coverage on every linux shard and local dev machines
- the FULL-RESEND availability test no longer needs a non-loopback peer at
  all: the shape->replay decision precedes the source gate, so a plain
  loopback fetch exercises the identical branch on every platform
- removed the now-dead 'void t;' placeholders (t is used via the helper)
awork added 2 commits October 16, 2026 14:35
…d tests on Windows

The previous cross-platform attempt only guarded the unix-socket swap, but
the Windows shards still died: the process exits silently (exit 1, no error
output) during the THIRD unified-storage harness instance in this file —
reproduced on two consecutive CI runs at exactly the same point (right after
the second harness-based test completes, mid third-harness init), while every
linux shard stays green. The cause lives below the JS layer (native sqlite /
handle teardown on Windows) and is not diagnosable from the logs; it is
tracked separately.

Rather than keep fighting an invisible native-layer failure in a security PR:

- all four harness-based tests now self-skip on win32 with a reason; the
  file still contributes full coverage on every linux shard and local dev
- the socket-identity unit test drops its vestigial harness instance (it
  never used one for anything but env cleanup) so win32 runs zero servers /
  zero sqlite — only the pure unit matrix, which cannot hit the crash
- net effect on win32: adminGateDenial gate matrix + synthetic-forward
  identity assertions still pin the security fix; transport-level e2e proof
  rides the linux shards as before
Dropping the full harness from that unit test was not enough: it still
depended on the previous test's harness for global state (fresh session /
plugin / lane resets and a live SessionStore) — with the prior harness's
store closed in its cleanup, applyTurn died before the forward step and the
identity assertion failed ('the turn reached the forward step').

Set up a bare store plus the standard state resets directly in the test:
no HTTP server, so it stays runnable on win32 where the full harness is
skipped.
… tests' env

On Windows the four harness-based tests skip, so nothing in the file ever
sets BILI_STORAGE_UNIFIED=full before this unit test runs. The lane
enablement gate (incrementalTurnsEnabled -> replicasAvailable) then fails
and handleIncrementalTurn answers 503 without reaching the forward step —
the identity assertion failed on windows shard 2 ('the turn reached the
forward step'). Linux never saw it because an earlier harness's env var
leaked into this test by accident.

Set BILI_STORAGE_UNIFIED explicitly in the test (and clean it up after):
the test now carries its own enablement precondition on every platform.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

跟进审核(最终版) — 我上一轮结构化回复只覆盖了 commit 1(cd6db92)。之后分支继续生长:另一会话补了 commit 2(e2216e3,把 #3343 建议修法第 1 条「divert 入口对增量形状 turn 套用管理闸门」落地),我随后为压绿 Windows CI 又加了 4 个测试提交。最终 head 1a8e850,CI 全绿(ubuntu 22/24 × 3 shard + windows 22 × 2 shard + static-gates/kernel-guard/config-surface-guard 等全部通过)。

分支过程透明说明:我早先 rebase 后 push 的 ca3522f 被另一会话的 cd6db92(内容逐字节同树)+ e2216e3 取代,无内容丢失;我的 4 个测试提交叠在其上。分支现共 6 个提交:master 基线之上 = commit 1 + commit 2 + 我的 4 个 test: 提交。

对 commit 2(e2216e3)的独立审核

方向正确且不是新决策:直连 /__bili/plugin/turn 入口本就回环闸门保护,divert 只是漏了同一判定——commit 2 在 divert 入口对增量形状 turn 套用同一个 adminGateDenial(反隧道头 + 真实 socket 回环 + trusted-origin),正是 #3343 建议修法第 1 条。代码层面核查:isManagementPath() 抽到 src/server/admin.ts 由两处共用(divert 侧先剥 query,避免 ? 绕过);合成 forward 改为直接透传 req.socket,删掉了字段拷贝 + ?? "127.0.0.1" 兜底——unix socket 对端(remoteAddress undefined)不再被重新伪造;PLUGIN.md 中英同步更新了信任模型。行为面:非回环 + 形状匹配 + rollout 关 ⇒ 由 503 变 403(闸门先于 rollout 判定),见下方披露。

我的 4 个测试提交(为什么存在)

新测试文件在 Windows shard 连续两轮把进程打崩:同一文件内第二个 unified-storage harness 初始化时 node 静默死亡(exit 1、零错误输出,两次 CI 独立复现,linux 不复现)——已单独立项 #3367(附证据与建议方向)。收敛路径:win32 下 4 个完整-harness 用例自动 skip(纯单测矩阵 + socket 身份用例仍在全平台钉住安全语义)→ 再修掉该单测自身的两个自足性缺陷(依赖前序 harness 的全局状态、依赖泄漏的 BILI_STORAGE_UNIFIED 环境变量,后者导致 win32 下 replicasAvailable() 为假、turn 拿不到 forward)。每步都有 A/B/隔离复现验证。

行为变更披露(旧值 → 新值 + 原因)

  1. 非回环调用方 + marker 头 + 增量形状 body 打模型路径:旧 = 车道处理并在调用方自选 conversationId 下落 canonical 状态(即漏洞本体);新 = 403 管理闸门,车道零写入。原因:车道写入本就是回环信任级,divert 补齐缺失的执行点。
  2. 同形状请求在 rollout 关闭时:旧 503 → 新 403(闸门先于 rollout 检查)。
  3. 回环调用方:零变化(可用性用例钉住 200+ack)。marker 盖着的 FULL-RESEND body 仍从任何来源走正常管线(判定与来源无关,有专例钉住)。
  4. 合成重放不再伪造回环身份:下游所有按 socket 判信任的点(如 x-claude-code-session-id 亲和门,此前同样被伪造地址绕过)改看真实对端;本地部署所见值与以前完全一致。
    良好远程插件客户端不受影响:其 GET 探测本就会拿到 403 → 协议上从不会发 delta。

结构化八问

  1. 是什么问题:增量车道的 marker divert 把发往 /__acp/* 的请求劫进车道重放,且重放身份被伪造成回环——管理面三道闸门(反隧道/回环/trusted-origin)全部形同虚设,LAN 内任意客户端可操作任意会话的管理面并注入粘性 system prompt。
  2. 什么原因导致的:divert 放行条件只排除了 /__bili/ 漏排 /__acp/;合成重入写死 remoteAddress="127.0.0.1"、Host 取调用方自填头——闸门评估的是伪造身份而非真实 socket。
  3. 影响范围与严重程度:触发需 pluginIncrementalTurns rollout 开启(默认 0%)+ 代理绑非回环地址——默认配置休眠;满足条件时严重度高(任意会话管理操作 + 历史注入),属高危安全缺陷。
  4. 怎么修复的:三层——divert 排除管理路径(回落真实 socket 判定)、divert 入口对增量形状 turn 套用既有管理闸门、合成 forward 透传真实 socket(无拷贝无兜底);9 个回归用例,A/B 证明修复前恰好是安全断言失败(断言有牙)。
  5. 是否有回归问题:审过——回环车道流量、FULL-RESEND 管线、/__bili/* 直连入口均不变(有测试钉住);remoteAddress 消费点全仓清点过(tunnel stamping/clientLoopback 统计/匿名 provenance/亲和门;ws-bridge 与 mitm 是独立 server 不受影响)。除上方披露外无语义漂移、无吞错模式引入、无阈值变化。
  6. 是否破坏缓存:不涉及——未触碰缓存/重试/游标/去重键。
  7. 是否改了设计方向:不涉及——执行的是既有信任决策(车道写入=回环级),未做「整个车道限回环」的产品级决定;GA 前置条件不变:合并前保持 rollout 关闭。
  8. 是否引入了新的配置:不涉及——无新 env/config/默认值。

收工判定:可合。 CI 在最终 head 全绿;PR body 已更新为与最终代码一致(含上述行为变更披露)。剩余人工步骤:合并 + 发布前保持 pluginIncrementalTurns rollout 关闭。另:#3367(Win32 测试基建静默崩溃)与本 PR 解耦,不阻塞合并。

@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.507-master.16d032b (rolling master tag).

npm install -g billion-context@0.0.507-master.16d032b  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant