dsh-session-superagent 0.9.198 → 0.9.200

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,58 @@
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.200] - 2026-11-05 —— 安全审计:最该脱敏的那个出口,一个字符都没脱
6
+
7
+ ### M1 · 唤醒消息完全没走 `redact()`(本轮最重)
8
+ issue 标题/评论是**外部内容**,会被拼进唤醒消息 —— 而唤醒消息是**唯一必进模型上下文**的出口。
9
+ 全仓 11 个 `redact()` 调用点全在错误分支上,方向正好反了。
10
+ 真机实测:标题里放 GitHub 令牌,原样进上下文。已在 `wake()` 出口统一脱敏。
11
+
12
+ ### M2 / M3 · 25 种真实凭证形状,实测漏 16 种
13
+ 补上:GitLab `glpat-`、AWS `AKIA`、Slack `xoxb-`、Stripe `sk_live_`、npm、Google `AIza`、JWT、
14
+ 数据库 URL 里的密码(postgres/mysql/mongodb/redis/amqp)、裸 `Bearer`、`Authorization: Basic`、
15
+ **被截断的 PEM**(无 END)、PGP 私钥块、查询参数里的 `access_token`、无前缀的 **Gitee 32 位令牌**。
16
+ **不误伤**:讨论 `ghp_` 前缀、40 位 sha、md5、issue 链接都原样保留(有单测钉住)。
17
+
18
+ ### M4 · Gitee 错误正文原样进 `watch_doctor` 结果
19
+ `lastError` 里带着 Gitee 返回的原始响应体,而 doctor 的输出会进模型上下文。已在输出处脱敏。
20
+
21
+ ### M5 · issue 标题能伪造「【主理鱼】」抬头(注入面)
22
+ 同一函数里 `goal` 的换行早就被压平了,`title` 漏了 —— 说明知道要防,不是设计如此。
23
+ 现在标题压平换行、把 `【】` 换成 `[]`(保留内容,只让它无法伪造结构),并截断 200 字。
24
+
25
+ ### 证据
26
+ ```
27
+ node --test → 345/345(新增:14 种凭证形状必须脱、4 种正常文本必须不脱)
28
+ 审核报告:docs/报告-脱敏与注入审计.md(4 必须修 / 7 值得改)
29
+ ```
30
+
31
+ ### 仍未修(登记)
32
+ `\S+` 吃掉引号、未闭合 PEM 的平方复杂度、64 KB 按字节截断切坏汉字、脱敏无收口点(24 个 `run(` vs 12 个 `redact(`)。
33
+ ## [0.9.199] - 2026-11-05 —— Gitee 边界审计剩余三条(其中最危险的会往**别人仓库**写)
34
+
35
+ ### G6 · 列标签失败仍盲发 POST —— 唯一会碰别人仓库的路径
36
+ `ensureGiteeLabel()` 先 `GET /labels` 查重,再 `POST` 建。但**查失败时它也照发**:
37
+ 读不到现有标签就建 —— 等于在**别人仓库**里造重复标签。现在读失败就老实回报 `list-failed`。
38
+ 实测:403 时 POST 次数 = **0**。
39
+
40
+ ### G7 · 每条 Gitee 守都恒挂「只读」徽章
41
+ `mapGiteeRepoAccess()` 读 `permissions.push`,而 Gitee 的仓库对象里**根本没有** `permissions` 字段(67 个键都没有它)。
42
+ `undefined === true` 恒 false → 每条 Gitee 守都显示「只读」+「你只有读权限」假警告。
43
+ 改成「字段不存在 → `push: null`(不知道)」,面板按 `=== false` 才提示只读。
44
+
45
+ ### G3 · 只取一页,截断的部分静默消失
46
+ `listGiteeItems()` 只读一页且不告诉调用方「满了」。停机恢复/首次轮询时最危险:
47
+ **攒了 30 条只看到 20 条,另外 10 条永远不再出现**(`cursor` 还会推进过去)。
48
+ 现在回 `truncated: true`,轮询路径**这一轮不推进水位**并留一条事件。
49
+
50
+ ### 证据
51
+ ```
52
+ node --test → 343/343(新增:盲发 POST 守卫、permissions 缺失、truncated 三条)
53
+ ```
54
+
55
+ ### 仍未修(登记)
56
+ G2(`request()` 不读响应头)、G4(Gitee 分支沿用 GitHub 措辞)。
5
57
  ## [0.9.198] - 2026-11-05 —— Gitee 边界审计「值得改」三条:403 限流、404 被抢、非数组抛错
