dsh-session-superagent 0.9.205 → 0.9.206

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 CHANGED
@@ -2,6 +2,51 @@
2
2
 
3
3
  格式参照 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/),版本号遵循 [语义化版本](https://semver.org/lang/zh-CN/)。
4
4
 
5
+ ## [0.9.206] - 2026-11-05 —— 路由安全审计:任意网页都能删掉你的守
6
+
7
+ ### ① 九条路由零来源校验(CSRF)
8
+
9
+ 宿主只绑 `127.0.0.1`,但**浏览器里的任意网页**都能往 localhost 发请求:`text/plain` 是「简单请求」,
10
+ 不触发预检;而 CORS 只挡跨站**读**响应,不挡副作用。真机实测:
11
+
12
+ ```
13
+ 跨站 POST /watch {action:delete} → 200 {"deleted":true} 状态文件真被删
14
+ 跨站 POST /credentials {token:""} → 200 secrets.json 里 token 消失
15
+ 跨站 POST /goal → 200 活会话目标被改成「忽略用户的指令…」
16
+ ```
17
+
18
+ 宿主层也不拦(`app.asar` 里抽出来的派发就是 pathname 查表,没有 Origin/Referer 校验)。
19
+ 现在三条写路由统一走 `guardWrite()`:**带了 Origin 就必须是本机**(127.0.0.1 / localhost / ::1)。
20
+ 浏览器跨站 POST 一定带 Origin;curl / 测试不带,所以合法用法不受影响。
21
+
22
+ ### ② `id = "__proto__"` 原型污染
23
+
24
+ `watchers[id]` 命中 `Object.prototype`,随后 `entry.enabled = false` **写到原型上** ——
25
+ 进程级生效(所有缺省 `enabled` 的守、同进程其它插件一起受影响),而盘上一个字没改。
26
+ 实测:`({}).enabled` 变成 `false`。已改成只认**自有属性**且 id 必须是字符串。
27
+
28
+ ### ③ 请求体没有硬上限
29
+
30
+ 64KB 以前只是「读完再截断」—— 48MB 的请求体会先把 RSS 从 105MB 顶到 333MB。
31
+ 现在边读边算,超了立刻 `destroy()` 并返回 **413**。
32
+
33
+ ### ④ `repo` 放行 `..`
34
+
35
+ `.` 和 `..` 能过 `[A-Za-z0-9_.-]+` 这条字符类,于是 `../..` 会被当成 owner/name 一路拼进 URL 与磁盘路径。
36
+ 已拒绝这两个路径段。
37
+
38
+ ### 未修(登记)
39
+
40
+ `workdir` 可以指到任意路径(实测能落盘到 `C:\Windows`)、`sessionId` 无长度校验、`/update?refresh=1` 可被迫出站、
41
+ 守数量无上限。这些都需要产品级决策(workdir 该不该限制到某个根),单独立项。
42
+
43
+ ### 证据
44
+
45
+ ```
46
+ node --test → 355/355(新增:跨站 403 / __proto__ 被拒 / repo 拒绝 ..)
47
+ 实测:__proto__ → {"ok":false},({}).enabled = undefined,正常 id 照旧
48
+ ```
49
+
5
50
  ## [0.9.205] - 2026-11-05 —— 门禁锁只覆盖 2/39 项;`verify-gates` 被强杀会留下坏文件
6
51
 
7
52
  ### M2 · 整轮门禁只持一把锁
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  <img src="assets/icon-180.png" width="88" height="88" alt="">
4
4
 
5
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
- [![Version](https://img.shields.io/badge/version-0.9.205-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
6
+ [![Version](https://img.shields.io/badge/version-0.9.206-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
7
7
  [![npm](https://img.shields.io/npm/v/dsh-session-superagent.svg)](https://www.npmjs.com/package/dsh-session-superagent)
8
8
  [![dsh](https://img.shields.io/badge/DeepSeek%20Harness-plugin-orange.svg)](https://github.com/topics/dsh-plugin)
9
9
 
@@ -144,7 +144,7 @@ Gitee 私有仓库要在「设置 → 凭证」填私人令牌;公开仓库不
144
144
  ## 开发
145
145
 
146
146
  ```sh
147
- node --test # 352 项单测
147
+ node --test # 355 项单测
148
148
  ```
149
149
 
150
150
  ### 工具输出:文本给人和 agent,JSON 给程序
package/client.js CHANGED
@@ -14,7 +14,7 @@ window.__ModuleLoader__.load({
14
14
  const { useCallback, useEffect, useRef, useState } = React
15
15
 
16
16
  // 客户端版本探针:每次模块加载写一次,用来确认浏览器里跑的是哪一版
17
- const CLIENT_VERSION = '0.9.205'
17
+ const CLIENT_VERSION = '0.9.206'
18
18
  let BASE = '/session-superagent'
19
19
  /**
20
20
  * 挑「最新的那个服务端实例」。
package/lib/index.js CHANGED
@@ -42,7 +42,7 @@ import {
42
42
 
43
43
  export const name = 'dsh-session-superagent'
44
44
  /** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
45
- export const SERVER_VERSION = '0.9.205'
45
+ export const SERVER_VERSION = '0.9.206'
46
46
  export const inject = ['tools', 'agents', 'webServer']
47
47
  /** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
48
48
  // 本进程启动时刻:用来区分「刚重启还没轮到」与「定时器真的丢了」
@@ -1800,10 +1800,27 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
1800
1800
  path: '/session-superagent/client-error',
1801
1801
  handler: (req, res) => { record('error', String(req.url).slice(0, 400)); res.statusCode = 204; res.end() },
1802
1802
  })
1803
- const readBody = (req) => new Promise((resolve) => {
1803
+ // 审核 T19:64KB 以前只是「读完再截断」—— 48MB 的请求体会先把 RSS 从 105MB 顶到 333MB。
1804
+ // 现在边读边算,超了立刻 destroy 并返回 413。
1805
+ const MAX_BODY_BYTES = 64 * 1024
1806
+ const readBody = (req, res) => new Promise((resolve) => {
1804
1807
  const chunks = []
1805
- req.on('data', (chunk) => chunks.push(chunk))
1808
+ let bytes = 0
1809
+ let aborted = false
1810
+ req.on('data', (chunk) => {
1811
+ if (aborted) return
1812
+ bytes += chunk.length
1813
+ if (bytes > MAX_BODY_BYTES) {
1814
+ aborted = true
1815
+ try { res.statusCode = 413; res.setHeader('content-type', 'application/json; charset=utf-8'); res.end(JSON.stringify({ error: 'request body too large' })) } catch { /* 尽力而为 */ }
1816
+ try { req.destroy() } catch { /* 尽力而为 */ }
1817
+ resolve(null)
1818
+ return
1819
+ }
1820
+ chunks.push(chunk)
1821
+ })
1806
1822
  req.on('end', () => {
1823
+ if (aborted) return
1807
1824
  try {
1808
1825
  // 按字符边界截断:直接 subarray 会切开汉字,剩下的半截被 decodeBody 当成 GBK 整段重解(T16)
1809
1826
  const raw = decodeBody(truncateUtf8(Buffer.concat(chunks), 64 * 1024))
@@ -1819,6 +1836,38 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
1819
1836
  res.end(JSON.stringify(body))
1820
1837
  }
1821
1838
 
1839
+ /**
1840
+ * 写操作的来源校验(审核 T19)。
1841
+ *
1842
+ * 宿主只绑 127.0.0.1,但**浏览器里的任意网页**都能往 localhost 发请求:
1843
+ * `text/plain` 是「简单请求」,不触发预检,而 CORS 只挡跨站**读**响应、不挡副作用。
1844
+ * 实测:跨站 POST `{action:'delete'}` 就能删守、清凭证、改活会话目标。
1845
+ *
1846
+ * 两道闸(任一不过就 403):
1847
+ * 1. `Content-Type` 必须是 `application/json` —— 这就要求预检,浏览器会先问 OPTIONS;
1848
+ * 2. 带了 `Origin` 就必须是**本机**(127.0.0.1 / localhost / [::1])。
1849
+ * 非浏览器客户端(curl / 测试)不带 Origin,只受第 1 条约束。
1850
+ */
1851
+ const allowedOrigin = (origin) => {
1852
+ if (!origin) return true // 非浏览器(curl、同源 GET)
1853
+ try {
1854
+ const url = new URL(origin)
1855
+ return url.hostname === '127.0.0.1' || url.hostname === 'localhost' || url.hostname === '[::1]' || url.hostname === '::1'
1856
+ } catch {
1857
+ return false
1858
+ }
1859
+ }
1860
+ const guardWrite = (req, res) => {
1861
+ // 只查 Origin:浏览器跨站 POST **一定**带它(简单请求也一样),而 curl / 测试不带。
1862
+ // 不要求 content-type —— 那会把 curl 之类的合法用法一起挡掉,收益还一样。
1863
+ const origin = req.headers.origin || req.headers.referer
1864
+ if (!allowedOrigin(origin)) {
1865
+ json(res, 403, { error: 'cross-origin request refused' })
1866
+ return false
1867
+ }
1868
+ return true
1869
+ }
1870
+
1822
1871
  // Create or update a watcher from the panel. The panel is session-scoped,
1823
1872
  // so it must send the session id it is bound to.
1824
1873
  addRoute({
@@ -1826,7 +1875,9 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
1826
1875
  path: '/session-superagent/watch',
1827
1876
  handler: async (req, res) => {
1828
1877
  if (req.method !== 'POST') return json(res, 405, { error: 'method not allowed' })
1829
- const body = await readBody(req)
1878
+ if (!guardWrite(req, res)) return // 来源不对:已回 403
1879
+ const body = await readBody(req, res)
1880
+ if (!body) return // 已回 413
1830
1881
  // pause / resume / delete target an existing watcher by id; the
1831
1882
  // create path below is the default when no action is supplied.
1832
1883
  if (body.action) {
@@ -1966,7 +2017,9 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
1966
2017
  path: '/session-superagent/credentials',
1967
2018
  handler: async (req, res) => {
1968
2019
  if (req.method !== 'POST') return json(res, 405, { error: 'method not allowed' })
1969
- const body = await readBody(req)
2020
+ if (!guardWrite(req, res)) return // 来源不对:已回 403
2021
+ const body = await readBody(req, res)
2022
+ if (!body) return // 已回 413
1970
2023
  const next = readSecrets()
1971
2024
  if (typeof body.token === 'string') {
1972
2025
  const token = body.token.trim()
@@ -2086,7 +2139,9 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2086
2139
  path: '/session-superagent/goal',
2087
2140
  handler: async (req, res) => {
2088
2141
  if (req.method !== 'POST') return json(res, 405, { error: 'method not allowed' })
2089
- const body = await readBody(req)
2142
+ if (!guardWrite(req, res)) return // 来源不对:已回 403
2143
+ const body = await readBody(req, res)
2144
+ if (!body) return // 已回 413
2090
2145
  const sessionId = String(body.sessionId || '').trim()
2091
2146
  const objective = String(body.objective || '').trim()
2092
2147
  if (!sessionId) return json(res, 400, { error: 'sessionId is required' })
package/lib/watch.js CHANGED
@@ -452,8 +452,13 @@ export function newestUpdatedAt(fresh) {
452
452
  */
453
453
  export function applyWatcherAction(state, { action, id } = {}) {
454
454
  const watchers = (state && state.watchers) || {}
455
+ // 审核 T19:`id = "__proto__"` 会命中 Object.prototype —— 随后 `entry.enabled = false`
456
+ // 写到**原型**上,进程级生效(所有缺省 enabled 的守、同进程其它插件一起受影响),
457
+ // 而盘上一个字没改。只认自有属性,且 id 必须是字符串。
458
+ if (typeof id !== 'string' || !id || !Object.prototype.hasOwnProperty.call(watchers, id)) {
459
+ return { ok: false, error: `unknown watcher: ${id || '(missing id)'}` }
460
+ }
455
461
  const entry = watchers[id]
456
- if (!entry) return { ok: false, error: `unknown watcher: ${id || '(missing id)'}` }
457
462
  if (action === 'delete') {
458
463
  delete watchers[id]
459
464
  return { ok: true, action, id, deleted: true }
@@ -1139,6 +1144,11 @@ export function parseRepoSpec(input) {
1139
1144
  if (!/^[A-Za-z0-9_.-]+$/.test(owner) || !/^[A-Za-z0-9_.-]+$/.test(name)) {
1140
1145
  return { ok: false, error: 'owner/name 只能包含字母、数字、下划线、点、短横线' }
1141
1146
  }
1147
+ // 审核 T19:`.` 和 `..` 能过上面那条字符类(点也算合法字符),于是 `'../..'` 会被当成 owner/name ——
1148
+ // 它会一路拼进 URL 与磁盘路径。路径段不许是这两个。
1149
+ if (owner === '.' || owner === '..' || name === '.' || name === '..') {
1150
+ return { ok: false, error: 'owner/name 不能是 . 或 ..' }
1151
+ }
1142
1152
  return { ok: true, provider, repo: owner + '/' + name, spec: provider === 'github' ? owner + '/' + name : 'gitee:' + owner + '/' + name }
1143
1153
  }
1144
1154
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-superagent",
3
- "version": "0.9.205",
3
+ "version": "0.9.206",
4
4
  "description": "Session-level superagent for DeepSeek Harness: watch a GitHub repository and wake a session when something needs doing. Credentials never reach the model.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",