Repository navigation
[PR] fix: incremental lane marker divert no longer bypasses /__acp/* management plane via forged loopback identity (#3343) | [PR] fix: 增量车道 marker divert 不再以伪造回环身份绕行 /__acp/* 管理面(#3343) - #3349
Conversation
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.3977-pr.3349.fe33937This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr3349.tgz
npm install -g packageInstall instructions are refreshed on each push. |
(ai: vllm-qwen/qwen3.8-27b) 收到,开始核验这个 PR(不重做,只审)。 查重: 不重复——近期 PR 列表里只有本 PR 引用 #3343,无并行修复。 当前状态:
正在做:rebase 到最新 master → 本地 typecheck + 定向测试(新增回归测试 + incremental-lane 既有套件)→ 推送 → 等 CI 分片结果,然后给结构化结论。 |
…s with a forged loopback (#3343)
2669f35 to
ca3522f
Compare
(ai: vllm-qwen/qwen3.8-27b) 核验完成(独立重审,非复读 issue 结论)。结论:可合——等 CI 分片在新 head 上转绿即可合。 做了什么:拉分支逐段读了 diff 与相关代码( 八问:
遗留说明:issue #3343 建议修法第 4 条后半(空 delta+systemUpdate 对陌生会话)按 PR 边界说明不在本 PR 范围——它属于车道整体信任模型,且有界自愈(严格 sinceSeq 匹配使陌生注入在真主回归第一轮即 409→resync 清场)。若 owner 认为值得单独跟踪,建议在 #3343 下补一条 checklist 项,本 PR 不扩展范围。 判定:代码、测试有效性、回归清点均通过;待 CI test 分片在新 head |
…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.
ca3522f to
e2216e3
Compare
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)
…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.
(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 个 对 commit 2(e2216e3)的独立审核方向正确且不是新决策:直连 我的 4 个测试提交(为什么存在)新测试文件在 Windows shard 连续两轮把进程打崩:同一文件内第二个 unified-storage harness 初始化时 node 静默死亡(exit 1、零错误输出,两次 CI 独立复现,linux 不复现)——已单独立项 #3367(附证据与建议方向)。收敛路径:win32 下 4 个完整-harness 用例自动 skip(纯单测矩阵 + socket 身份用例仍在全平台钉住安全语义)→ 再修掉该单测自身的两个自足性缺陷(依赖前序 harness 的全局状态、依赖泄漏的 行为变更披露(旧值 → 新值 + 原因)
结构化八问
收工判定:可合。 CI 在最终 head 全绿;PR body 已更新为与最终代码一致(含上述行为变更披露)。剩余人工步骤:合并 + 发布前保持 |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.507-master.16d032b # this exact build
npm install -g billion-context@master # always the newest merged build
|
Fixes #3343
问题:增量压缩车道(#3248)的 marker divert 会把发往
/__acp/*管理路径的请求劫进车道重放,而重放请求的源地址被写死成 127.0.0.1、Host 取调用方自己填的头——管理面的三道闸门(反隧道/回环/trusted-origin)全部被绕过。在 rolloutpluginIncrementalTurns开启且代理绑定非回环地址时,局域网内任意客户端可凭两个头对任意 conversationId 执行/__acp/*管理操作。默认配置(rollout=0%、仅回环监听)不受影响,故此前是休眠状态。修法 — commit 1
cd6db9251(两处最小改动):src/server/handle.ts:marker divert 放行条件增加/__acp/前缀排除——与既有的/__bili/排除对齐。这些路径回到handleAdminRoute,由闸门按调用方真实 socket 判定(回环照常,远程得到标准 403)。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入口同一套闸门):isManagementPath()(src/server/admin.ts),handleAdminRoute 与 divert 共用一处定义;req.socket(替代逐字段拷贝 +?? "127.0.0.1"兜底——兜底会把 remoteAddress 为 undefined 的 peer(如 unix socket)重新伪造回环);这不是新的产品决定:直连 turn 端点本就回环门控(lane 写入面早已是回环级),divert 只是漏了执行同一标准;正常远程宿主不受影响——其 GET 探针本来就 403,因此不会发 delta。
行为变更披露(旧值 → 新值 + 原因):
回归测试(两文件共 9 例;A/B 已验证:安全断言在修复前树全部失败、可用性例通过):
tests/issue3343-incremental-divert-authz.test.ts(3 例):增量形状 body 打未知/__acp/*路径 ⇒ 管理面 404、无x-bili-applied-seqack、该会话下无任何车道状态落库(修复前失败);同一 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 之前保持
pluginIncrementalTurnsrollout 关闭(当前默认即关)。