@240xu/dsh-message-ops 0.47.0 → 0.47.2
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/README.md +6 -1
- package/package.json +4 -2
- package/src/index.js +81 -3
package/README.md
CHANGED
|
@@ -2043,10 +2043,15 @@ applyScriptLive`),replace 语义由 `applySurfaceReplace` 唯一拥有。旧
|
|
|
2043
2043
|
| --- | --- |
|
|
2044
2044
|
| 0.46.0 | 消息详情区分「取消」与「读取失败」:写操作作废了在途 `/text` 请求时不再误报失败(保持读取态并自动重取一次),超时用专用文案 |
|
|
2045
2045
|
| 0.46.1 | **P0**:宿主 0.2.3 服务隔离使 `connection.admit` 抛错,旧代码把异常当拒绝 → 全站 401。现降级到静态围栏(回环 + same-origin + BrowserAuth):真机 `GET /messages` 200、`POST /revert` 200、`POST /restore` 200 全部复验 |
|
|
2046
|
-
|
|
|
2046
|
+
| 0.46.1 | 围栏在 `admit` 抛隔离错误时降级到静态围栏(不再全站 401) |
|
|
2047
|
+
| 0.47.1 | 新增 `config.trustedHosts`:0.2.3 + `inject=[]` 时部署方可显式声明可信 Host(同源 + BrowserAuth cookie 条件不放宽),非回环站点重新可用 |
|
|
2047
2048
|
|
|
2048
2049
|
当前规模:**744 tests / 740 pass / 4 skip / 0 todo / 0 fail**(`npm test`)。
|
|
2049
2050
|
|
|
2051
|
+
基准:`npm run bench:incremental`(离线合成事件,可复现增量派生成本);CI 每次在
|
|
2052
|
+
Node 22/24 上跑 20k 事件档并设 200ms 宽松上限(本地 revert 批 1.5ms / restore 批 1.9ms,
|
|
2053
|
+
全量重算 49ms 是增量合并的 14.4×)。
|
|
2054
|
+
|
|
2050
2055
|
真机验证记录见 [`docs/verification/`](docs/verification/README.md)(环境基线、复核手法、
|
|
2051
2056
|
每轮逐项判定与证据)。最近一轮:0.46.1 在宿主 0.2.3-alpha.3 上的 P0 修复复验(9 项 PASS)
|
|
2052
2057
|
与大日志增量派生实测。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@240xu/dsh-message-ops",
|
|
3
|
-
"version": "0.47.
|
|
3
|
+
"version": "0.47.2",
|
|
4
4
|
"description": "DSH web 插件:消息级回滚 / 删除 / 恢复 / 分叉 / 编辑重发(补 dsh 官方没有的部分)。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -44,7 +44,9 @@
|
|
|
44
44
|
"scripts": {
|
|
45
45
|
"build:client": "node scripts/build-client.mjs",
|
|
46
46
|
"test": "node --check src/client.js && node --test \"test/*.test.js\"",
|
|
47
|
-
"prepack": "npm run build:client"
|
|
47
|
+
"prepack": "npm run build:client",
|
|
48
|
+
"bench:incremental": "node bench/incremental.mjs",
|
|
49
|
+
"bench": "node bench/derive.mjs"
|
|
48
50
|
},
|
|
49
51
|
"peerDependencies": {
|
|
50
52
|
"@deepseek-ai/dsh-tools": "^0.1.0-rc.6 || ^0.2.0-rc.1 || ^0.2.2-rc.5 || ^0.2.3-alpha.3",
|
package/src/index.js
CHANGED
|
@@ -169,6 +169,41 @@ async function readJsonBody(req) {
|
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
+
/**
|
|
173
|
+
* 判定请求是否来自**显式配置**的可信 Host(0.47.1,srv-audit E19)。
|
|
174
|
+
*
|
|
175
|
+
* 宿主 0.2.3 下 `connection.admit` 不可调用时,非回环站点只能靠部署方在插件
|
|
176
|
+
* `config.trustedHosts` 里显式声明。判定与宿主同条件:
|
|
177
|
+
* - Host(去端口)必须精确命中列表;
|
|
178
|
+
* - `sec-fetch-site` 存在时必须是 same-origin(拒 cross-site);
|
|
179
|
+
* - `Origin` 存在时必须与本请求 Host 同源。
|
|
180
|
+
* 之后仍要过 `webAuthGate`(BrowserAuth cookie)—— 配置只放宽「来源」,不放宽认证。
|
|
181
|
+
*
|
|
182
|
+
* @param {object} req Node HTTP 请求(需 headers)
|
|
183
|
+
* @returns {boolean} 是否命中配置的可信 Host
|
|
184
|
+
*/
|
|
185
|
+
function isConfiguredTrustedHost(req) {
|
|
186
|
+
if (__trustedHosts.length === 0) return false
|
|
187
|
+
const headers = (req && req.headers) || {}
|
|
188
|
+
const hostHeader = String(headers.host || '').toLowerCase()
|
|
189
|
+
if (!hostHeader) return false
|
|
190
|
+
const hostnameOnly = hostHeader.split(':')[0]
|
|
191
|
+
if (!__trustedHosts.includes(hostHeader) && !__trustedHosts.includes(hostnameOnly)) return false
|
|
192
|
+
const site = String(headers['sec-fetch-site'] || '').toLowerCase()
|
|
193
|
+
if (site && site !== 'same-origin' && site !== 'none') return false
|
|
194
|
+
const origin = String(headers.origin || '').toLowerCase()
|
|
195
|
+
if (origin) {
|
|
196
|
+
let originHost = ''
|
|
197
|
+
try {
|
|
198
|
+
originHost = new URL(origin).host
|
|
199
|
+
} catch {
|
|
200
|
+
return false
|
|
201
|
+
}
|
|
202
|
+
if (originHost !== hostHeader && originHost !== hostnameOnly) return false
|
|
203
|
+
}
|
|
204
|
+
return true
|
|
205
|
+
}
|
|
206
|
+
|
|
172
207
|
/**
|
|
173
208
|
* 统一入口围栏:全部 /api/message-ops/* 路由先过这一层。
|
|
174
209
|
*
|
|
@@ -228,8 +263,13 @@ async function fence(targetCtx, req, res) {
|
|
|
228
263
|
}
|
|
229
264
|
return true
|
|
230
265
|
}
|
|
231
|
-
if (!isTrustedApiRequest(req)) {
|
|
232
|
-
sendJson(res, 403, {
|
|
266
|
+
if (!isTrustedApiRequest(req) && !isConfiguredTrustedHost(req)) {
|
|
267
|
+
sendJson(res, 403, {
|
|
268
|
+
ok: false,
|
|
269
|
+
error: __trustedHosts.length > 0
|
|
270
|
+
? 'untrusted request origin (host not in config.trustedHosts + same-origin only)'
|
|
271
|
+
: 'untrusted request origin (loopback Host + same-origin only)',
|
|
272
|
+
})
|
|
233
273
|
return false
|
|
234
274
|
}
|
|
235
275
|
// 0.10.8:宿主同条件 GET 被读全量(审计缺口)。宿主 /api admit = 三层围栏
|
|
@@ -1490,6 +1530,12 @@ async function runDiskWrite({ logPath, diag, plannedOf, scriptOf, resultOf }) {
|
|
|
1490
1530
|
/** 测试钩子(非公开 API):直接驱动 list / search / text 与文件派生缓存。 */
|
|
1491
1531
|
export const _internals = {
|
|
1492
1532
|
errorStatusOf,
|
|
1533
|
+
deriveFromEvents,
|
|
1534
|
+
validateConfig,
|
|
1535
|
+
isConfiguredTrustedHost,
|
|
1536
|
+
setTrustedHostsForTests: hosts => {
|
|
1537
|
+
__trustedHosts = hosts
|
|
1538
|
+
},
|
|
1493
1539
|
publicErrorOf,
|
|
1494
1540
|
runningSourceOf: () => __runningSource,
|
|
1495
1541
|
resetCapturedServicesForTests,
|
|
@@ -1977,7 +2023,39 @@ function registerToolTolerantly(ctx, loadDefineTool) {
|
|
|
1977
2023
|
// 插件入口:HTTP 路由 + 容错工具注册
|
|
1978
2024
|
// ---------------------------------------------------------------------------
|
|
1979
2025
|
|
|
1980
|
-
|
|
2026
|
+
/**
|
|
2027
|
+
* 校验插件配置(0.47.1,srv-audit E19)。
|
|
2028
|
+
*
|
|
2029
|
+
* 宿主 0.2.3 + `inject=[]` 时 `connection.admit` 不可调用(服务隔离),插件拿不到
|
|
2030
|
+
* trustedHosts 判定。此处允许部署方显式配置可信 Host(cordis.yml 的插件 `config`),
|
|
2031
|
+
* 让经 `--trusted-host` 暴露的站点仍可用 —— 与宿主判定同条件(同源 + BrowserAuth cookie)。
|
|
2032
|
+
*
|
|
2033
|
+
* @param {unknown} config cordis 传入的插件配置
|
|
2034
|
+
* @returns {{trustedHosts: string[]}} 规范化后的配置
|
|
2035
|
+
* @throws {Error} 配置形状非法时 fail loud(不静默忽略)
|
|
2036
|
+
*/
|
|
2037
|
+
export function validateConfig(config) {
|
|
2038
|
+
if (config === undefined || config === null) return { trustedHosts: [] }
|
|
2039
|
+
if (typeof config !== 'object' || Array.isArray(config)) throw new Error('dsh-message-ops: config must be an object')
|
|
2040
|
+
const unknown = Object.keys(config).filter(key => key !== 'trustedHosts')
|
|
2041
|
+
if (unknown.length > 0) throw new Error(`dsh-message-ops: unknown config key "${unknown[0]}"`)
|
|
2042
|
+
const raw = config.trustedHosts
|
|
2043
|
+
if (raw === undefined) return { trustedHosts: [] }
|
|
2044
|
+
if (!Array.isArray(raw)) throw new Error('dsh-message-ops: trustedHosts must be an array of host names')
|
|
2045
|
+
const hosts = []
|
|
2046
|
+
for (const item of raw) {
|
|
2047
|
+
if (typeof item !== 'string' || item.trim() === '') throw new Error('dsh-message-ops: trustedHosts entries must be non-empty strings')
|
|
2048
|
+
if (/^[^:/]*:/.test(item) || item.includes('/')) throw new Error(`dsh-message-ops: trustedHosts entry "${item}" must be a bare host name (no port, no scheme)`)
|
|
2049
|
+
hosts.push(item.trim().toLowerCase())
|
|
2050
|
+
}
|
|
2051
|
+
return { trustedHosts: hosts }
|
|
2052
|
+
}
|
|
2053
|
+
|
|
2054
|
+
/** 本插件进程内生效的可信 Host 列表(apply 时写入;测试可重置)。 */
|
|
2055
|
+
let __trustedHosts = []
|
|
2056
|
+
|
|
2057
|
+
export function apply(ctx, config) {
|
|
2058
|
+
__trustedHosts = validateConfig(config).trustedHosts
|
|
1981
2059
|
// 诊断(0.5.4 调试):会话状态服务解析情况
|
|
1982
2060
|
try {
|
|
1983
2061
|
const names = ['sessions', 'agents', 'sessionController', 'sessionList', 'session-manager']
|