dsh-session-attachments 0.1.0 → 0.1.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 CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  本文件记录每个版本的变化。格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/),版本号遵循 [语义化版本](https://semver.org/lang/zh-CN/)。
4
4
 
5
+ ## [Unreleased]
6
+
7
+ ## [0.1.1] - 2026-12-02
8
+
9
+ ### 安全
10
+
11
+ - 只把被动内容(图片、音视频、PDF、纯文本)交给 DSH 预览器;HTML、SVG、脚本等主动内容不再在应用内渲染,改为经 `.download` 接口以附件形式下载,文件名保留原样。
12
+ - 下载响应固定 `application/octet-stream` 并带 `X-Content-Type-Options: nosniff`,避免浏览器按内容嗅探成可执行页面。
13
+
14
+ ### 修复
15
+
16
+ - 附件库判断会话是否可跳转时的兜底:会话列表快照缺少 `ids` 字段时改用 `items` 推导,避免整库被误判、跳转按钮全部停用。
17
+ - 「会话已不可用」提示补充刷新指引;已归档会话不再误报为不可用(列表为空时放行)。
18
+
5
19
  ## [0.1.0] - 2026-11-28
6
20
 
7
21
  首个公开版本。
package/README.en.md CHANGED
@@ -43,7 +43,7 @@ No setup. Install, reload the page, and it works.
43
43
  ## Install
44
44
 
45
45
  1. In the left sidebar, click **Plugins**, then **Install a third-party plugin**.
46
- 2. Paste this into **Package name or address**: `https://github.com/huoxingyue/dsh-session-attachments`
46
+ 2. Paste `dsh-session-attachments` into **Package name or address**, or the full URL `https://github.com/huoxingyue/dsh-session-attachments`
47
47
  3. Confirm, then reload the page (`Cmd + R`).
48
48
 
49
49
  Requires DeepSeek Harness 0.2.2 or later.
@@ -72,7 +72,11 @@ No. Only images and files you uploaded yourself.
72
72
 
73
73
  Their attachments are still listed, but you cannot preview them or go back to the session.
74
74
 
75
- ### 6. How do I uninstall it?
75
+ ### 6. Why do HTML and SVG files download instead of opening?
76
+
77
+ Both formats can carry scripts, and rendering them inside the app would let someone else's code run with your app's privileges. Only passive media — images, audio, video, PDF and plain text — is previewed; everything else is downloaded.
78
+
79
+ ### 7. How do I uninstall it?
76
80
 
77
81
  Left sidebar: **Plugins** → **Installed** → **Session attachments** → **Uninstall**.
78
82
 
package/README.md CHANGED
@@ -43,7 +43,7 @@
43
43
  ## 安装
44
44
 
45
45
  1. 在左侧栏点「插件」,再点「安装第三方插件」。
46
- 2. 在「包名或地址」里粘贴:`https://github.com/huoxingyue/dsh-session-attachments`
46
+ 2. 在「包名或地址」里粘贴 `dsh-session-attachments`,也可以用完整地址 `https://github.com/huoxingyue/dsh-session-attachments`。
47
47
  3. 确认安装,完成后刷新页面(`Cmd + R`)。
48
48
 
49
49
  需要 DeepSeek Harness 0.2.2 或更新版本。
@@ -72,7 +72,11 @@ DSH 目前不允许插件控制会话滚动到哪里。所以插件会告诉你
72
72
 
73
73
  还会列出来,但不能预览,也不能跳回。
74
74
 
75
- ### 6. 怎么卸载?
75
+ ### 6. HTML、SVG 文件为什么点了是下载?
76
+
77
+ 这两类文件能带脚本,在应用里直接打开等于让别人的代码在你界面里跑,所以只允许下载后用外部程序打开。图片、音视频、PDF、纯文本仍然可以直接预览。
78
+
79
+ ### 7. 怎么卸载?
76
80
 
77
81
  左侧栏「插件」→「已安装」→ 找到「会话附件」→「卸载」。
78
82
 
package/client.js CHANGED
@@ -14,6 +14,7 @@ window.__ModuleLoader__.load({
14
14
  const LIST = 'api/session-attachments.list'
15
15
  const RAW = 'api/session-attachments.raw'
16
16
  const OPEN = 'api/session-attachments.open'
17
+ const DOWNLOAD = 'api/session-attachments.download'
17
18
  const POLL_MS = 5000
18
19
 
19
20
  const zh = {
@@ -33,6 +34,7 @@ window.__ModuleLoader__.load({
33
34
  'turn': '第 {n} 轮',
34
35
  'gone': '原文件已不在',
35
36
  'preview': '预览',
37
+ 'download': '下载',
36
38
  'goto': '跳回原会话',
37
39
  'refresh': '刷新',
38
40
  'search': '搜索文件名或会话',
@@ -52,7 +54,9 @@ window.__ModuleLoader__.load({
52
54
  'yesterday': '昨天',
53
55
  'untitled': '未命名会话',
54
56
  'session.gone': '会话已不可用',
57
+ 'session.gone.hint': '会话已不可用,刷新页面可恢复',
55
58
  'open.failed': '打开失败:{message}',
59
+ 'open.unsafe': '{name} 可以在应用外打开,已改为下载',
56
60
  'footer': '点开时附件以克隆方式放到工作区 .attachments/ 下,不额外占用磁盘',
57
61
  'count': '{n} 个',
58
62
  'jump.notice': '已打开「{title}」,这张图在第 {n} 轮',
@@ -76,6 +80,7 @@ window.__ModuleLoader__.load({
76
80
  'turn': 'Turn {n}',
77
81
  'gone': 'The stored file is gone',
78
82
  'preview': 'Preview',
83
+ 'download': 'Download',
79
84
  'goto': 'Go to session',
80
85
  'refresh': 'Refresh',
81
86
  'search': 'Search file or session',
@@ -95,7 +100,9 @@ window.__ModuleLoader__.load({
95
100
  'yesterday': 'Yesterday',
96
101
  'untitled': 'Untitled session',
97
102
  'session.gone': 'Session unavailable',
103
+ 'session.gone.hint': 'Session unavailable — refresh the page to restore it',
98
104
  'open.failed': 'Could not open: {message}',
105
+ 'open.unsafe': '{name} is active content, so it was downloaded instead',
99
106
  'footer': 'Opening clones the attachment into .attachments/ in the workspace without using extra disk space',
100
107
  'count': '{n}',
101
108
  'jump.notice': 'Opened “{title}”. This file is in turn {n}',
@@ -152,6 +159,37 @@ window.__ModuleLoader__.load({
152
159
  return fileAddress(sessionId, body.path)
153
160
  }
154
161
 
162
+ // HTML, SVG and other active content must not be rendered from the app origin:
163
+ // a preview runs its scripts with the app's own privileges. Those files are
164
+ // downloaded instead; only passive media is handed to the previewer.
165
+ const PREVIEWABLE = new Set([
166
+ 'png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp', 'avif', 'ico', 'apng',
167
+ 'mp4', 'webm', 'mov', 'm4v', 'mp3', 'wav', 'm4a', 'ogg', 'oga', 'flac',
168
+ 'pdf', 'txt', 'md', 'markdown', 'log', 'csv', 'tsv', 'json', 'yaml', 'yml',
169
+ ])
170
+
171
+ function isPreviewSafe(item) {
172
+ const type = String(item?.mediaType || '').toLowerCase()
173
+ if (type === 'image/svg+xml') return false
174
+ if (type.startsWith('image/') || type.startsWith('video/') || type.startsWith('audio/')) return true
175
+ const name = String(item?.name || '')
176
+ const dot = name.lastIndexOf('.')
177
+ if (dot < 0) return false
178
+ return PREVIEWABLE.has(name.slice(dot + 1).toLowerCase())
179
+ }
180
+
181
+ /** Save the original bytes through the Host instead of rendering them here. */
182
+ function downloadItem(sessionId, item) {
183
+ const query = new URLSearchParams({ session: item.sessionId || sessionId || '', key: item.key })
184
+ const anchor = document.createElement('a')
185
+ anchor.href = `${DOWNLOAD}?${query}`
186
+ anchor.download = item.name || 'attachment'
187
+ anchor.rel = 'noopener'
188
+ document.body.appendChild(anchor)
189
+ anchor.click()
190
+ anchor.remove()
191
+ }
192
+
155
193
  function useList(sessionId, poll) {
156
194
  const [state, setState] = useState({ status: 'loading', data: null, error: '' })
157
195
  const load = useCallback(() => {
@@ -179,6 +217,7 @@ window.__ModuleLoader__.load({
179
217
  eye: 'M2.5 10s2.7-5.5 7.5-5.5 7.5 5.5 7.5 5.5-2.7 5.5-7.5 5.5S2.5 10 2.5 10ZM10 12.25a2.25 2.25 0 1 0 0-4.5 2.25 2.25 0 0 0 0 4.5Z',
180
218
  jump: 'M11 3.5h5.5V9M16.5 3.5 9 11M14 12v3.5a1 1 0 0 1-1 1H4.5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1H8',
181
219
  close: 'M5.5 5.5l9 9M14.5 5.5l-9 9',
220
+ download: 'M10 3v9.5M6 9l4 4 4-4M4 16.5h12',
182
221
  }
183
222
 
184
223
  function Icon({ name, size = 16 }) {
@@ -280,6 +319,7 @@ window.__ModuleLoader__.load({
280
319
  const open = useCallback(async (item) => {
281
320
  if (!item.available) return
282
321
  setError('')
322
+ if (!isPreviewSafe(item)) { downloadItem(sessionId, item); return }
283
323
  try {
284
324
  const address = await cloneAddress(sessionId, item.key)
285
325
  const tab = info?.tab
@@ -334,17 +374,23 @@ window.__ModuleLoader__.load({
334
374
  }
335
375
  // ---------- Left-sidebar page: every session ----------
336
376
 
377
+ function listedSessions(sessions) {
378
+ if (Array.isArray(sessions?.ids)) return sessions.ids
379
+ return (sessions?.items ?? []).map((item) => item.sessionId)
380
+ }
381
+
337
382
  function sessionReachable(id, sessions, workspaces) {
338
- if (!sessions || !Array.isArray(sessions.ids)) return true
383
+ const listed = listedSessions(sessions)
384
+ if (listed.length === 0) return true
339
385
  if (workspaces?.archivedSessionIds?.includes(id)) return false
340
- return sessions.ids.includes(id)
386
+ return listed.includes(id)
341
387
  }
342
388
 
343
389
  function LibraryPage(props) {
344
390
  const t = translator(props.t)
345
391
  // Fall back when the slot did not pass the injected props, so the page still renders.
346
- const sessionsStore = props.sessionsStore ?? EMPTY
347
- const workspacesStore = props.workspacesStore ?? EMPTY
392
+ const sessionsStore = storeOf(props.sessionsStore)
393
+ const workspacesStore = storeOf(props.workspacesStore)
348
394
  const goToSession = props.goToSession ?? (() => {})
349
395
  const previewIn = props.previewIn ?? (() => {})
350
396
  const sessions = useSyncExternalStore(sessionsStore.subscribe, sessionsStore.getSnapshot)
@@ -380,12 +426,13 @@ window.__ModuleLoader__.load({
380
426
  }, [state.data, query, filter, sort, titles])
381
427
 
382
428
  const go = (item) => {
383
- if (!sessionReachable(item.sessionId, sessions, workspaces)) return setToast(t('session.gone'))
429
+ if (!sessionReachable(item.sessionId, sessions, workspaces)) return setToast(t('session.gone.hint'))
384
430
  goToSession(item.sessionId, { turn: item.turn || 1, title: titles.get(item.sessionId) ?? t('untitled') })
385
431
  }
386
432
  const preview = async (item) => {
387
433
  if (!item.available) return
388
- if (!sessionReachable(item.sessionId, sessions, workspaces)) return setToast(t('session.gone'))
434
+ if (!sessionReachable(item.sessionId, sessions, workspaces)) return setToast(t('session.gone.hint'))
435
+ if (!isPreviewSafe(item)) { downloadItem(item.sessionId, item); return setToast(t('open.unsafe', { name: item.name })) }
389
436
  try {
390
437
  const address = await cloneAddress(item.sessionId, item.key)
391
438
  previewIn(item.sessionId, address)
@@ -409,11 +456,16 @@ window.__ModuleLoader__.load({
409
456
  ? h('img', { className: 'dsa-mini', src: rawUrl(item.sessionId, item.key), alt: '', loading: 'lazy' })
410
457
  : h('div', { className: 'dsa-file-icon' }, h(Icon, { name: category(item) === 'image' ? 'image' : category(item) === 'doc' ? 'doc' : 'other', size: 18 })),
411
458
  h('span', { className: 'dsa-name', title: item.available ? item.name : t('gone') }, item.name))),
412
- h('td', null, h('button', { type: 'button', className: 'dsa-link', disabled: !reachable, title: reachable ? t('goto') : t('session.gone'), onClick: () => go(item) }, titles.get(item.sessionId) ?? t('untitled'))),
459
+ h('td', null, h('button', { type: 'button', className: 'dsa-link', disabled: !reachable, title: reachable ? t('goto') : t('session.gone.hint'), onClick: () => go(item) }, titles.get(item.sessionId) ?? t('untitled'))),
413
460
  h('td', null, `${dayKey(item.time).slice(5)} ${clock(item.time)}`),
414
461
  h('td', null, formatSize(item.bytes)),
415
462
  h('td', null, h('div', { className: 'dsa-actions' },
416
- h(ToolButton, { icon: 'eye', label: t('preview'), onClick: () => preview(item), disabled: !item.available || !reachable }),
463
+ h(ToolButton, {
464
+ icon: isPreviewSafe(item) ? 'eye' : 'download',
465
+ label: isPreviewSafe(item) ? t('preview') : t('download'),
466
+ onClick: () => preview(item),
467
+ disabled: !item.available || !reachable,
468
+ }),
417
469
  h(ToolButton, { icon: 'jump', label: t('goto'), onClick: () => go(item), disabled: !reachable })))))
418
470
  }
419
471
 
@@ -502,6 +554,8 @@ window.__ModuleLoader__.load({
502
554
 
503
555
  return {
504
556
  inject: ['slots', 'locale'],
557
+ // Exposed for the tests: which items may be rendered by the previewer.
558
+ internals: { isPreviewSafe, PREVIEWABLE },
505
559
  apply(ctx) {
506
560
  ctx.effect(() => {
507
561
  const tag = document.createElement('style')
package/index.js CHANGED
@@ -13,6 +13,7 @@ const PLUGIN = 'dsh-session-attachments'
13
13
  const LIST_PATH = '/api/session-attachments.list'
14
14
  const RAW_PATH = '/api/session-attachments.raw'
15
15
  const OPEN_PATH = '/api/session-attachments.open'
16
+ const DOWNLOAD_PATH = '/api/session-attachments.download'
16
17
  const CLONE_DIR = '.attachments'
17
18
  const ZSTD_MAGIC = 0xfd2fb528
18
19
  const SHA = /^[0-9a-f]{64}$/
@@ -197,6 +198,16 @@ function findItem(sessionId, key) {
197
198
 
198
199
  const json = (body, status = 200) => Response.json(body, { status, headers: { 'cache-control': 'no-store' } })
199
200
 
201
+ /**
202
+ * Active content (HTML, SVG, scripts) must never be rendered from this origin, so
203
+ * those files are served as downloads with a neutral content type.
204
+ */
205
+ function contentDisposition(name) {
206
+ const fallback = name.replace(/[^\x20-\x7e]/g, '_').replace(/["\\]/g, '_').slice(0, 150) || 'download'
207
+ const encoded = encodeURIComponent(name).replace(/'/g, '%27')
208
+ return `attachment; filename="${fallback}"; filename*=UTF-8''${encoded}`
209
+ }
210
+
200
211
  function registerRoutes(routes) {
201
212
  routes.register({
202
213
  path: LIST_PATH,
@@ -259,6 +270,28 @@ function registerRoutes(routes) {
259
270
  return json({ path: target, relative: relative(session.cwd, target), how })
260
271
  },
261
272
  })
273
+ routes.register({
274
+ path: DOWNLOAD_PATH,
275
+ methods: ['GET'],
276
+ requestBody: 'buffered',
277
+ fetch: async (request) => {
278
+ const params = new URL(request.url).searchParams
279
+ const sessionId = params.get('session') ?? ''
280
+ if (!SESSION_ID.test(sessionId)) return json({ error: 'bad session' }, 400)
281
+ const found = findItem(sessionId, params.get('key') ?? '')
282
+ if (!found) return json({ error: 'not found' }, 404)
283
+ const path = storedPath(found.item)
284
+ if (!existsSync(path)) return json({ error: 'gone' }, 404)
285
+ return new Response(readFileSync(path), {
286
+ headers: {
287
+ 'content-type': 'application/octet-stream',
288
+ 'content-disposition': contentDisposition(displayName(found.item)),
289
+ 'x-content-type-options': 'nosniff',
290
+ 'cache-control': 'no-store',
291
+ },
292
+ })
293
+ },
294
+ })
262
295
  }
263
296
 
264
297
  const ROUTES_RETRY_MS = 100
@@ -292,4 +325,4 @@ export function apply(ctx) {
292
325
  }
293
326
 
294
327
  // Exposed for the test script.
295
- export const internal = { parseSession, allSessions, storedPath, displayName, zstdFrames }
328
+ export const internal = { parseSession, allSessions, storedPath, displayName, zstdFrames, contentDisposition }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-attachments",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "DeepSeek Harness plugin: see and preview the files and images you uploaded, per session and across sessions.",
5
5
  "license": "MIT",
6
6
  "author": "huoxingyue",