Skip to content

fix: gate the incremental-lane marker divert to loopback and stop forging the caller socket - #3350

Closed
ranxianglei wants to merge 1 commit into
masterfrom
2026-10-16_fix-3343-marker-divert-gate
Closed

ranxianglei wants to merge 1 commit into
masterfrom
2026-10-16_fix-3343-marker-divert-gate

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #3343

What

The #3248 marker divert trusted the plugin marker headers alone: any client that could reach the listening port could POST an incremental-shaped body with x-bili-plugin + x-bili-plugin-turn and land in applyTurn — which writes canonical session state under a caller-chosen conversationId. The lane's synthetic re-entry made it worse: it carried a hardcoded remoteAddress: "127.0.0.1" plus the caller's own Host header — exactly the two facts the /__acp//__bili/ admin gate trusts (isLoopbackAddress(socket.remoteAddress) + isTrustedAdminOrigin with no Origin). A LAN peer on a --host 0.0.0.0 deployment could therefore:

  • overwrite any known session's canonical history (resync semantics);
  • persist a sticky system prompt into a foreign session (empty delta + systemUpdate is a legal turn shape — inc:system survives into every later assembled turn);
  • ride the diverted request onto the management prefixes with a forged loopback identity.

Exposure pre-fix: rollout pluginIncrementalTurns enabled (default 0%, forceable via env/config) AND proxy listening on a non-loopback address.

Changes

  1. Divert entry applies adminGateDenial (loopback + anti-tunnel + trusted-origin — the same checks as the direct /__bili/plugin/turn entry) on incremental-SHAPED turns. Denial → 403 before the lane runs.
  2. Management prefixes never ride the divert: new shared isManagementPath() predicate (single definition, used by both handleAdminRoute and the divert condition) excludes /__bili/* and /__acp/* from marker handling entirely.
  3. The synthetic forward carries the REAL req.socket instead of a forged loopback one — every downstream gate (admin plane, tunnel admission, provenance) judges the actual peer.
  4. Regression tests (tests/issue3343-marker-divert-gate.test.ts): non-loopback peers simulated deterministically via unix sockets (remoteAddress === undefined ⇒ non-loopback by isLoopbackAddress, no network-topology luck). Verified against the pre-fix code: the three security assertions fail there and pass here.

Behavior changes (old → new)

Surface Old New Why
Shaped turn, non-loopback/tunnel/untrusted-origin source diverted into the lane with a forged 127.0.0.1 identity 403 the hole itself; legitimate remote hosts never send deltas — their GET probe already 403s, so they stay full-resend
Synthetic re-entry socket { localPort, remoteAddress: "127.0.0.1", destroy } the caller's real socket loopback topology is byte-identical (real == 127.0.0.1); a remote peer degrades to ordinary model traffic and can no longer reach the management plane. Side effect: session provenance for such turns records the real peer address instead of the forged one
Marker'd request on /__acp/* / /__bili/* paths entered the divert/replay path skips the divert, goes straight to the normal pipeline (admin gate judges the real socket) defense-in-depth; loopback behavior unchanged (same endpoints, same gate outcome)
Shaped turn, loopback source; full-resend marker'd turn, ANY source works works, unchanged availability preserved — the shape is still the final word for model paths

No config surface change. Rollout stays at its default 0% — this fix is what makes enabling pluginIncrementalTurns safe (GA precondition from the issue).

Local: typecheck clean; targeted suites green (issue3343-marker-divert-gate, incremental-lane, admin-probe). Full-suite verdict: CI.

…ging the caller socket (#3343)

The #3248 marker divert accepted any client that could reach the listening
port (trust = the plugin marker headers alone), and the lane's synthetic
re-entry carried a hardcoded remoteAddress of 127.0.0.1 plus the caller's
Host header — exactly the two facts the /__acp//__bili/ admin gate trusts.
A LAN peer could therefore drive applyTurn for ANY conversationId: overwrite
canonical history via resync, persist a sticky system prompt into a foreign
session (empty delta + systemUpdate is a legal turn), and ride the diverted
request onto the management prefixes with a forged loopback identity.

- divert entry now applies adminGateDenial (loopback + anti-tunnel +
  trusted origin) on incremental-SHAPED turns, same trust class as the
  direct /__bili/plugin/turn entry; full-resend marker'd bodies keep
  riding the normal pipeline from any source (shape is the final word)
- management prefixes (/__bili/, /__acp/) never ride the divert at all
  (shared isManagementPath predicate, single definition)
- the synthetic forward carries the REAL req.socket instead of a forged
  loopback one — every downstream gate judges the actual peer; loopback
  topology is byte-identical
- regression tests: unix-socket peers simulate non-loopback callers
  deterministically (remoteAddress undefined); pre-fix code fails the
  three security assertions, post-fix passes
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-16_fix-3343-marker-divert-gate (f7eb395)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3951-pr.3350.4799cc4

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-pr3350.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

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

重复判定:与 #3349 重复,按先来后到关闭本 PR。

两个 agent 并行处理了 #3343,#3349 先开。本 PR 的全部内容已作为增量提交并入 #3349 的分支(顺带 rebase 到最新 master):divert 入口回环闸门(建议修法第 1 条)、共享 isManagementPath 谓词、真实 socket 直传、PLUGIN.md 契约更新(en/zh)、基于 unix socket 的非回环回归测试——#3349 原有的测试文件保留共存。关闭本 PR 不丢失任何独有内容。

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