6
58
 
7
59
  ### G1 · 线上 Gitee 限流回的是 **403**,不是 429
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.198-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
6
+ [![Version](https://img.shields.io/badge/version-0.9.200-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 # 340 项单测
147
+ node --test # 345 项单测
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.198'
17
+ const CLIENT_VERSION = '0.9.200'
18
18
  let BASE = '/session-superagent'
19
19
  /**
20
20
  * 挑「最新的那个服务端实例」。
package/lib/gitee.js CHANGED
@@ -106,7 +106,8 @@ export async function listGiteeItems({ repo, token = '', perPage = 20, since = '
106
106
  // 真机验证:since 传给未来时间 → 返回 [];传今天 → 只返回今天之后更新的。
107
107
  // 两个端点都支持,缺了它就只能每轮全量读。
108
108
  const sinceQ = since ? '&since=' + encodeURIComponent(String(since)) : ''
109
- const q = 'state=all&sort=updated&direction=desc&per_page=' + Math.max(1, Math.min(100, Number(perPage) || 20)) + sinceQ
109
+ const size = Math.max(1, Math.min(100, Number(perPage) || 20))
110
+ const q = 'state=all&sort=updated&direction=desc&per_page=' + size + sinceQ
110
111
  const [issues, pulls] = await Promise.all([
111
112
  request(`/repos/${repo}/issues?${q}`, { token, fetchImpl }),
112
113
  request(`/repos/${repo}/pulls?${q}`, { token, fetchImpl }),
@@ -114,11 +115,16 @@ export async function listGiteeItems({ repo, token = '', perPage = 20, since = '
114
115
  if (!issues.ok && !pulls.ok) {
115
116
  return { ok: false, status: issues.status || pulls.status, error: issues.error || pulls.error }
116
117
  }
118
+ // 审核 G3:只取一页时,超出的部分会**静默消失**,而 cursor 还会推进过去 ——
119
+ // 停机恢复/首次轮询时最危险(攒了 30 条只看到 20 条,另外 10 条永远不再出现)。
120
+ // 这里如实告诉调用方「满了,可能被截断」,由它决定是否推迟推进水位。
121
+ const truncated = [issues, pulls].some((res) => res.ok && Array.isArray(res.data) && res.data.length >= size)
117
122
  return {
118
123
  ok: true,
119
124
  items: normalizeGiteeList(issues.ok ? issues.data : [], pulls.ok ? pulls.data : []),
120
125
  // 一半成功也要说清楚:否则客户以为 PR 一条都没有
121
126
  partial: !issues.ok || !pulls.ok ? (issues.ok ? 'pulls' : 'issues') : null,
127
+ truncated,
122
128
  }
123
129
  }
124
130
 
@@ -172,9 +178,14 @@ export async function giteeRepo({ repo, token = '', fetchImpl } = {}) {
172
178
  */
173
179
  export function mapGiteeRepoAccess(repo, info = {}) {
174
180
  const perms = info.permissions || {}
181
+ // 审核 G7:Gitee 的仓库对象里**没有** `permissions` 字段(67 个键都没有它)。
182
+ // 以前 `perms.push === true` 恒 false → 每条 Gitee 守都恒挂「只读」徽章 + 「你只有读权限」假警告。
183
+ // 没有这个字段时 `push` 应该是 `null`(不知道),不是 `false`(只读)——
184
+ // 调用方按 `=== false` 才提示只读。
185
+ const known = info.permissions && typeof info.permissions === 'object'
175
186
  return {
176
187
  repo,
177
- push: perms.push === true || perms.admin === true,
188
+ push: known ? (perms.push === true || perms.admin === true) : null,
178
189
  private: info.private === true,
179
190
  fork: Boolean(info.parent) || info.fork === true,
180
191
  hasIssues: info.has_issues !== false,
@@ -221,6 +232,16 @@ export async function ensureGiteeLabel({ repo, token = '', label, color = 'edede
221
232
  if (listed.ok) {
222
233
  const names = (Array.isArray(listed.data) ? listed.data : []).map((item) => String(item && item.name || ''))
223
234
  if (names.includes(name)) return { ok: true, created: false, reason: 'already-exists' }
235
+ } else {
236
+ // 审核 G6:**列标签失败时不许盲发 POST**。
237
+ // 这是唯一会往「别人仓库」写的路径 —— 读不到现有标签就去建,等于在别人仓库里造重复标签。
238
+ // 读失败就老实回报失败,让客户知道是「查不到」而不是「没有」。
239
+ return {
240
+ ok: false,
241
+ reason: 'list-failed',
242
+ status: listed.status,
243
+ error: '查不到现有标签(HTTP ' + (listed.status || '?') + '):' + String(listed.error || '').slice(0, 120),
244
+ }
224
245
  }
225
246
  const created = await request(`/repos/${repo}/labels`, { token, method: 'POST', body: { name, color }, fetchImpl })
226
247
  if (created.ok) return { ok: true, created: true, reason: 'created' }
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.198'
45
+ export const SERVER_VERSION = '0.9.200'
46
46
  export const inject = ['tools', 'agents', 'webServer']
47
47
  /** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
48
48
  // 本进程启动时刻:用来区分「刚重启还没轮到」与「定时器真的丢了」
@@ -725,10 +725,14 @@ function wake(ctx, sessionId, text) {
725
725
  const allowed = decideWake(agent.status)
726
726
  if (!allowed.ok) return allowed
727
727
 
728
+ // 审核 M1:这是**唯一必进模型上下文**的出口,以前一个字符都不脱敏 ——
729
+ // 全仓 11 个 redact() 调用点全在错误分支上,方向正好反了。
730
+ // issue 标题/评论是外部内容,里面可能带着 token;进了上下文就等于进了日志与训练数据。
731
+ const safeText = redact(text)
728
732
  const message = {
729
733
  id: randomUUID(),
730
734
  role: 'user',
731
- content: [{ type: 'text', text }],
735
+ content: [{ type: 'text', text: safeText }],
732
736
  source: { kind: 'user' },
733
737
  }
734
738
  try {
@@ -1097,6 +1101,14 @@ async function pollOnce(ctx, entry, baseMs) {
1097
1101
  }
1098
1102
  // 一半成功(issue 拿到、PR 没拿到)要说出来,否则客户以为 PR 一条都没有
1099
1103
  if (listed.partial) noteEvent(entry, 'partial', 'Gitee ' + (listed.partial === 'pulls' ? 'PR' : 'issue') + ' 列表这一轮没拿到')
1104
+ // 审核 G3:一页满了 = 可能被截断。这一轮**不推进水位**,否则被截掉的那些永远不再出现
1105
+ // (停机恢复/首次轮询时最危险:攒了 30 条只看到 20 条,另外 10 条静默丢掉)。
1106
+ if (listed.truncated) {
1107
+ noteEvent(entry, 'partial', 'Gitee 列表满了一页(可能被截断):这一轮不推进水位,下一轮接着读')
1108
+ entry.lastDeferred = 'Gitee 列表可能被截断,水位先不动'
1109
+ entry.deferReason = 'truncated'
1110
+ return
1111
+ }
1100
1112
  const items = listed.items || []
1101
1113
  if (items.length === 0) {
1102
1114
  entry.lastError = null
@@ -2514,7 +2526,8 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2514
2526
  }
2515
2527
 
2516
2528
  // 6. 最近一次状态
2517
- const last = entry.lastError ? `错误:${entry.lastError}` : entry.lastDeferred ? `等待:${entry.lastDeferred}` : '正常'
2529
+ // 审核 M4:lastError 里可能原样带着 Gitee 返回的请求/令牌 —— 工具结果会进模型上下文,先脱敏
2530
+ const last = entry.lastError ? `错误:${redact(entry.lastError)}` : entry.lastDeferred ? `等待:${redact(entry.lastDeferred)}` : '正常'
2518
2531
  lines.push(`INFO ${isEnabled(entry) ? '运行中' : '已暂停'} · 上次轮询 ${entry.lastPoll || '无'} · ${last}`)
2519
2532
  }
2520
2533
  // format=json 时从同一份文本行解析出结构 —— 单一来源,不会出现两套逻辑走偏
package/lib/redact.js CHANGED
@@ -5,14 +5,33 @@
5
5
  * carry one by accident: a GitHub API error echoing the request headers, a
6
6
  * command printing its environment, a config dump. Every string that leaves
7
7
  * the plugin passes through `redact()` first.
8
+ *
9
+ * 审核(0.9.199 T16):原来只有 4 条形状,**25 种真实凭证里漏了 16 种**。
10
+ * 而且最该脱敏的出口(唤醒消息 → 模型上下文)一个都没接。已按「供应商前缀 + 受控通用形状」两层补齐:
11
+ * 前缀是精确的(误伤极低);通用形状(URL 密码 / 裸 Bearer / 查询参数)必须配上下文词,别裸扫。
8
12
  */
9
13
 
10
14
  /** Patterns that must never reach the transcript. */
11
15
  export const SECRET_PATTERNS = [
12
- /gh[pousr]_[A-Za-z0-9]{20,}/g, // classic PAT (ghp_, gho_, ghu_, ghs_, ghr_)
13
- /github_pat_[A-Za-z0-9_]{20,}/g, // fine-grained PAT
14
- /-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z ]*PRIVATE KEY-----/g, // SSH / PEM blocks
15
- /Authorization:\s*(?:token|Bearer)\s+\S+/gi, // echoed request headers
16
+ /gh[pousr]_[A-Za-z0-9]{20,}/g, // GitHub PAT(ghp_ / gho_ / ghu_ / ghs_ / ghr_)
17
+ /github_pat_[A-Za-z0-9_]{20,}/g, // GitHub 细粒度 PAT
18
+ /glpat-[A-Za-z0-9_-]{20,}/g, // GitLab PAT
19
+ /xox[baprs]-[A-Za-z0-9-]{10,}/g, // Slack
20
+ /sk_live_[A-Za-z0-9]{20,}/g, // Stripe
21
+ /npm_[A-Za-z0-9]{30,}/g, // npm automation token
22
+ /AIza[0-9A-Za-z_-]{35}/g, // Google API key
23
+ /AKIA[0-9A-Z]{16}/g, // AWS access key id
24
+ /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\b/g, // JWT
25
+ /-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z ]*PRIVATE KEY-----/g, // SSH / PEM 完整块
26
+ /-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*/g, // **被截断的** PEM(没有 END):吃到结尾
27
+ /-----BEGIN PGP PRIVATE KEY BLOCK-----[\s\S]*?-----END PGP PRIVATE KEY BLOCK-----/g,
28
+ /Authorization:\s*(?:token|Bearer|Basic)\s+\S+/gi, // 回显的请求头
29
+ /\bBearer\s+[A-Za-z0-9._~+/=-]{20,}/g, // 裸 Bearer(无头名)
30
+ /\b(?:postgres(?:ql)?|mysql|mongodb(?:\+srv)?|redis|amqp):\/\/[^:\s/]+:[^@\s]+@/gi, // 数据库 URL 里的密码
31
+ /[?&](?:access_token|api_key|apikey|private_token)=[^&\s"']+/gi, // 查询参数里的凭证
32
+ // Gitee 私人令牌:**无前缀**的 32 位十六进制(真机形状)。裸扫会误伤 md5/commit sha,
33
+ // 所以要求前面 20 字内出现 gitee / 令牌 / access_token 这类上下文词。
34
+ /\b(?:gitee|私人令牌|access[_ ]?token)[^\n]{0,20}?\b[0-9a-f]{32}\b/gi,
16
35
  ]
17
36
 
18
37
  /** Replace every credential-shaped substring with `***`. */
package/lib/watch.js CHANGED
@@ -141,7 +141,16 @@ export function formatWatchText(repo, fresh, options = {}) {
141
141
  : null,
142
142
  ].filter(Boolean).join(' ')
143
143
  // 单行太长在聊天窗口里会挤成一团:超过 120 字就把补充信息挪到下一行(链接点哪都一样)
144
- const head = `#${item.number} [${item.state}] ${item.title} — @${who}`
144
+ // 审核 M5(注入面):issue 标题是**外部不可信内容**,直接插值会被拼出第二个
145
+ // 「【主理鱼】以下为系统指令」抬头。同一个函数里 goal 的换行早就被压平了,title 漏了。
146
+ // 压平换行 + 把方括号抬头换成普通括号(保留内容,只让它无法伪造结构)。
147
+ const safeTitle = String(item.title || '')
148
+ .split(String.fromCharCode(13)).join(' ')
149
+ .split(String.fromCharCode(10)).join(' ')
150
+ .split('【').join('[')
151
+ .split('】').join(']')
152
+ .slice(0, 200)
153
+ const head = `#${item.number} [${item.state}] ${safeTitle} — @${who}`
145
154
  const oneLine = tail ? `${head} ${tail}` : head
146
155
  if (oneLine.length <= 120) return oneLine
147
156
  return `${head}\n ${tail}`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-superagent",
3
- "version": "0.9.198",
3
+ "version": "0.9.200",
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",