Repository navigation
fix: gate pi project prompt packs on project trust (#2529) - #2537
ranxianglei wants to merge 1 commit into
Conversation
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.2758-pr.2537.444f645This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2537.tgz
npm install -g packageInstall instructions are refreshed on each push. |
|
继续 看上面消息 |
An untrusted pi project could plant .billion-context/packs/<name>.json to shadow a same-named user/builtin pack and inject its surface text into ACP system prompts (pack precedence project > user > builtin). The pi extension now stamps x-bili-project-trusted per request from ctx.isProjectTrusted() (fail closed on anything but an explicit true); the proxy then drops the PROJECT pack source for untrusted pi contexts while keeping user/builtin packs active. Other lanes and wire/launcher-mode pi are unchanged (no trust channel exists there). Resolution is per-request, so a mid-session trust flip re-derives on the next request.
8708f80 to
fc85797
Compare
Review 结论:修法正确、已验证、CI 全绿(26/26 @ 已做动作:
八问逐项:
其他注记:
判定:代码本身 solid 且验证充分;唯一待决项是上面 |
Closes #2529
What this changes
An untrusted pi project could plant
.billion-context/packs/<name>.jsonto shadow a same-named user/builtin prompt pack and inject its own surface text (tool descriptions / prompt sections / nudge text) into ACP system prompts — pack precedence isproject > user > builtin, so a project pack wins over a trusted one. The proxy resolved packs per request with no trust input.This gates the project pack source on pi's project-trust decision, failing closed.
Mechanism
src/agent/pi.ts—Ctxgains an optionalisProjectTrusted?: () => boolean | Promise<boolean>; newprojectTrustedOf(ctx)returnstrueonly for an explicittrue(missing method / throw / non-boolean ⇒ untrusted). Thebefore_provider_headershandler stampsx-bili-project-trusted: "1"|"0"on every pi plugin-mode model request.src/compress-settings.ts—resolveCompressSurface(Detailed)(s, dirs?, includeProject?): whenincludeProject === falsethe resolver chain drops the project dir and keeps the user + builtin sources; the default (undefined) preserves today's chain byte-for-byte. New pure predicatepiProjectPacksAllowed(agent, trustedHeader): non-pi lanes always allow; pi allows only on the literal"1".src/server/handle.ts— the per-request pack resolution now passespiProjectPacksAllowed(pluginAgentHeader(req.headers), headerValue(req, "x-bili-project-trusted")). Resolution is per-request (no process-lifetime cache), so a mid-session trust flip re-derives on the very next request — no stale state.Behavior changes (old → new)
ctx.isProjectTrusted() !== true(including the signal being unavailable). User + builtin packs stay active.x-bili-pluginagent header / no trust channel there). Fail-closed applies only where the signal exists.Scope note (see #2529)
The migrated issue also names a
.pi/acp.jsonACP-config loader facet. That loader does not exist in billion-context — it lives in the standalonebillion-context-pi, tracked by its open PR ranxianglei/billion-context-pi#625. This PR covers the facet that actually lives here: project prompt-pack injection. No.pi/acp.jsoncode path is touched.Residual
Wire/launcher-mode pi (no extension
ctx) has no project-trust channel, so it keeps today's behavior. Hardening that mode needs a trust signal that mode does not expose — out of scope here, flagged for follow-up if desired.Tests
New
tests/pi-project-trust.test.ts(9 cases): the allow/block decision matrix, fail-closed detection (missing method / throw / non-boolean), the same-name shadowing attack itself, omitted-argument back-compat, project-only pack loss → default, builtin packs still available to untrusted contexts, and per-request trust-flip re-resolution. Existing pack/surface suites are unchanged and green.Rebased on current master; typecheck + targeted suites green locally, full regression runs on CI.