dsh-injection-manager 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/README.md +5 -1
- package/README.zh.md +3 -1
- package/docs/ARCHITECTURE.md +12 -1
- package/docs/COMPATIBILITY.md +3 -0
- package/docs/FAQ.md +4 -0
- package/index.js +7 -2
- package/lib/routes.js +62 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.0.1 — 2026-11-17
|
|
4
|
+
|
|
5
|
+
### Security
|
|
6
|
+
|
|
7
|
+
- **Every HTTP route now passes the host's own admission fence first.** All 15 registered
|
|
8
|
+
route handlers are wrapped at registration time (`makeFencedHandler`): a request asks
|
|
9
|
+
`ctx.connection.requestRejection(req)` before any route logic runs, so a Host/Origin the
|
|
10
|
+
host does not trust — or a request without the host-issued browser/API credential — is
|
|
11
|
+
answered with the host's `403`/`401` and an empty body. The rejection happens before any
|
|
12
|
+
JSON, file or policy data is read, so nothing leaks; the response still carries the usual
|
|
13
|
+
`nosniff` / `no-referrer` / frame-deny / `no-store` headers.
|
|
14
|
+
- **Compatible degradation, not a new hard dependency.** `connection` is not added to the
|
|
15
|
+
plugin's `inject` list: on a host without the service (older DSH, or before it is available
|
|
16
|
+
during boot), without a `requestRejection` method, or when the call throws, the fence is
|
|
17
|
+
skipped and the routes behave exactly as in 2.0.0. A security fence must never turn the
|
|
18
|
+
panel into a blank page.
|
|
19
|
+
- Write actions keep their own same-origin check on top: `POST /action` requires a JSON
|
|
20
|
+
content type, a non-cross-site `sec-fetch-site`, and a matching `Origin` when one is sent.
|
|
21
|
+
- New tests cover the fence paths: service missing → pass-through, `401`/`403` → handler not
|
|
22
|
+
executed and response ended, `undefined` → pass-through, thrown error → pass-through; the
|
|
23
|
+
registration path is covered route-by-route (15/15 fenced) and the old-host path still answers.
|
|
24
|
+
11 new tests, `node --test` 207/207 green; `npm run smoke` green.
|
|
25
|
+
|
|
3
26
|
## 2.0.0 — 2026-11-16
|
|
4
27
|
|
|
5
28
|
The control-plane release: the panel now shows what the next request carries, what can be
|
package/README.md
CHANGED
|
@@ -316,7 +316,11 @@ for switches.
|
|
|
316
316
|
| Plugin config row | dock / refreshOnFocus / showRawNames / budgetTokens | Plugins → Configuration |
|
|
317
317
|
| Browser local storage | Drawer line numbers, insights range, dismissed cards | This browser only |
|
|
318
318
|
|
|
319
|
-
No network requests, no telemetry, no uploads.
|
|
319
|
+
No network requests, no telemetry, no uploads. Every HTTP route also passes the host's own
|
|
320
|
+
Host/Origin admission fence before any route logic runs: an untrusted origin, or a request without
|
|
321
|
+
the host-issued browser/API credential, gets a `401`/`403` with an empty body. Only on a host that
|
|
322
|
+
does not offer that service is the fence skipped (the routes then behave exactly as in 2.0.0). The
|
|
323
|
+
event feed stores only policy and session
|
|
320
324
|
metadata: strings are flattened and truncated to 200 characters and the session's prompt text is
|
|
321
325
|
never written. The content drawer reads files from disk only when you open it, only for paths the
|
|
322
326
|
snapshot registered, and nothing read there is persisted.
|
package/README.zh.md
CHANGED
|
@@ -281,7 +281,9 @@ Plugins → dsh-injection-manager → Configuration 里有四项,只影响显
|
|
|
281
281
|
| 插件行 `config` | dock / refreshOnFocus / showRawNames / budgetTokens | Plugins → Configuration |
|
|
282
282
|
| 浏览器 localStorage | 抽屉行号、洞察范围、被关掉的提示卡 | 只在这个浏览器 |
|
|
283
283
|
|
|
284
|
-
|
|
284
|
+
不联网、不遥测、不上传。所有 HTTP 路由在入口先过宿主的 Host/Origin 准入门:不可信来源,或没有
|
|
285
|
+
宿主签发凭据的请求,直接 401/403 且空 body;只有宿主没有该服务时才跳过栅栏(此时行为与 2.0.0
|
|
286
|
+
相同)。事件流只存策略与会话元数据:字符串会被拍平并截到 200 字符,会话正文
|
|
285
287
|
永远不写进去。内容抽屉只在打开时读磁盘,只读快照登记过的路径,读完不落盘。
|
|
286
288
|
|
|
287
289
|
## 自查
|
package/docs/ARCHITECTURE.md
CHANGED
|
@@ -168,7 +168,17 @@ locale/*.json 八语言字典(宿主展示用 meta + 客户端词条)
|
|
|
168
168
|
|
|
169
169
|
## 安全边界
|
|
170
170
|
|
|
171
|
-
-
|
|
171
|
+
- **所有 15 条路由入口先过宿主的准入栅栏。** `webServer.register` 前统一包一层
|
|
172
|
+
`makeFencedHandler(ctx, handler)`:每个请求先问 `ctx.connection.requestRejection(req)`
|
|
173
|
+
(DSH 自己的 Host/Origin 准入 + 浏览器/API 凭据)。宿主返回 `401/403` 时由栅栏直接应答
|
|
174
|
+
(空 body + `nosniff`/`no-referrer`/frame-deny/`no-store`),路由逻辑、文件与策略都不执行;
|
|
175
|
+
返回 `undefined` 才放行。
|
|
176
|
+
- 返回 `undefined` 才放行;只有宿主明确返回 401/403 时才拒绝(失败开放:缺服务、缺方法、抛错、异常返回值都放行)。
|
|
177
|
+
- **栅栏可降级,不是硬依赖。** `connection` 没有加进 `inject`:宿主缺少该服务(旧版本、或启动
|
|
178
|
+
早期)、没有 `requestRejection` 方法、或调用抛错时,栅栏跳过,路由保持 2.0.0 的行为——安全
|
|
179
|
+
栅栏不能把面板变砖。
|
|
180
|
+
- 写操作(`POST /action`)在此基础上仍要求 `content-type: application/json`,且
|
|
181
|
+
`sec-fetch-site` 不是跨站;带 `Origin` 时还要求 host 与页面一致。
|
|
172
182
|
- 所有 JSON 响应带 `x-content-type-options: nosniff`、`x-frame-options: DENY`、`cache-control: no-store`。
|
|
173
183
|
- 没有任何 GET 路由会写文件:`/summary`、`/content`、`/trend`、`/events`、`/health`、`/stats`、`/verify`、`/export` 都只读策略、快照、统计与事件文件。
|
|
174
184
|
- `/content` 是唯一读磁盘内容的接口,但路径来自快照登记,不接受外部路径;有 2 秒预算与 256KB 上限。
|
|
@@ -193,3 +203,4 @@ locale/*.json 八语言字典(宿主展示用 meta + 客户端词条)
|
|
|
193
203
|
| `test/health.test.mjs` | 每个 code 的触发条件、排序、summary、不产生的 code |
|
|
194
204
|
| `test/tool-content.test.mjs` | 模型工具单条模式:参数校验、32KB 上限、错误 JSON |
|
|
195
205
|
| `test/command.test.mjs` | `/inject` 子命令(含 health)与错误分支 |
|
|
206
|
+
| `test/fence.test.mjs` | 准入栅栏:缺服务/无方法/undefined/抛错放行,401/403 拒绝且 handler 不执行,15 条路由全包,旧宿主路径仍可用 |
|
package/docs/COMPATIBILITY.md
CHANGED
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
| `ctx.tools.schemas(agent)` / `restrict({ deny })` | 工具 schema 清单与裁剪 | 工具无法关闭 |
|
|
25
25
|
| `ctx.agents.get(id)` / `currentInitiator()` | 面板对会话取数 | 退回到最近活跃会话 |
|
|
26
26
|
| `ctx.webServer.register({ kind: 'exact' })` | 面板路由 | 面板无数据(工具与命令仍可用) |
|
|
27
|
+
| `ctx.connection.requestRejection(req)` | 15 条路由入口的 Host/Origin 准入栅栏(2.0.1 起) | 跳过栅栏,路由保持 2.0.0 的旧行为(可降级,不是硬依赖) |
|
|
27
28
|
| `agent/created` 事件的 `source` | 区分新会话与恢复/压缩 | 只按 `startup` / `clear` 兜底 |
|
|
28
29
|
| `ctx.get('tokenMeter').contextPressure(session)` | 窗口占用:分子(provider 报的 prompt)与分母(`contextWindow`) | 窗口卡片显示「窗口未知」,其余功能不受影响 |
|
|
29
30
|
| `ctx.get('sessionProjections').snapshot(session)` 的 `contextBreakdown` | 系统 / 工具 / 消息构成 | 只显示占用条,不显示构成 |
|
|
@@ -45,6 +46,8 @@ v2 新增的四条只读路由与它们的宿主侧依赖:
|
|
|
45
46
|
|
|
46
47
|
宿主版本无关:这些路由全部由插件自己实现,只用到 `0.2.2` 已有的公开服务(`agents`、`webServer`、`sessionQuery`)。
|
|
47
48
|
|
|
49
|
+
**准入栅栏(2.0.1 起)**:15 条路由的每个入口先过 `ctx.connection.requestRejection(req)`——DSH 自己的 Host/Origin 准入与浏览器/API 凭据校验,不符直接 401/403 且不执行路由逻辑。`connection` 不是硬依赖:服务缺失(旧宿主/启动早期)、方法缺失或调用抛错时跳过栅栏,路由保持 2.0.0 的行为。
|
|
50
|
+
|
|
48
51
|
## 明确不可管(不是兼容性问题)
|
|
49
52
|
|
|
50
53
|
- 工作区规则(`AGENTS.md` / `CLAUDE.md`):`dsh-agent-instructions` 在 `agent/pre-step` 直接注入 user 消息,0.2.2 没有公开抑制入口;本插件只读展示。
|
package/docs/FAQ.md
CHANGED
|
@@ -83,6 +83,10 @@
|
|
|
83
83
|
|
|
84
84
|
不会。应用预算会按目标 token 重算四条通道,把当前单个条目的关闭/开启**替换掉**。所以面板在检测到已有手动关闭项时会先提示「当前有 N 项被手动关闭;应用建议会按预算重算,并覆盖这些选择。」切换预设(全开/极简)同理。如果只想保留手动结果,别点「应用这套建议」,直接调大预算即可。
|
|
85
85
|
|
|
86
|
+
## 这些 HTTP 路由会不会被网页跨站调用?
|
|
87
|
+
|
|
88
|
+
不会裸奔。2.0.1 起,全部 15 条路由在入口先过宿主 DSH 自己的准入门(`ctx.connection.requestRejection`):Host/Origin 不被信任、或请求没有宿主签发的浏览器/API 凭据时,直接返回 401/403,空 body,路由逻辑与文件读取都不执行。写操作本来还有一层同源 POST 校验(JSON content-type + `sec-fetch-site` + 匹配的 `Origin`)。宿主没有 `connection` 服务(旧版本或启动早期)时栅栏自动跳过,插件保持旧行为——不会因此把面板挡死。
|
|
89
|
+
|
|
86
90
|
## 数据存在哪?会上传吗?
|
|
87
91
|
|
|
88
92
|
四个地方:`policy.json`(开关与预算)、`stats.json`(每会话测量与通道分解)、`events.json`(事件流)、插件行的 `config`;另有浏览器 localStorage 存两个纯界面偏好。没有网络请求,没有遥测,不上传策略或会话内容。
|
package/index.js
CHANGED
|
@@ -15,7 +15,7 @@ import { createRequire } from 'node:module'
|
|
|
15
15
|
import { homedir } from 'node:os'
|
|
16
16
|
import { join } from 'node:path'
|
|
17
17
|
import { applyPolicyForAgent, releaseAll, savePolicy } from './lib/apply.js'
|
|
18
|
-
import { createRoutes, ROUTES } from './lib/routes.js'
|
|
18
|
+
import { createRoutes, makeFencedHandler, ROUTES } from './lib/routes.js'
|
|
19
19
|
import { buildSnapshot, planBudget, policyFromPlan } from './lib/snapshot.js'
|
|
20
20
|
import { watchCompaction } from './lib/compaction.js'
|
|
21
21
|
import { CONTENT_CHANNELS, TOOL_CONTENT_LIMIT, collectContent } from './lib/content.js'
|
|
@@ -277,7 +277,12 @@ export function apply(ctx, config) {
|
|
|
277
277
|
for (const [key, path] of Object.entries(ROUTES)) {
|
|
278
278
|
const handler = routes[key]
|
|
279
279
|
if (typeof handler !== 'function') continue
|
|
280
|
-
|
|
280
|
+
// Every registered route first asks the host's connection service for a
|
|
281
|
+
// Host/Origin (and browser-auth) rejection. A rejected request is answered
|
|
282
|
+
// by the fence itself, before any route logic or file read. Older hosts
|
|
283
|
+
// without the service fall through unchanged (see makeFencedHandler).
|
|
284
|
+
const fenced = makeFencedHandler(ctx, handler)
|
|
285
|
+
ctx.effect(() => ctx.webServer.register({ kind: 'exact', path, handler: fenced }), `injection-manager route ${key}`)
|
|
281
286
|
}
|
|
282
287
|
|
|
283
288
|
// The only moment a policy can still influence the first assemble().
|
package/lib/routes.js
CHANGED
|
@@ -64,6 +64,68 @@ function harden(res) {
|
|
|
64
64
|
res.setHeader('x-frame-options', 'DENY')
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
// ---------------------------------------------------------------- trust fence
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Resolve the host's `connection` service without making it a hard dependency.
|
|
71
|
+
* DSH 0.2.2+ exposes `ctx.connection`; older hosts do not, and the plugin must
|
|
72
|
+
* keep working there. `ctx.get()` is the public service accessor; the property
|
|
73
|
+
* read covers contexts where the service is exposed directly.
|
|
74
|
+
*/
|
|
75
|
+
export function connectionOf(ctx) {
|
|
76
|
+
try {
|
|
77
|
+
const viaGet = typeof ctx?.get === 'function' ? ctx.get('connection') : undefined
|
|
78
|
+
if (viaGet !== undefined && viaGet !== null) return viaGet
|
|
79
|
+
} catch {
|
|
80
|
+
/* fall through to the property read */
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
return Reflect.get(ctx, 'connection')
|
|
84
|
+
} catch {
|
|
85
|
+
return undefined
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Apply the host's Host/Origin (and browser-auth) fence to one registered
|
|
91
|
+
* route. Returns true when the request was answered with a 401/403 and the
|
|
92
|
+
* handler must not run; false when the caller may proceed.
|
|
93
|
+
*
|
|
94
|
+
* A missing service, a missing method and thrown errors all mean "proceed": a
|
|
95
|
+
* security fence must never turn the panel into a blank page on an older host
|
|
96
|
+
* or during early boot. The rejection is answered by the fence itself, before
|
|
97
|
+
* any route logic runs, so no JSON, file or policy data can leak.
|
|
98
|
+
*/
|
|
99
|
+
export function fenceRequest(ctx, req, res) {
|
|
100
|
+
let rejection
|
|
101
|
+
try {
|
|
102
|
+
const connection = connectionOf(ctx)
|
|
103
|
+
if (connection === undefined || connection === null || typeof connection.requestRejection !== 'function') return false
|
|
104
|
+
rejection = connection.requestRejection(req)
|
|
105
|
+
} catch {
|
|
106
|
+
return false
|
|
107
|
+
}
|
|
108
|
+
if (rejection !== 401 && rejection !== 403) return false
|
|
109
|
+
try {
|
|
110
|
+
res.statusCode = rejection
|
|
111
|
+
// A rejected request carries no data and must not be cached or sniffed.
|
|
112
|
+
res.setHeader('cache-control', 'no-store')
|
|
113
|
+
harden(res)
|
|
114
|
+
res.end()
|
|
115
|
+
} catch {
|
|
116
|
+
/* the socket may already be gone; the request was still rejected */
|
|
117
|
+
}
|
|
118
|
+
return true
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Wrap one route handler with the trust fence at registration time. */
|
|
122
|
+
export function makeFencedHandler(ctx, handler) {
|
|
123
|
+
return async function fenced(req, res) {
|
|
124
|
+
if (fenceRequest(ctx, req, res) === true) return undefined
|
|
125
|
+
return handler(req, res)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
67
129
|
function respondJson(res, statusCode, payload) {
|
|
68
130
|
const body = Buffer.from(JSON.stringify(payload), 'utf8')
|
|
69
131
|
res.statusCode = statusCode
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-injection-manager",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "See and control everything a DeepSeek Harness session injects before its first request — prompt sections, runtime contexts, skills, tool schemas and workspace rules — with a content browser that opens each item's source, cross-session injection trends, an injection event log, health checks, suite switches, presets and a token budget.",
|
|
6
6
|
"keywords": [
|