Skip to content

[PR] fix: escape remote advisory feed fields in web panel banner (#6153) - #6156

Open
ranxianglei wants to merge 2 commits into
masterfrom
2026-11-11_advisory-banner-escape
Open

ranxianglei wants to merge 2 commits into
masterfrom
2026-11-11_advisory-banner-escape

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

Closes #6153

What

The defect-advisory banner in the admin panel interpolated id and reason — strings parsed verbatim from the remote billion-context-advisories npm feed (parseAdvisoryDoc checks non-emptiness only, no charset) — directly into innerHTML. Every other dynamic string in client.ts goes through escapeHtml first; this banner was the one remote-string sink left raw. A compromised advisories package (or stolen NPM_TOKEN for it) gets script execution inside the panel — same-origin with the config editor and update-install actions.

Change

  • src/web/client.ts:1587/:1589 — route all three feed-derived fields (id, reason, target) through the existing escapeHtml at the render sink. target was already charset-safe via semver.valid; escaped anyway so all remote fields are uniformly inert.
  • tests/issue6153-advisory-banner-escape.test.ts — regression test slicing the banner block out of WEB_CLIENT under stubbed globals (same seam discipline as tests/issue2645-pck-banner-escape.test.ts). Marker-escape probe proves each field passes through escapeHtml in BOTH banner states (pendingRestart / active); real-algorithm probe asserts no raw <img/<script survives; static pins forbid the historic raw interpolations; negative case keeps the hidden path intact.

Verification

  • New test: 6/6 pass on the fix; 3 fail on the unfixed code (reproduces the bug).
  • Adjacent suites green locally: advisory-panel / advisory / advisory-endpoint-parity / issue2645-pck-banner-escape / web-update-banner (31/31).
  • npm run typecheck clean. Full-suite verdict = remote CI on this head.

Behavior change disclosure

Rendered banner HTML changes ONLY when a field contains HTML metacharacters — i.e. exactly the previously injectable content, which now renders escaped text instead of executing. For clean feed values (the documented bc-<year>-<seq> ids and prose reasons) output is byte-identical; escaping is a no-op.

Alternatives considered and rejected

  1. Route the banner through the Unified Announcement Panel Design (Approved): Built-in declarations + local JSON + remote GitHub raw — a single renderer | 公告面统一设计(已批准):内置声明 + 本地 JSON + 远程 GitHub raw,三来源一套渲染器 #5548 unified notice renderer — rejected: the defect advisory is a distinct mechanism (npm companion package, force-install control root) from announcements (remote.json feed), with its own two-state shape and install command; it is not part of the notice registry. Folding it in would merge two surfaces that should stay separate.
  2. Charset-validate id at parse time (/^bc-\d{4}-\d{3}$/) + reason length cap — rejected: sink escaping makes every field inert regardless of content, so parse-time tightening adds zero protection while making the high-value install-control channel brittle (a non-conforming id would be skipped, and an all-nonconforming document errors out, silently disabling advisory force-installs). Robustness of that channel wins over redundant hardening.

Security-related change — human review gate per §7.4.

The defect-advisory banner interpolated id/reason parsed verbatim from
the remote billion-context-advisories npm feed into innerHTML, while
every other dynamic string in the panel goes through escapeHtml first.
Route all three remote fields (id, reason, target) through escapeHtml at
the render sink; target was charset-safe via semver.valid but escaped for
uniformity. Regression test slices the banner block out of WEB_CLIENT
under stubbed globals (same seam discipline as #2645's pck banner test)
and fails on the unfixed code.
@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-11-11_advisory-banner-escape (09dd5c2)

Latest build — install this exact version

npm install -g billion-context@0.0.9014-pr.6156.17a3237

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

Recent builds (commit → version)

commit version build
09dd5c2 billion-context@0.0.9014-pr.6156.17a3237 build
9d82a45 billion-context@0.0.9005-pr.6156.5f39c3c build

Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix: escape remote advisory feed fields in web panel banner (#6155) [PR] fix: escape remote advisory feed fields in web panel banner (#6155) Nov 10, 2026
…#6153)

The test file and its header cited #6155 — a number that on GitHub
belongs to an unrelated thread (snapshot-table compression foundation).
Cross-references in PR artifacts must use GitHub numbers; the source bug
report for this fix is GitHub issue #6153. Pure rename + header fix;
no behavior change.
@ranxianglei ranxianglei changed the title [PR] fix: escape remote advisory feed fields in web panel banner (#6155) [PR] fix: escape remote advisory feed fields in web panel banner (#6153) Nov 10, 2026
@ranxianglei ranxianglei added bug Something isn't working p2 scope/ui labels Nov 10, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b)

Note: a previous session run stalled after all work had landed; this reply reports the end-state, and every status claim below was re-verified live just now.

Dedup check: not a duplicate. PR #6156 (GitHub) is the only open fix for this topic; the source bug report is GitHub #6153 ("[security][web] advisory banner renders remote id/reason into innerHTML unescaped"); no other open/closed issue or PR addresses this mechanism.

Labels: bug / scope/ui / p2 — defect class; web-panel display surface; usable today but a latent supply-chain XSS exposure (needs a compromised advisories package or stolen publish token) → p2, not availability/cache-leak territory.

Status (live-verified)

Defect found in the deliverable — fixed before delivery

The PR's cross-references pointed at the wrong GitHub number: title and body cited #6155, which on GitHub is an unrelated thread (snapshot-table compression foundation). Merged as-is, GitHub would have auto-closed that unrelated open issue; the real source bug report is #6153. Fixed:

  • PR title → (#6153), body line 1 → Closes #6153, filename reference updated — verified via API after patching.
  • Test file renamed tests/issue6155-advisory-banner-escape.test.ts → tests/issue6153-advisory-banner-escape.test.ts (+ header comment) as labeled commit 09dd5c2c9b, pushed to the PR branch. Re-ran the suite after the rename: 6/6 pass.

Independent review (code & behavior)

  • ① Direction (correct): sink-side escaping at the render point is the right layer. Parse-time charset validation correctly rejected (adds zero protection once the sink escapes, while making the force-install channel brittle — a non-conforming id would silently disable advisory force-installs). Keeping the advisory surface OUT of the Unified Announcement Panel Design (Approved): Built-in declarations + local JSON + remote GitHub raw — a single renderer | 公告面统一设计(已批准):内置声明 + 本地 JSON + 远程 GitHub raw,三来源一套渲染器 #5548 unified notice registry also holds: distinct mechanism (npm companion package + force-install control root vs the remote.json announcements feed).
  • ② Regression surface (reviewed item by item): the diff touches ONLY the two banner innerHTML lines (both states) + one new test file. i18n strings, the hidden path, the targetFailed → latest fallback, and the install-command text are untouched. For clean feed values escapeHtml is a no-op → byte-identical output (pinned by the clean-value test, including the exact npm install -g billion-context@0.1.157 string). I swept the rest of client.ts: no other advisory-feed field reaches a DOM sink — bili_pluginAdvisoryBanner, bili_hostPluginBanner, the PCK banner and the Unified Announcement Panel Design (Approved): Built-in declarations + local JSON + remote GitHub raw — a single renderer | 公告面统一设计(已批准):内置声明 + 本地 JSON + 远程 GitHub raw,三来源一套渲染器 #5548 notice renderer all already escape their data. One non-blocking observation: the resolver-wedge banner (src/web/client.ts:1605) interpolates w.hosts raw — that data is locally derived (this process's own DNS-failure hostnames, src/resolver-wedge.ts), not a remote feed; different threat model, out of scope here.
  • ③ Code: the fix covers ALL paths of the bug — id/reason/target × both banner states (pendingRestart / active).
  • ④ Test validity (real teeth, verified both directions locally): 6/6 pass on the fixed head; against the UNFIXED master client.ts exactly 3 fail (both marker probes + the static pin). The marker probes record every value reaching escapeHtml, proving pass-through independent of payload content; the static pin forbids the historic raw-interpolation strings even if seam markers move; the negative case keeps the hidden path intact.
  • ⑤ Diff cleanliness: original diff = 2 files, +123/−2, every line on-topic, no lockfile/generated churn; base == current master (no stale-base risk). My follow-up commit is a pure rename + one header-comment line.
  • ⑤b Code cleanliness: naming/style consistent with file conventions, no dead code, no new dependencies, DRY loop over the two banner states.

Behavior change disclosure (restated from the PR)

Rendered banner HTML changes ONLY when a field contains HTML metacharacters — i.e. exactly the previously injectable content, which now renders as escaped text instead of executing. Documented clean values (bc-<year>-<seq> ids, prose reasons) produce byte-identical output.


结构化八问

  1. 是什么问题:管理面板的缺陷公告横幅把远端 billion-context-advisories npm feed 的三个字段(id/reason/target)未转义直接拼进 innerHTML —— 存储型 XSS:feed 包或其发布 token 被攻破时,可在面板内执行脚本(与配置编辑器、更新安装动作同源)。
  2. 什么原因导致的:parseAdvisoryDoc 只校验非空、不做字符集校验;client.ts 其余动态字符串进 innerHTML 前都过 escapeHtml,唯独这个横幅的远端字符串 sink 漏了转义——根因在渲染 sink 缺防护,不在数据源。
  3. 影响范围与严重程度:影响开着管理面板且有活跃远端公告的用户;触发前提 = advisories 包供应链被攻破或 NPM_TOKEN 被盗;定级 p2——正常使用无感,属潜在安全暴露(需前提条件才可利用),一旦被利用可在配置编辑器/更新动作同源执行任意 JS。
  4. 怎么修复的:渲染 sink 处把三个字段统一过既有 escapeHtml(两种横幅状态全覆盖),使任何内容都惰性化;拒绝解析期字符集校验(零额外保护、却让高价值 force-install 通道变脆)与并入 Unified Announcement Panel Design (Approved): Built-in declarations + local JSON + remote GitHub raw — a single renderer | 公告面统一设计(已批准):内置声明 + 本地 JSON + 远程 GitHub raw,三来源一套渲染器 #5548 通知体系(机制不同应保持分离)两个替代方案均成立。另修复审核发现的引用错误:PR 标题/正文/测试文件名误用编号 [PR] Snapshot-table compression foundation (#5874): server owns the fold ledger, outbound prefix renders from the table #6155(在 GitHub 上属于无关的快照表线程),原样合并会自动关闭无关 issue——已更正为 GitHub [security][web] advisory banner renders remote id/reason into innerHTML unescaped — stored XSS from the billion-context-advisories feed into the admin panel #6153(commit 09dd5c2c9b + PR 标题/正文已更新并复核)。
  5. 是否有回归问题:逐项审过既有行为——改动仅两处横幅 innerHTML 行;i18n 文案、hidden 路径、targetFailed→latest 回退、安装命令文本均未动;干净值下输出逐字节相同(clean-value 测试钉死,含 npm install 命令精确匹配)。无语义漂移、无 fail-fast 变吞错、无阈值/时序/输出格式漂移。
  6. 是否破坏缓存:不涉及——未触碰缓存/重试/增量游标/去重键逻辑。
  7. 是否改了设计方向:无——刻意不把 advisory 横幅并入 Unified Announcement Panel Design (Approved): Built-in declarations + local JSON + remote GitHub raw — a single renderer | 公告面统一设计(已批准):内置声明 + 本地 JSON + 远程 GitHub raw,三来源一套渲染器 #5548 统一通知渲染器(advisory = npm 伴生包 + force-install 控制根,announcements = remote.json feed,机制不同应保持分离)。
  8. 是否引入了新的配置:无。

判定:代码侧闭环——CI 全绿 @ 09dd5c2c9b(30 项检查 0 失败)、回归测试有牙(未修复代码 3 红 / 修复后 6 绿,本地实测)、交叉引用缺陷已修。安全相关变更按 §7.4 属人工评审档,等 owner 人工评审后合并(当前 blocked 即评审门禁,非 CI 红)。

This branch has not been deployed

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

Labels

bug Something isn't working p2 scope/ui

Projects

None yet

1 participant