@sleep2agi/agent-network-dashboard 0.6.3-preview.37 → 0.6.3-preview.39
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/.next/BUILD_COMMIT +1 -1
- package/.next/BUILD_ID +1 -1
- package/.next/build-manifest.json +3 -3
- package/.next/diagnostics/route-bundle-stats.json +14 -14
- package/.next/fallback-build-manifest.json +3 -3
- package/.next/server/app/_global-error.html +1 -1
- package/.next/server/app/_global-error.rsc +1 -1
- package/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/.next/server/app/_not-found.html +2 -2
- package/.next/server/app/_not-found.rsc +2 -2
- package/.next/server/app/_not-found.segments/_full.segment.rsc +2 -2
- package/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_index.segment.rsc +2 -2
- package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
- package/.next/server/app/admin/page_client-reference-manifest.js +1 -1
- package/.next/server/app/admin.html +2 -2
- package/.next/server/app/admin.rsc +2 -2
- package/.next/server/app/admin.segments/_full.segment.rsc +2 -2
- package/.next/server/app/admin.segments/_head.segment.rsc +1 -1
- package/.next/server/app/admin.segments/_index.segment.rsc +2 -2
- package/.next/server/app/admin.segments/_tree.segment.rsc +2 -2
- package/.next/server/app/admin.segments/admin/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/admin.segments/admin.segment.rsc +1 -1
- package/.next/server/app/index.html +2 -2
- package/.next/server/app/index.rsc +3 -3
- package/.next/server/app/index.segments/__PAGE__.segment.rsc +2 -2
- package/.next/server/app/index.segments/_full.segment.rsc +3 -3
- package/.next/server/app/index.segments/_head.segment.rsc +1 -1
- package/.next/server/app/index.segments/_index.segment.rsc +2 -2
- package/.next/server/app/index.segments/_tree.segment.rsc +2 -2
- package/.next/server/app/login/page_client-reference-manifest.js +1 -1
- package/.next/server/app/login.html +2 -2
- package/.next/server/app/login.rsc +3 -3
- package/.next/server/app/login.segments/_full.segment.rsc +3 -3
- package/.next/server/app/login.segments/_head.segment.rsc +1 -1
- package/.next/server/app/login.segments/_index.segment.rsc +2 -2
- package/.next/server/app/login.segments/_tree.segment.rsc +2 -2
- package/.next/server/app/login.segments/login/__PAGE__.segment.rsc +2 -2
- package/.next/server/app/login.segments/login.segment.rsc +1 -1
- package/.next/server/app/logs/page_client-reference-manifest.js +1 -1
- package/.next/server/app/logs.html +2 -2
- package/.next/server/app/logs.rsc +2 -2
- package/.next/server/app/logs.segments/_full.segment.rsc +2 -2
- package/.next/server/app/logs.segments/_head.segment.rsc +1 -1
- package/.next/server/app/logs.segments/_index.segment.rsc +2 -2
- package/.next/server/app/logs.segments/_tree.segment.rsc +2 -2
- package/.next/server/app/logs.segments/logs/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/logs.segments/logs.segment.rsc +1 -1
- package/.next/server/app/messages/page.js.nft.json +1 -1
- package/.next/server/app/messages/page_client-reference-manifest.js +1 -1
- package/.next/server/app/messages.html +2 -2
- package/.next/server/app/messages.rsc +3 -3
- package/.next/server/app/messages.segments/_full.segment.rsc +3 -3
- package/.next/server/app/messages.segments/_head.segment.rsc +1 -1
- package/.next/server/app/messages.segments/_index.segment.rsc +2 -2
- package/.next/server/app/messages.segments/_tree.segment.rsc +2 -2
- package/.next/server/app/messages.segments/messages/__PAGE__.segment.rsc +2 -2
- package/.next/server/app/messages.segments/messages.segment.rsc +1 -1
- package/.next/server/app/node/page.js.nft.json +1 -1
- package/.next/server/app/node/page_client-reference-manifest.js +1 -1
- package/.next/server/app/node.html +2 -2
- package/.next/server/app/node.rsc +3 -3
- package/.next/server/app/node.segments/_full.segment.rsc +3 -3
- package/.next/server/app/node.segments/_head.segment.rsc +1 -1
- package/.next/server/app/node.segments/_index.segment.rsc +2 -2
- package/.next/server/app/node.segments/_tree.segment.rsc +2 -2
- package/.next/server/app/node.segments/node/__PAGE__.segment.rsc +2 -2
- package/.next/server/app/node.segments/node.segment.rsc +1 -1
- package/.next/server/app/nodes/page.js.nft.json +1 -1
- package/.next/server/app/nodes/page_client-reference-manifest.js +1 -1
- package/.next/server/app/nodes.html +2 -2
- package/.next/server/app/nodes.rsc +3 -3
- package/.next/server/app/nodes.segments/_full.segment.rsc +3 -3
- package/.next/server/app/nodes.segments/_head.segment.rsc +1 -1
- package/.next/server/app/nodes.segments/_index.segment.rsc +2 -2
- package/.next/server/app/nodes.segments/_tree.segment.rsc +2 -2
- package/.next/server/app/nodes.segments/nodes/__PAGE__.segment.rsc +2 -2
- package/.next/server/app/nodes.segments/nodes.segment.rsc +1 -1
- package/.next/server/app/page.js.nft.json +1 -1
- package/.next/server/app/page_client-reference-manifest.js +1 -1
- package/.next/server/app/providers/page_client-reference-manifest.js +1 -1
- package/.next/server/app/providers.html +2 -2
- package/.next/server/app/providers.rsc +2 -2
- package/.next/server/app/providers.segments/_full.segment.rsc +2 -2
- package/.next/server/app/providers.segments/_head.segment.rsc +1 -1
- package/.next/server/app/providers.segments/_index.segment.rsc +2 -2
- package/.next/server/app/providers.segments/_tree.segment.rsc +2 -2
- package/.next/server/app/providers.segments/providers/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/providers.segments/providers.segment.rsc +1 -1
- package/.next/server/app/server-logs/page_client-reference-manifest.js +1 -1
- package/.next/server/app/server-logs.html +2 -2
- package/.next/server/app/server-logs.rsc +2 -2
- package/.next/server/app/server-logs.segments/_full.segment.rsc +2 -2
- package/.next/server/app/server-logs.segments/_head.segment.rsc +1 -1
- package/.next/server/app/server-logs.segments/_index.segment.rsc +2 -2
- package/.next/server/app/server-logs.segments/_tree.segment.rsc +2 -2
- package/.next/server/app/server-logs.segments/server-logs/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/server-logs.segments/server-logs.segment.rsc +1 -1
- package/.next/server/app/servers/page_client-reference-manifest.js +1 -1
- package/.next/server/app/servers.html +2 -2
- package/.next/server/app/servers.rsc +2 -2
- package/.next/server/app/servers.segments/_full.segment.rsc +2 -2
- package/.next/server/app/servers.segments/_head.segment.rsc +1 -1
- package/.next/server/app/servers.segments/_index.segment.rsc +2 -2
- package/.next/server/app/servers.segments/_tree.segment.rsc +2 -2
- package/.next/server/app/servers.segments/servers/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/servers.segments/servers.segment.rsc +1 -1
- package/.next/server/app/settings/networks/page_client-reference-manifest.js +1 -1
- package/.next/server/app/settings/networks.html +2 -2
- package/.next/server/app/settings/networks.rsc +2 -2
- package/.next/server/app/settings/networks.segments/_full.segment.rsc +2 -2
- package/.next/server/app/settings/networks.segments/_head.segment.rsc +1 -1
- package/.next/server/app/settings/networks.segments/_index.segment.rsc +2 -2
- package/.next/server/app/settings/networks.segments/_tree.segment.rsc +2 -2
- package/.next/server/app/settings/networks.segments/settings/networks/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/settings/networks.segments/settings/networks.segment.rsc +1 -1
- package/.next/server/app/settings/networks.segments/settings.segment.rsc +1 -1
- package/.next/server/app/settings/page_client-reference-manifest.js +1 -1
- package/.next/server/app/settings/tokens/page_client-reference-manifest.js +1 -1
- package/.next/server/app/settings/tokens.html +2 -2
- package/.next/server/app/settings/tokens.rsc +2 -2
- package/.next/server/app/settings/tokens.segments/_full.segment.rsc +2 -2
- package/.next/server/app/settings/tokens.segments/_head.segment.rsc +1 -1
- package/.next/server/app/settings/tokens.segments/_index.segment.rsc +2 -2
- package/.next/server/app/settings/tokens.segments/_tree.segment.rsc +2 -2
- package/.next/server/app/settings/tokens.segments/settings/tokens/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/settings/tokens.segments/settings/tokens.segment.rsc +1 -1
- package/.next/server/app/settings/tokens.segments/settings.segment.rsc +1 -1
- package/.next/server/app/settings.html +2 -2
- package/.next/server/app/settings.rsc +3 -3
- package/.next/server/app/settings.segments/_full.segment.rsc +3 -3
- package/.next/server/app/settings.segments/_head.segment.rsc +1 -1
- package/.next/server/app/settings.segments/_index.segment.rsc +2 -2
- package/.next/server/app/settings.segments/_tree.segment.rsc +2 -2
- package/.next/server/app/settings.segments/settings/__PAGE__.segment.rsc +2 -2
- package/.next/server/app/settings.segments/settings.segment.rsc +1 -1
- package/.next/server/app/tasks/[id]/page_client-reference-manifest.js +1 -1
- package/.next/server/app/tasks/page_client-reference-manifest.js +1 -1
- package/.next/server/app/tasks.html +2 -2
- package/.next/server/app/tasks.rsc +2 -2
- package/.next/server/app/tasks.segments/_full.segment.rsc +2 -2
- package/.next/server/app/tasks.segments/_head.segment.rsc +1 -1
- package/.next/server/app/tasks.segments/_index.segment.rsc +2 -2
- package/.next/server/app/tasks.segments/_tree.segment.rsc +2 -2
- package/.next/server/app/tasks.segments/tasks/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/tasks.segments/tasks.segment.rsc +1 -1
- package/.next/server/chunks/[root-of-the-server]__0nhjt1j._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__0nhjt1j._.js.map +1 -1
- package/.next/server/chunks/ssr/0s9s_fef0eb55-b39c-4abc-b7ff-48440b9ad805_scratchpad_dashrel_app_01~-ebd._.js +3 -0
- package/.next/server/chunks/ssr/0s9s_fef0eb55-b39c-4abc-b7ff-48440b9ad805_scratchpad_dashrel_app_01~-ebd._.js.map +1 -0
- package/.next/server/chunks/ssr/{0s9s_fef0eb55-b39c-4abc-b7ff-48440b9ad805_scratchpad_dashrel_app_0~af09u._.js → 0s9s_fef0eb55-b39c-4abc-b7ff-48440b9ad805_scratchpad_dashrel_app_0ei5728._.js} +2 -2
- package/.next/server/chunks/ssr/0s9s_fef0eb55-b39c-4abc-b7ff-48440b9ad805_scratchpad_dashrel_app_0ei5728._.js.map +1 -0
- package/.next/server/chunks/ssr/0s9s_fef0eb55-b39c-4abc-b7ff-48440b9ad805_scratchpad_dashrel_app_0lzn~cs._.js +3 -0
- package/.next/server/chunks/ssr/0s9s_fef0eb55-b39c-4abc-b7ff-48440b9ad805_scratchpad_dashrel_app_0lzn~cs._.js.map +1 -0
- package/.next/server/chunks/ssr/0s9s_fef0eb55-b39c-4abc-b7ff-48440b9ad805_scratchpad_dashrel_app_0mek_e~._.js +1 -1
- package/.next/server/chunks/ssr/0s9s_fef0eb55-b39c-4abc-b7ff-48440b9ad805_scratchpad_dashrel_app_0mek_e~._.js.map +1 -1
- package/.next/server/chunks/ssr/0s9s_fef0eb55-b39c-4abc-b7ff-48440b9ad805_scratchpad_dashrel_app_0wz8z_e._.js +3 -0
- package/.next/server/chunks/ssr/0s9s_fef0eb55-b39c-4abc-b7ff-48440b9ad805_scratchpad_dashrel_app_0wz8z_e._.js.map +1 -0
- package/.next/server/chunks/ssr/0s9s_fef0eb55-b39c-4abc-b7ff-48440b9ad805_scratchpad_dashrel_app_0~ejwde._.js +1 -1
- package/.next/server/chunks/ssr/0s9s_fef0eb55-b39c-4abc-b7ff-48440b9ad805_scratchpad_dashrel_app_0~ejwde._.js.map +1 -1
- package/.next/server/chunks/ssr/[root-of-the-server]__04fj5h4._.js +3 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__04fj5h4._.js.map +1 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__05plnr_._.js +3 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__05plnr_._.js.map +1 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__0l~vdgn._.js +3 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__0l~vdgn._.js.map +1 -0
- package/.next/server/middleware-build-manifest.js +3 -3
- package/.next/server/pages/404.html +2 -2
- package/.next/server/pages/500.html +1 -1
- package/.next/static/chunks/{0a~ml7_0i0z70.js → 0.o~6-f11_j6i.js} +1 -1
- package/.next/static/chunks/{0.wmcjkg_pule.js → 01cd3uiuzejbt.js} +1 -1
- package/.next/static/chunks/{17xziuvljtbgu.js → 04y_am25nk4g..js} +2 -2
- package/.next/static/chunks/04~ypes~t4khh.js +1 -0
- package/.next/static/chunks/0p~997s2myymh.js +1 -0
- package/.next/static/chunks/0xy6sa.x2zvar.css +1 -0
- package/.next/static/chunks/{05q4-tajm2ro0.js → 14xnrhzhmv37o.js} +2 -2
- package/.next/trace +2 -2
- package/.next/trace-build +1 -1
- package/app/api/hub/files/[fileId]/route.ts +147 -14
- package/app/components/AttachmentBlock.tsx +316 -19
- package/package.json +1 -1
- package/tests/e2e-492-inline-preview/verify-summary.md +41 -0
- package/tests/e2e-492-inline-preview/verify.sh +227 -0
- package/.next/server/chunks/ssr/0s9s_fef0eb55-b39c-4abc-b7ff-48440b9ad805_scratchpad_dashrel_app_0~af09u._.js.map +0 -1
- package/.next/server/chunks/ssr/[root-of-the-server]__00kmdl9._.js +0 -3
- package/.next/server/chunks/ssr/[root-of-the-server]__00kmdl9._.js.map +0 -1
- package/.next/server/chunks/ssr/[root-of-the-server]__0lazm_f._.js +0 -3
- package/.next/server/chunks/ssr/[root-of-the-server]__0lazm_f._.js.map +0 -1
- package/.next/server/chunks/ssr/[root-of-the-server]__0na-tid._.js +0 -3
- package/.next/server/chunks/ssr/[root-of-the-server]__0na-tid._.js.map +0 -1
- package/.next/static/chunks/0hz543f47.wfq.js +0 -1
- package/.next/static/chunks/13yysku~0ccjx.css +0 -1
- package/.next/static/chunks/16ix0.lg2.ee1.js +0 -1
- /package/.next/static/{DfxWRgilFHyub5iovIeiq → FHSqMAj0yD_AXCKEYrGTW}/_buildManifest.js +0 -0
- /package/.next/static/{DfxWRgilFHyub5iovIeiq → FHSqMAj0yD_AXCKEYrGTW}/_clientMiddlewareManifest.js +0 -0
- /package/.next/static/{DfxWRgilFHyub5iovIeiq → FHSqMAj0yD_AXCKEYrGTW}/_ssgManifest.js +0 -0
|
@@ -13,19 +13,111 @@ const FILE_ID_REGEX = /^[A-Za-z0-9_-]{8,64}$/;
|
|
|
13
13
|
* Header allowlist for the pass-through. We deliberately do NOT forward
|
|
14
14
|
* everything from the hub response — the browser must NOT see anything
|
|
15
15
|
* that could leak the internal request path or the Bearer token.
|
|
16
|
-
*
|
|
16
|
+
*
|
|
17
|
+
* `content-disposition` and `x-content-type-options` are intentionally
|
|
18
|
+
* NOT in this list — they're stamped explicitly below (see JSDoc on
|
|
19
|
+
* the response builder). Passing them through the allowlist would
|
|
20
|
+
* silently defer to hub for the security-critical values, which is
|
|
21
|
+
* exactly the regression path 通信龙 flagged in the #47 review.
|
|
17
22
|
*/
|
|
18
23
|
const HEADER_PASSTHROUGH = [
|
|
19
24
|
'content-type',
|
|
20
25
|
'content-length',
|
|
21
|
-
'content-disposition',
|
|
22
|
-
'x-content-type-options',
|
|
23
26
|
] as const;
|
|
24
27
|
|
|
28
|
+
// ── #492 preview half: safe-inline-type detection ──────────────
|
|
29
|
+
//
|
|
30
|
+
// 🔴 STRUCTURAL SAFETY (通信龙 #46 review of the inline design):
|
|
31
|
+
// This proxy NEVER returns an inline response, regardless of the
|
|
32
|
+
// file's real type. `Content-Disposition: attachment` + `nosniff`
|
|
33
|
+
// stay stamped on every download, so no dashboard-origin URL can
|
|
34
|
+
// ever serve user-uploaded content as a rendered page — that entire
|
|
35
|
+
// XSS class is structurally impossible, not defended-by-whitelist.
|
|
36
|
+
//
|
|
37
|
+
// What we DO expose: a `X-Verified-Type` header carrying the true MIME
|
|
38
|
+
// as detected by magic bytes. The client uses this header to decide:
|
|
39
|
+
// 1. Fetch the bytes (browser downloads — no navigation)
|
|
40
|
+
// 2. `new Blob([bytes], {type: xVerifiedType})`
|
|
41
|
+
// 3. `URL.createObjectURL(blob)` → `<img>` / `<video>` src
|
|
42
|
+
//
|
|
43
|
+
// The blob URL is same-origin *to the browser's blob: scheme*, isolated
|
|
44
|
+
// from the dashboard origin — a bug in whitelist can degrade UX (image
|
|
45
|
+
// won't render) but can never become a cross-origin script vector.
|
|
46
|
+
//
|
|
47
|
+
// Detection rule: EXACT MIME match by per-format magic bytes at each
|
|
48
|
+
// format's actual offset. No prefix matching (`image/*` would let SVG
|
|
49
|
+
// in). No trust of upload-time mime/filename (both untrusted).
|
|
50
|
+
type SafeMime =
|
|
51
|
+
| 'image/png'
|
|
52
|
+
| 'image/jpeg'
|
|
53
|
+
| 'image/gif'
|
|
54
|
+
| 'image/webp'
|
|
55
|
+
| 'video/mp4'
|
|
56
|
+
| 'video/webm';
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Peek magic bytes and return the safe MIME if the file matches one
|
|
60
|
+
* of our whitelisted formats.
|
|
61
|
+
*
|
|
62
|
+
* Per-format offset rules (not naive first-N compare — 通信龙 review):
|
|
63
|
+
* - PNG: offset 0, `89 50 4E 47 0D 0A 1A 0A`
|
|
64
|
+
* - JPEG: offset 0, `FF D8 FF`
|
|
65
|
+
* - GIF: offset 0, `47 49 46 38 (37|39) 61` ("GIF87a" / "GIF89a")
|
|
66
|
+
* - WebP: offset 0 `52 49 46 46` ("RIFF") + offset 8 `57 45 42 50` ("WEBP")
|
|
67
|
+
* - MP4: offset 4 `66 74 79 70` ("ftyp") — MP4/M4V/QT ISO BMFF box
|
|
68
|
+
* - WebM: offset 0 `1A 45 DF A3` (EBML)
|
|
69
|
+
*
|
|
70
|
+
* Returns null for anything else (SVG, HTML, empty, corrupted, unknown).
|
|
71
|
+
*/
|
|
72
|
+
function detectSafeMime(head: Uint8Array): SafeMime | null {
|
|
73
|
+
const b = head;
|
|
74
|
+
if (b.length < 4) return null;
|
|
75
|
+
|
|
76
|
+
// PNG
|
|
77
|
+
if (
|
|
78
|
+
b.length >= 8 &&
|
|
79
|
+
b[0] === 0x89 && b[1] === 0x50 && b[2] === 0x4E && b[3] === 0x47 &&
|
|
80
|
+
b[4] === 0x0D && b[5] === 0x0A && b[6] === 0x1A && b[7] === 0x0A
|
|
81
|
+
) return 'image/png';
|
|
82
|
+
|
|
83
|
+
// JPEG (FF D8 FF — final byte is FF E0 / FF E1 / FF DB variants; the FF prefix
|
|
84
|
+
// is enough to distinguish. Reject if not exactly the three-byte JPEG marker.)
|
|
85
|
+
if (b[0] === 0xFF && b[1] === 0xD8 && b[2] === 0xFF) return 'image/jpeg';
|
|
86
|
+
|
|
87
|
+
// GIF — "GIF87a" or "GIF89a"
|
|
88
|
+
if (
|
|
89
|
+
b.length >= 6 &&
|
|
90
|
+
b[0] === 0x47 && b[1] === 0x49 && b[2] === 0x46 && b[3] === 0x38 &&
|
|
91
|
+
(b[4] === 0x37 || b[4] === 0x39) && b[5] === 0x61
|
|
92
|
+
) return 'image/gif';
|
|
93
|
+
|
|
94
|
+
// WebP — "RIFF????WEBP"
|
|
95
|
+
if (
|
|
96
|
+
b.length >= 12 &&
|
|
97
|
+
b[0] === 0x52 && b[1] === 0x49 && b[2] === 0x46 && b[3] === 0x46 &&
|
|
98
|
+
b[8] === 0x57 && b[9] === 0x45 && b[10] === 0x42 && b[11] === 0x50
|
|
99
|
+
) return 'image/webp';
|
|
100
|
+
|
|
101
|
+
// WebM (EBML header) — 1A 45 DF A3
|
|
102
|
+
if (b[0] === 0x1A && b[1] === 0x45 && b[2] === 0xDF && b[3] === 0xA3) {
|
|
103
|
+
return 'video/webm';
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// MP4 (ISO BMFF `ftyp` box at offset 4) — the first 4 bytes are a
|
|
107
|
+
// big-endian box size we don't need to validate; the "ftyp" marker
|
|
108
|
+
// is what we key on.
|
|
109
|
+
if (
|
|
110
|
+
b.length >= 8 &&
|
|
111
|
+
b[4] === 0x66 && b[5] === 0x74 && b[6] === 0x79 && b[7] === 0x70
|
|
112
|
+
) return 'video/mp4';
|
|
113
|
+
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
|
|
25
117
|
/**
|
|
26
118
|
* #492 — file download proxy: browser fetches `/api/hub/files/<file_id>`,
|
|
27
119
|
* this proxy attaches the browser session's V3 user token as
|
|
28
|
-
* `Authorization: Bearer <utok>` and
|
|
120
|
+
* `Authorization: Bearer <utok>` and forwards the response.
|
|
29
121
|
*
|
|
30
122
|
* Why proxy vs direct-browser-fetch to `/api/files/<id>`:
|
|
31
123
|
*
|
|
@@ -40,18 +132,25 @@ const HEADER_PASSTHROUGH = [
|
|
|
40
132
|
* - By proxying, the token stays server-side. The client sends
|
|
41
133
|
* nothing but its own session cookie; the server adds the Bearer.
|
|
42
134
|
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* concurrent
|
|
48
|
-
*
|
|
135
|
+
* Buffering vs streaming: this half of the proxy USED to stream (O(1)
|
|
136
|
+
* memory). The preview half needs to detect magic bytes before
|
|
137
|
+
* headers can be sent, so we now buffer the full body. Acceptable
|
|
138
|
+
* because hub caps uploads at 12 MiB; worst case is 12 MiB *
|
|
139
|
+
* concurrent-preview-requests per node process. If that becomes
|
|
140
|
+
* memory pressure the fix is to tee the ReadableStream and inspect
|
|
141
|
+
* the first chunk without buffering the rest — deferred until
|
|
142
|
+
* evidence shows it's worth the complexity.
|
|
49
143
|
*
|
|
50
144
|
* Content-Disposition + X-Content-Type-Options come from the hub
|
|
51
145
|
* response and are passed through verbatim — the hub already stamps
|
|
52
146
|
* `attachment` disposition + `nosniff` on downloads (issue #221),
|
|
53
147
|
* meaning the browser will download-not-render even if the file
|
|
54
148
|
* happens to be text/html. Do not add or alter those headers here.
|
|
149
|
+
*
|
|
150
|
+
* The response ALWAYS carries `attachment` disposition — the client
|
|
151
|
+
* reads `X-Verified-Type` and constructs a blob URL if it wants to
|
|
152
|
+
* inline the content. See `detectSafeMime` above for the security
|
|
153
|
+
* reasoning.
|
|
55
154
|
*/
|
|
56
155
|
export async function GET(
|
|
57
156
|
_req: Request,
|
|
@@ -76,7 +175,6 @@ export async function GET(
|
|
|
76
175
|
hubRes = await fetch(url, {
|
|
77
176
|
method: 'GET',
|
|
78
177
|
headers: { Authorization: `Bearer ${userToken}` },
|
|
79
|
-
// Streaming: avoid Next.js caching of the file bytes.
|
|
80
178
|
cache: 'no-store',
|
|
81
179
|
});
|
|
82
180
|
} catch (e: unknown) {
|
|
@@ -89,8 +187,6 @@ export async function GET(
|
|
|
89
187
|
// Forward hub's status verbatim so a 404 (unknown file_id) surfaces
|
|
90
188
|
// as a 404 the client can distinguish from a proxy error.
|
|
91
189
|
if (!hubRes.ok) {
|
|
92
|
-
// Try to keep JSON error shape when the hub gave one; otherwise
|
|
93
|
-
// return a generic status-only response.
|
|
94
190
|
const ct = hubRes.headers.get('content-type') || '';
|
|
95
191
|
if (ct.includes('json')) {
|
|
96
192
|
try {
|
|
@@ -103,6 +199,10 @@ export async function GET(
|
|
|
103
199
|
return new Response(null, { status: hubRes.status });
|
|
104
200
|
}
|
|
105
201
|
|
|
202
|
+
// Buffer full body — see JSDoc for the memory rationale.
|
|
203
|
+
const bytes = new Uint8Array(await hubRes.arrayBuffer());
|
|
204
|
+
const verifiedType = detectSafeMime(bytes.subarray(0, 32));
|
|
205
|
+
|
|
106
206
|
// Build the response header set — only the allowlisted ones. This
|
|
107
207
|
// strips anything the hub might leak (Set-Cookie, X-Hub-*, etc.).
|
|
108
208
|
const outHeaders = new Headers();
|
|
@@ -110,12 +210,45 @@ export async function GET(
|
|
|
110
210
|
const value = hubRes.headers.get(key);
|
|
111
211
|
if (value !== null) outHeaders.set(key, value);
|
|
112
212
|
}
|
|
213
|
+
// Content-Length may not survive if we re-emit the body; set from
|
|
214
|
+
// our own buffer length to be authoritative.
|
|
215
|
+
outHeaders.set('content-length', String(bytes.length));
|
|
216
|
+
|
|
113
217
|
// Defense-in-depth: always stamp nosniff on downloads even if the
|
|
114
218
|
// hub didn't (it does today per #221, but pinning here means a hub
|
|
115
219
|
// regression can't retroactively make the browser sniff-execute).
|
|
220
|
+
// The polyglot-PNG-HTML adversarial sample in verify.sh depends on
|
|
221
|
+
// this exact header being present.
|
|
116
222
|
outHeaders.set('x-content-type-options', 'nosniff');
|
|
117
223
|
|
|
118
|
-
|
|
224
|
+
// 🔴 SYMMETRIC PIN with nosniff (通信龙 review of PR #47):
|
|
225
|
+
// "永不 inline" is the single load-bearing invariant of this
|
|
226
|
+
// whole design. It CANNOT depend on hub always sending
|
|
227
|
+
// `Content-Disposition: attachment`, because a hub regression =
|
|
228
|
+
// proxy regression = XSS. Pin it here explicitly.
|
|
229
|
+
//
|
|
230
|
+
// Filename preservation: if hub sent `attachment; filename="..."`
|
|
231
|
+
// we keep the whole thing (users see the friendly name in their
|
|
232
|
+
// download folder). If hub returns anything else (`inline; ...`,
|
|
233
|
+
// or missing) we override to bare `attachment` with a
|
|
234
|
+
// safe file_id-based filename fallback.
|
|
235
|
+
const hubDisposition = hubRes.headers.get('content-disposition') || '';
|
|
236
|
+
if (/^\s*attachment\b/i.test(hubDisposition)) {
|
|
237
|
+
outHeaders.set('content-disposition', hubDisposition);
|
|
238
|
+
} else {
|
|
239
|
+
outHeaders.set('content-disposition', `attachment; filename="${fileId}"`);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// Structural invariant: `X-Verified-Type` is INFORMATIONAL only.
|
|
243
|
+
// Adding it does not change the response's disposition or
|
|
244
|
+
// Content-Type. The client uses it to decide whether to construct
|
|
245
|
+
// a blob URL for inline rendering (browser-owned blob: scheme,
|
|
246
|
+
// isolated from the dashboard origin).
|
|
247
|
+
if (verifiedType) {
|
|
248
|
+
outHeaders.set('x-verified-type', verifiedType);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return new Response(bytes, {
|
|
119
252
|
status: 200,
|
|
120
253
|
headers: outHeaders,
|
|
121
254
|
});
|
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { useState } from 'react';
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
4
|
+
|
|
5
|
+
// ── #492 preview half — inline image/video display ───────────────
|
|
6
|
+
//
|
|
7
|
+
// See docs/design-492-inline-preview.md for the full design rationale
|
|
8
|
+
// (通信龙 v2 review approved the "never inline" structure).
|
|
9
|
+
//
|
|
10
|
+
// The proxy at /api/hub/files/[fileId] ALWAYS returns bytes with
|
|
11
|
+
// `Content-Disposition: attachment` + `nosniff`. It also stamps a
|
|
12
|
+
// `X-Verified-Type` header when the file matches a magic-bytes-verified
|
|
13
|
+
// safe-media type. Client:
|
|
14
|
+
// 1. Fetches via the download proxy (browser downloads bytes to memory)
|
|
15
|
+
// 2. Reads `X-Verified-Type` — if absent, falls back to download card
|
|
16
|
+
// 3. Constructs `new Blob([bytes], {type: X-Verified-Type})`
|
|
17
|
+
// 4. `URL.createObjectURL(blob)` → `<img>` / `<video>` src
|
|
18
|
+
//
|
|
19
|
+
// The blob URL is a browser-owned handle, isolated from the dashboard
|
|
20
|
+
// origin. A whitelist bug can degrade rendering (image won't load) but
|
|
21
|
+
// can NEVER become an XSS on the dashboard origin.
|
|
22
|
+
|
|
23
|
+
/** Client-side ext hint — used ONLY to decide whether it's worth
|
|
24
|
+
* fetching the file to try the preview. The SERVER decides
|
|
25
|
+
* authoritatively whether to expose `X-Verified-Type` via magic
|
|
26
|
+
* bytes; this list just avoids fetching a PDF just to learn it
|
|
27
|
+
* isn't inline-able. Under-selection here = missed preview
|
|
28
|
+
* opportunity (only a UX cost). Over-selection = wasted fetch that
|
|
29
|
+
* falls back to card (only a bandwidth cost). Nothing security. */
|
|
30
|
+
const PREVIEW_HINT_EXTS = new Set([
|
|
31
|
+
'png', 'jpg', 'jpeg', 'gif', 'webp',
|
|
32
|
+
'mp4', 'webm', 'mov', // .mov may or may not verify as mp4; server decides
|
|
33
|
+
]);
|
|
34
|
+
|
|
35
|
+
const IMAGE_MIMES = new Set(['image/png', 'image/jpeg', 'image/gif', 'image/webp']);
|
|
36
|
+
const VIDEO_MIMES = new Set(['video/mp4', 'video/webm']);
|
|
37
|
+
|
|
38
|
+
/** Auto-load images below this size. Larger images render as a
|
|
39
|
+
* click-to-load card to protect mobile bandwidth. Vincent uses this
|
|
40
|
+
* on his phone; a full 12 MiB image auto-loading over a random
|
|
41
|
+
* cellular connection is not the right default. */
|
|
42
|
+
const IMAGE_AUTOLOAD_MAX_BYTES = 5 * 1024 * 1024;
|
|
4
43
|
|
|
5
44
|
/**
|
|
6
45
|
* #492 attachment descriptor as it appears in `meta.attachments[]` on
|
|
@@ -113,9 +152,235 @@ function iconFor(mime: string, name: string): string {
|
|
|
113
152
|
* the chat scroll position isn't lost. Two seconds of visible
|
|
114
153
|
* feedback is enough for the user to see + retry.
|
|
115
154
|
*/
|
|
155
|
+
/** Shared blob-URL fetcher — returns {blobUrl, verifiedType} or
|
|
156
|
+
* throws. Used by both InlineImage/InlineVideo (for preview) and
|
|
157
|
+
* the download button (for the save-to-disk flow). Caller owns the
|
|
158
|
+
* returned blobUrl lifecycle (must revoke). */
|
|
159
|
+
async function fetchVerified(fileId: string): Promise<{ blobUrl: string; verifiedType: string | null; blob: Blob }> {
|
|
160
|
+
const res = await fetch(`/api/hub/files/${encodeURIComponent(fileId)}`, {
|
|
161
|
+
credentials: 'include',
|
|
162
|
+
});
|
|
163
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
164
|
+
// Header lookup is case-insensitive; Next's Response uses this pattern.
|
|
165
|
+
const verifiedType = res.headers.get('x-verified-type');
|
|
166
|
+
// Only trust the whitelist values — anything else is dropped so a
|
|
167
|
+
// future server bug can't smuggle an arbitrary type in.
|
|
168
|
+
const trusted =
|
|
169
|
+
verifiedType && (IMAGE_MIMES.has(verifiedType) || VIDEO_MIMES.has(verifiedType))
|
|
170
|
+
? verifiedType
|
|
171
|
+
: null;
|
|
172
|
+
const rawBlob = await res.blob();
|
|
173
|
+
const blob = trusted ? new Blob([rawBlob], { type: trusted }) : rawBlob;
|
|
174
|
+
return { blobUrl: URL.createObjectURL(blob), verifiedType: trusted, blob };
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Filename extension helper — lowercase, no dot, empty for extensionless. */
|
|
178
|
+
function extOf(name: string): string {
|
|
179
|
+
const i = name.lastIndexOf('.');
|
|
180
|
+
return i >= 0 ? name.slice(i + 1).toLowerCase() : '';
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** True when it's worth trying an inline preview (client-side hint
|
|
184
|
+
* only — server decides authoritatively). */
|
|
185
|
+
function shouldTryPreview(name: string, mime: string): boolean {
|
|
186
|
+
if (IMAGE_MIMES.has(mime) || VIDEO_MIMES.has(mime)) return true;
|
|
187
|
+
const ext = extOf(name);
|
|
188
|
+
return ext !== '' && PREVIEW_HINT_EXTS.has(ext);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Inline image preview. Auto-loads for images below
|
|
193
|
+
* IMAGE_AUTOLOAD_MAX_BYTES; renders a click-to-load card for larger
|
|
194
|
+
* images (mobile bandwidth protection). If the server doesn't return
|
|
195
|
+
* `X-Verified-Type` in the whitelist, or if the fetch fails, calls
|
|
196
|
+
* `onNotInlineable` so the parent falls back to the download card.
|
|
197
|
+
*/
|
|
198
|
+
function InlineImage({
|
|
199
|
+
fileId,
|
|
200
|
+
name,
|
|
201
|
+
size,
|
|
202
|
+
onNotInlineable,
|
|
203
|
+
}: {
|
|
204
|
+
fileId: string;
|
|
205
|
+
name: string;
|
|
206
|
+
size: number | undefined;
|
|
207
|
+
onNotInlineable: () => void;
|
|
208
|
+
}) {
|
|
209
|
+
const autoLoad = typeof size === 'number' && size <= IMAGE_AUTOLOAD_MAX_BYTES;
|
|
210
|
+
const [blobUrl, setBlobUrl] = useState<string | null>(null);
|
|
211
|
+
const [loading, setLoading] = useState(false);
|
|
212
|
+
const [failed, setFailed] = useState(false);
|
|
213
|
+
const notInlineableRef = useRef(onNotInlineable);
|
|
214
|
+
notInlineableRef.current = onNotInlineable;
|
|
215
|
+
|
|
216
|
+
const load = useCallback(async () => {
|
|
217
|
+
if (loading || blobUrl) return;
|
|
218
|
+
setLoading(true);
|
|
219
|
+
try {
|
|
220
|
+
const { blobUrl: url, verifiedType } = await fetchVerified(fileId);
|
|
221
|
+
if (!verifiedType || !IMAGE_MIMES.has(verifiedType)) {
|
|
222
|
+
// Server declined — the file's real type isn't a safe image.
|
|
223
|
+
// Release the URL immediately and hand off to the download card.
|
|
224
|
+
URL.revokeObjectURL(url);
|
|
225
|
+
notInlineableRef.current();
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
setBlobUrl(url);
|
|
229
|
+
} catch {
|
|
230
|
+
setFailed(true);
|
|
231
|
+
} finally {
|
|
232
|
+
setLoading(false);
|
|
233
|
+
}
|
|
234
|
+
}, [fileId, loading, blobUrl]);
|
|
235
|
+
|
|
236
|
+
useEffect(() => {
|
|
237
|
+
if (autoLoad) void load();
|
|
238
|
+
}, [autoLoad, load]);
|
|
239
|
+
|
|
240
|
+
// Revoke on unmount OR when blobUrl replaced.
|
|
241
|
+
useEffect(() => {
|
|
242
|
+
if (!blobUrl) return;
|
|
243
|
+
return () => URL.revokeObjectURL(blobUrl);
|
|
244
|
+
}, [blobUrl]);
|
|
245
|
+
|
|
246
|
+
if (failed) {
|
|
247
|
+
return (
|
|
248
|
+
<div className="mt-2 rounded-lg border border-amber-500/20 bg-amber-500/5 px-3 py-2 text-sm text-amber-200">
|
|
249
|
+
图片加载失败 · 请点击下方下载按钮查看
|
|
250
|
+
</div>
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (blobUrl) {
|
|
255
|
+
return (
|
|
256
|
+
<div className="mt-2 overflow-hidden rounded-lg border border-white/10 bg-black/20">
|
|
257
|
+
{/* eslint-disable-next-line @next/next/no-img-element -- blob: URL, next/image can't handle */}
|
|
258
|
+
<img
|
|
259
|
+
src={blobUrl}
|
|
260
|
+
alt={name}
|
|
261
|
+
className="block max-h-[50vh] w-auto max-w-full cursor-zoom-in object-contain"
|
|
262
|
+
// "Open in new tab" satisfies the "点开大图" acceptance gate
|
|
263
|
+
// without threading blob URLs through the multi-image
|
|
264
|
+
// TaskChatPanel lightbox (that integration is a follow-up).
|
|
265
|
+
onClick={() => window.open(blobUrl, '_blank', 'noopener')}
|
|
266
|
+
/>
|
|
267
|
+
</div>
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// Not loaded yet — either loading spinner or click-to-load card.
|
|
272
|
+
return (
|
|
273
|
+
<button
|
|
274
|
+
type="button"
|
|
275
|
+
onClick={load}
|
|
276
|
+
disabled={loading}
|
|
277
|
+
className="mt-2 flex w-full items-center gap-2 rounded-lg border border-cyan-500/20 bg-cyan-500/5 px-3 py-2 text-left text-sm text-cyan-100 transition hover:border-cyan-400/40 hover:bg-cyan-500/10 disabled:cursor-wait disabled:opacity-60"
|
|
278
|
+
>
|
|
279
|
+
<span aria-hidden className="text-lg">🖼️</span>
|
|
280
|
+
<span className="min-w-0 flex-1 truncate">{name}</span>
|
|
281
|
+
<span className="shrink-0 text-xs text-cyan-300">
|
|
282
|
+
{loading ? '加载中…' : '点击查看'}
|
|
283
|
+
</span>
|
|
284
|
+
</button>
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Inline video preview. NEVER auto-loads — 5 videos on-screen at
|
|
290
|
+
* 12 MiB each = 60 MiB memory spike. Renders a poster card that
|
|
291
|
+
* fetches + creates the blob only on click, then swaps to
|
|
292
|
+
* `<video controls autoplay>`.
|
|
293
|
+
*
|
|
294
|
+
* Trade-off (per design doc §5.2): blob URL means full file
|
|
295
|
+
* downloaded before first byte plays; there's no range/seek. Fine
|
|
296
|
+
* under the current 12 MiB hub cap; if the cap ever rises, this
|
|
297
|
+
* component needs a real streaming source (server-side signed URL
|
|
298
|
+
* with byte-range support), not a blob.
|
|
299
|
+
*/
|
|
300
|
+
function InlineVideo({
|
|
301
|
+
fileId,
|
|
302
|
+
name,
|
|
303
|
+
onNotInlineable,
|
|
304
|
+
}: {
|
|
305
|
+
fileId: string;
|
|
306
|
+
name: string;
|
|
307
|
+
onNotInlineable: () => void;
|
|
308
|
+
}) {
|
|
309
|
+
const [blobUrl, setBlobUrl] = useState<string | null>(null);
|
|
310
|
+
const [loading, setLoading] = useState(false);
|
|
311
|
+
const [failed, setFailed] = useState(false);
|
|
312
|
+
const notInlineableRef = useRef(onNotInlineable);
|
|
313
|
+
notInlineableRef.current = onNotInlineable;
|
|
314
|
+
|
|
315
|
+
const load = useCallback(async () => {
|
|
316
|
+
if (loading || blobUrl) return;
|
|
317
|
+
setLoading(true);
|
|
318
|
+
try {
|
|
319
|
+
const { blobUrl: url, verifiedType } = await fetchVerified(fileId);
|
|
320
|
+
if (!verifiedType || !VIDEO_MIMES.has(verifiedType)) {
|
|
321
|
+
URL.revokeObjectURL(url);
|
|
322
|
+
notInlineableRef.current();
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
setBlobUrl(url);
|
|
326
|
+
} catch {
|
|
327
|
+
setFailed(true);
|
|
328
|
+
} finally {
|
|
329
|
+
setLoading(false);
|
|
330
|
+
}
|
|
331
|
+
}, [fileId, loading, blobUrl]);
|
|
332
|
+
|
|
333
|
+
useEffect(() => {
|
|
334
|
+
if (!blobUrl) return;
|
|
335
|
+
return () => URL.revokeObjectURL(blobUrl);
|
|
336
|
+
}, [blobUrl]);
|
|
337
|
+
|
|
338
|
+
if (failed) {
|
|
339
|
+
return (
|
|
340
|
+
<div className="mt-2 rounded-lg border border-amber-500/20 bg-amber-500/5 px-3 py-2 text-sm text-amber-200">
|
|
341
|
+
视频加载失败 · 请点击下方下载按钮查看
|
|
342
|
+
</div>
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
if (blobUrl) {
|
|
347
|
+
return (
|
|
348
|
+
<div className="mt-2 overflow-hidden rounded-lg border border-white/10 bg-black/20">
|
|
349
|
+
<video
|
|
350
|
+
src={blobUrl}
|
|
351
|
+
controls
|
|
352
|
+
autoPlay
|
|
353
|
+
className="block max-h-[50vh] w-full"
|
|
354
|
+
>
|
|
355
|
+
您的浏览器不支持内联视频播放,请下载后查看。
|
|
356
|
+
</video>
|
|
357
|
+
</div>
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
return (
|
|
362
|
+
<button
|
|
363
|
+
type="button"
|
|
364
|
+
onClick={load}
|
|
365
|
+
disabled={loading}
|
|
366
|
+
className="mt-2 flex w-full items-center gap-2 rounded-lg border border-cyan-500/20 bg-cyan-500/5 px-3 py-2 text-left text-sm text-cyan-100 transition hover:border-cyan-400/40 hover:bg-cyan-500/10 disabled:cursor-wait disabled:opacity-60"
|
|
367
|
+
>
|
|
368
|
+
<span aria-hidden className="text-lg">🎬</span>
|
|
369
|
+
<span className="min-w-0 flex-1 truncate">{name}</span>
|
|
370
|
+
<span className="shrink-0 text-xs text-cyan-300">
|
|
371
|
+
{loading ? '加载中…' : '▶ 播放'}
|
|
372
|
+
</span>
|
|
373
|
+
</button>
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
|
|
116
377
|
export function AttachmentBlock({ attachment }: { attachment: Attachment }) {
|
|
117
378
|
const [downloading, setDownloading] = useState(false);
|
|
118
379
|
const [error, setError] = useState<string | null>(null);
|
|
380
|
+
// Ext-based hint says "try preview" — set to false after the
|
|
381
|
+
// server declines (no X-Verified-Type) or after a hard fetch
|
|
382
|
+
// failure. Once false, only the download card renders.
|
|
383
|
+
const [previewGivenUp, setPreviewGivenUp] = useState(false);
|
|
119
384
|
|
|
120
385
|
const safeName = sanitizeName(attachment.name);
|
|
121
386
|
const safeMime = sanitizeMime(attachment.mime);
|
|
@@ -125,6 +390,15 @@ export function AttachmentBlock({ attachment }: { attachment: Attachment }) {
|
|
|
125
390
|
const hasValidFileId =
|
|
126
391
|
typeof attachment.file_id === 'string' && FILE_ID_REGEX.test(attachment.file_id);
|
|
127
392
|
|
|
393
|
+
const tryPreview = hasValidFileId && !previewGivenUp && shouldTryPreview(safeName, safeMime);
|
|
394
|
+
const ext = extOf(safeName);
|
|
395
|
+
// Client hint only — server verifies. We just pick which preview
|
|
396
|
+
// component to try first. If the ext is ambiguous (e.g. missing),
|
|
397
|
+
// default to image since image detection is cheap and safe.
|
|
398
|
+
const previewKind: 'image' | 'video' | null = tryPreview
|
|
399
|
+
? (VIDEO_MIMES.has(safeMime) || ['mp4', 'webm', 'mov'].includes(ext) ? 'video' : 'image')
|
|
400
|
+
: null;
|
|
401
|
+
|
|
128
402
|
async function handleDownload() {
|
|
129
403
|
if (!hasValidFileId || !attachment.file_id) return;
|
|
130
404
|
setError(null);
|
|
@@ -176,25 +450,48 @@ export function AttachmentBlock({ attachment }: { attachment: Attachment }) {
|
|
|
176
450
|
}
|
|
177
451
|
|
|
178
452
|
return (
|
|
179
|
-
<
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
<span className="shrink-0 rounded bg-white/5 px-1.5 py-0.5 text-[10px] text-neutral-400">
|
|
191
|
-
{safeMime}
|
|
192
|
-
</span>
|
|
453
|
+
<div className="mt-2 flex flex-col">
|
|
454
|
+
{/* Inline preview: rendered when ext hint suggests media and the
|
|
455
|
+
server hasn't declined yet. On decline (`onNotInlineable`) or
|
|
456
|
+
hard failure, we drop back to just the download card below. */}
|
|
457
|
+
{previewKind === 'image' && attachment.file_id && (
|
|
458
|
+
<InlineImage
|
|
459
|
+
fileId={attachment.file_id}
|
|
460
|
+
name={safeName}
|
|
461
|
+
size={typeof attachment.size === 'number' ? attachment.size : undefined}
|
|
462
|
+
onNotInlineable={() => setPreviewGivenUp(true)}
|
|
463
|
+
/>
|
|
193
464
|
)}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
465
|
+
{previewKind === 'video' && attachment.file_id && (
|
|
466
|
+
<InlineVideo
|
|
467
|
+
fileId={attachment.file_id}
|
|
468
|
+
name={safeName}
|
|
469
|
+
onNotInlineable={() => setPreviewGivenUp(true)}
|
|
470
|
+
/>
|
|
471
|
+
)}
|
|
472
|
+
{/* Download card — always available for save-to-disk, even when
|
|
473
|
+
the preview is shown. Users still need a way to save a copy
|
|
474
|
+
off the ephemeral blob URL. */}
|
|
475
|
+
<button
|
|
476
|
+
type="button"
|
|
477
|
+
onClick={handleDownload}
|
|
478
|
+
disabled={downloading}
|
|
479
|
+
className="flex w-full items-center gap-2 rounded-lg border border-cyan-500/20 bg-cyan-500/5 px-3 py-2 text-left text-sm text-cyan-100 transition hover:border-cyan-400/40 hover:bg-cyan-500/10 disabled:cursor-wait disabled:opacity-60 mt-2 first:mt-0"
|
|
480
|
+
title={`Download ${safeName}`}
|
|
481
|
+
>
|
|
482
|
+
<span aria-hidden className="text-lg">{icon}</span>
|
|
483
|
+
<span className="min-w-0 flex-1 truncate">{safeName}</span>
|
|
484
|
+
{safeSize && <span className="shrink-0 text-xs text-neutral-400">{safeSize}</span>}
|
|
485
|
+
{safeMime && (
|
|
486
|
+
<span className="shrink-0 rounded bg-white/5 px-1.5 py-0.5 text-[10px] text-neutral-400">
|
|
487
|
+
{safeMime}
|
|
488
|
+
</span>
|
|
489
|
+
)}
|
|
490
|
+
<span className="shrink-0 text-xs text-cyan-300">
|
|
491
|
+
{downloading ? '下载中…' : error ? `⚠ ${error}` : '↓ 下载'}
|
|
492
|
+
</span>
|
|
493
|
+
</button>
|
|
494
|
+
</div>
|
|
198
495
|
);
|
|
199
496
|
}
|
|
200
497
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# #492 inline preview — verification summary
|
|
2
|
+
|
|
3
|
+
## Hard invariants (通信龙 v2 review)
|
|
4
|
+
|
|
5
|
+
Adopting 通信龙's structural fix: the proxy **never** returns an inline response, regardless of what the file's real type is. `Content-Disposition: attachment` + `X-Content-Type-Options: nosniff` stay stamped on every download. The client uses the `X-Verified-Type` header to decide whether to blob-and-inline; a bug in the whitelist can only degrade rendering, never become an XSS vector on the dashboard origin.
|
|
6
|
+
|
|
7
|
+
## verify.sh — 14/14 PASS (witnessed-green)
|
|
8
|
+
|
|
9
|
+
Real hub + real dashboard dev server. Every case builds real bytes, uploads via the dashboard proxy, fetches back, and asserts on response headers + body cmp.
|
|
10
|
+
|
|
11
|
+
| # | Case | Assertion |
|
|
12
|
+
|---|---|---|
|
|
13
|
+
| 1 | Real PNG | `X-Verified-Type: image/png` + `nosniff` + `Content-Disposition: attachment` |
|
|
14
|
+
| 2 | SVG-in-.png (mime says image/png) | `X-Verified-Type` absent; attachment |
|
|
15
|
+
| 3 | HTML-in-.png | `X-Verified-Type` absent |
|
|
16
|
+
| 4 | HTML-in-.mp4 (mime says video/mp4) | `X-Verified-Type` absent |
|
|
17
|
+
| 5 | PNG/HTML polyglot | `X-Verified-Type: image/png` + `nosniff` (the pin that stops HTML sniffing) |
|
|
18
|
+
| 6 | Real PDF | `X-Verified-Type` absent (not whitelisted) |
|
|
19
|
+
| 7 | Byte-identical cmp vs original | identical (preview path didn't mangle bytes) |
|
|
20
|
+
|
|
21
|
+
## witnessed-RED proof
|
|
22
|
+
|
|
23
|
+
Broke `detectSafeMime` to always return `image/png` (i.e. accept everything as an image):
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
── 2. SVG in .png ── ✗ x-verified-type should be absent
|
|
27
|
+
── 3. HTML in .png ── ✗ x-verified-type should be absent
|
|
28
|
+
── 4. HTML in .mp4 ── ✗ x-verified-type should be absent
|
|
29
|
+
── 6. PDF ── ✗ x-verified-type should be absent
|
|
30
|
+
── Summary ── PASS=10 FAIL=4
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Exactly the four adversarial cases turned red. The real PNG (case 1) and the PNG polyglot (case 5) stayed green because both are genuine PNGs by magic bytes — the broken impl was accidentally right about them. **This is the correct signal**: green-when-broken-shouldn't-be doesn't count as verification; the test needs to be able to fire red on the mutation it claims to protect against.
|
|
34
|
+
|
|
35
|
+
Restored + re-ran (`grep -c "WITNESSED-RED" route.ts` → 0).
|
|
36
|
+
|
|
37
|
+
## What this does NOT prove (deliberately deferred)
|
|
38
|
+
|
|
39
|
+
- **Browser-side behaviour of the blob URL.** The proxy returns bytes + `X-Verified-Type`; the browser wraps them in a blob and feeds `<img>`/`<video>`. That last step is tested manually — the design keeps the security boundary at the proxy so blob-level bugs can only degrade rendering, not create XSS.
|
|
40
|
+
- **Multi-image lightbox integration.** The current click-through opens the blob URL in a new tab (satisfies the "点开大图" gate literally). Threading blob URLs into `TaskChatPanel`'s multi-image lightbox is a follow-up.
|
|
41
|
+
- **Audio.** Design doc §9 confirms this is deliberate; adding audio is two whitelist rows.
|