Repository navigation
feat: dsh web admin relay (security.adminRelay) — remote browsers open the bili panel (#3373) - #3486
Conversation
…n the bili panel through the host entry (#3373) Headless hosts run 'dsh web' behind a reverse proxy; the settings panel iframe pointed at http://127.0.0.1:18787 and failed for every remote browser. The host now relays the /__bili/ admin surface through its own entry origin, gated by a fail-closed security.adminRelay (file-only): - dsh plugin registers a /__bili prefix route forwarding to the loopback proxy; the relayed hop is a local non-browser client (loopback source + Host, no Origin/Cookie/Referer forwarded) so the #1538 admin gate and its DNS-rebinding protection are untouched. Off by default: route answers 404, unbound proxy 503, unreachable proxy 502. - /bili/origin (and the index-inject snapshot) reports {relay:true} when enabled, so the panel UI builds same-origin URLs; the panel API root derives itself from the page path, fixing prefix gateways (/app/dsh/…) as a side effect; the origin probe caches the winning form (base-relative fallback first described in #3373-C1). - Docs: security section in CONFIGURATION.md + zh; config-reference seed.
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.4129-pr.3486.b64348cThis exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr3486.tgz
npm install -g packageInstall instructions are refreshed on each push. |
(ai: vllm-qwen/qwen3.8-27b) 查重:不重复。 这是 #3373(+已并入的 #3424)的唯一实现 PR,无并行同类工作。相邻项均不同向:#3343/#3350 是管理面收紧族(伪造回环身份拦截),本 PR 是显式 opt-in 放宽(宿主自身中继,闸门零改动);#1538 是被复用的既有闸门行为,不是重复项。 开始独立审查。已拉取分支 |
…ordering, effect disposer - contain the relay to the declared /__bili surface: reject decoded ".." segments (literal and %2e-encoded; fetch() normalizes both) with 400 before any upstream hop; an unchecked "/__bili/.." would otherwise land on sibling paths of the loopback proxy (#3486 review F1) - present 404 admin-relay-disabled before the 503 not-running state when the gate is off (fail-closed beats state disclosure; #3486 review F3) - restore the combined route disposer as the inject-effect cleanup so dsh disposes both panel routes on each re-run, matching master's effect contract; re-tighten the dsh-settings-ui assertion that had softened to dead code (#3486 review F2) - type the method/url extraction through locals so the typeof guard actually narrows (new strict usages exposed string|undefined) - regression tests: traversal rejected with zero upstream hops, gate-off+unbound 404 ordering, 413 oversized body with no upstream hop
(ai: vllm-qwen/qwen3.8-27b) 独立审核完成(查重结论见上一条)。审核中发现 3 个问题,已按「小问题直接修」在本分支修掉并推送:commit ① 是什么问题:headless dsh web 部署下,面板 iframe 指向 ② 什么原因导致的:功能类 issue,非缺陷修复。 ③ 影响范围与严重程度:仅影响显式开启 ④ 怎么修复的:13 个文件全量逐行审完。关键核验:
⑤ 是否有回归问题:审过的既有行为及结论——off 态 ⑥ 是否破坏缓存:不涉及——不触碰压缩缓存/重试/游标/去重键。 ⑦ 是否改了设计方向:不涉及——完全按 owner 在 #3373 拍板的 relay 架构执行,无新增架构决策。 ⑧ 是否引入新配置:是——顶层 测试有效性:新增测试有牙——fail-closed 404(带已绑定代理)、503 未绑定、GET+POST 字节精确转发、浏览器头剥离实证(上游 stub 看不到 Origin/Cookie/Referer)、流式透传、502;我补的 3 条:traversal 400 且零上游 hop、gate-off+unbound 的 404 优先级、413 超大 body 零上游 hop。本地定向验证:dsh-admin-relay + dsh-settings-ui + web-storage-banner + issue2861 + config-surface-guard 共 49/49 通过,tests/web-* 全集 100/100 通过,typecheck/build 干净。全量判定以推送 head 上的 CI 为准。 结论:可合入——等 CI 绿即可。分支落后 master 若干提交但 GitHub 判 mergeable,可直接合(需要的话 rebase 一下也行)。合并留给你:#3486 |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.522-master.fabb7f6 # this exact build
npm install -g billion-context@master # always the newest merged build
|
Closes #3373.
What this fixes
Headless host runs
dsh web; a browser on another machine reaches it through a reverse proxy, opens Settings → bili, and the panel iframe points athttp://127.0.0.1:18787— connection failed (#3373). With this PR the host itself relays the/__bili/admin surface through its own entry origin, so the whole panel round-trips same-origin with the entry the browser already reached. No0.0.0.0bind, no socat, no extra port.How
security.adminRelay(new, defaultfalse, fail-closed, file-only). When off, the relay route answers404 {"error":"admin relay disabled"}— the exposed surface is unchanged from today./__biliprefix route forwarding to the loopback proxy (currentOrigin()). Unbound proxy →503; unreachable proxy →502. Bodies forward byte-exact (8 MiB cap →413), response status/headers/body stream back.Host, and the browser'sOrigin/Cookie/Refererare dropped before forwarding — exactly the shapeisLoopbackAddress+isTrustedAdminOriginalready admit. NotrustedProxyOriginssurface was added./bili/origin(and the index-inject snapshot) report{"relay":true}when enabled; the panel UI then builds same-origin URLs. The panel's own API root now derives itself from the page path (API_ROOT), which also fixes prefix gateways (/app/dsh/…, the Settings panel completely blank over remote access: probe uses absolute paths, iframe points at loopback, absolute /__bili/ requests in the UI | 远程访问时设置面板完全空白:探测为绝对路径、iframe 指向回环地址、UI 内 16 处绝对 /__bili/ 请求 #3424 variant) as a side effect — and the origin probe caches the winning form (base-relative fallback) so it stops retrying the wrong URL forever (feat: support a public panel origin for remote / reverse-proxied deployments | feat: 远程/反代场景下面板不可用(headless 宿主 + 远程浏览器时 iframe 指向 127.0.0.1) #3373-C1).Config surface (per AGENTS §3)
security.adminRelay(boolean, defaultfalse). First knob under a new top-levelsecurityblock — the owner-approved home for posture knobs that widen a trust boundary (in-thread: feat: support a public panel origin for remote / reverse-proxied deployments | feat: 远程/反代场景下面板不可用(headless 宿主 + 远程浏览器时 iframe 指向 127.0.0.1) #3373 (comment)).native.*is attach-behavior for native hooks (host-side trust widening doesn't live there); anative.panelOrigindisplay-URL override was rejected because under the relay architecture there is nothing to override — the browser never learns the loopback origin; adsh.*knob would hide a posture decision inside a lane block.providers/compress/env conventions don't model "deliberately widen an admin boundary".security; nothing existing changes meaning. No env twin (deliberate posture decisions stay in the file, 彻底整治环境变了滥用,除非必要都走配置文件 #2030).website/config-reference/server.yaml(regenerated tables), hand-written### securitysections in CONFIGURATION.md + zh,hostsection amended ("loopback-only unless the relay is enabled").Security note (also in the docs)
/__bili/is the full admin surface — config editing and credential writes, not a read-only dashboard. Enabling the relay means whoever can reach the host web entry can reach all of that. The docs call this out: protect the entry (auth / reverse proxy) first.Tests
tests/dsh-admin-relay.test.ts(new): fail-closed 404 with a bound proxy; 503 unbound; full GET+POST forwarding against a real local stub — method/url/body byte-exact, browserOrigin/Cookie/Refererverified absent at the proxy, fetch-derived loopbackHost, header/status/body passthrough, streaming; 502 unreachable.tests/dsh-settings-ui.test.ts: relay-mode probe binds same-origin; prefix-gateway fallback resolves through the base-relative form (https://dsh.example/app/dsh/…); existing tests updated for the second route + hermeticBILI_CONFIG_FILE.API_ROOT(web-storage-banner,issue2861).testlanes on this head.No kernel/ or pi-subagents/ changes. No version bump.