Repository navigation
feat(cli): the console's frame-src names the storage origin a PDF preview frames, and nothing wider - #36565
Conversation
…view frames, and nothing wider (#36443) Claude-Session: https://claude.ai/code/session_01ADHkmRB34k9WUWeGpRnVNm Co-authored-by: Claude <noreply@anthropic.com>
…t spell (#36443) Claude-Session: https://claude.ai/code/session_01ADHkmRB34k9WUWeGpRnVNm Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 1 package(s): ⛔ 1 release-owned page(s) name something this change touched. These are read-only:
What this run could not see
Coarse fallback — 40 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 7c9d969c588ca4f2e5dbb82627ece62f77cc4abf && git checkout 7c9d969c588ca4f2e5dbb82627ece62f77cc4abf
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin abe95a950dc2fa93c49120b624129783ef818373 71ebf3eb13abfb6e867a61c5d1b11f63e3c0d4c1 && git checkout -B drift-repro abe95a950dc2fa93c49120b624129783ef818373 && git merge --no-ff 71ebf3eb13abfb6e867a61c5d1b11f63e3c0d4c1
node scripts/docs-audit/affected-docs.mjs --json abe95a950dc2fa93c49120b624129783ef818373
|
…eviews need (#36443) Claude-Session: https://claude.ai/code/session_01ADHkmRB34k9WUWeGpRnVNm Co-authored-by: Claude <noreply@anthropic.com>
|
repo:objectstack#2 · os-steve · session_01ADHkmRB34k9WUWeGpRnVNm 席位核对ACCEPT — PR #36565 @ 71ebf3e (head of record, full sha on the PR) · card #36443 · L1 first read by area s2-B (area order rule 9) · 2026-11-23T01:13Z
|
…achments and file fields (objectstack-ai#36587) <!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi92ncfFpPUpTD8314otX5oaG)_ Fixes objectstack-ai#36442 Clause-②: yes (widening) Metadata-protocol: none ## 维护者速读 - 控制台用户在记录的附件列表点文件名、或在文件字段点文件链接时,图片、PDF、纯文本和表格文件直接在页面弹窗里看,不再先下载;Word、Excel、PPT 仍只能下载。 - 这是附件预览决策选定的方案甲(页内预览,社区版默认)的界面半边,服务端那半边由同区另一张卡负责。 - 若出错,最坏是预览打不开、用户点弹窗里的下载或新标签页照旧拿到文件;没有下载权限的人在预览里同样被拒;可整体撤回。 - 要你做的:无。 ## What changes A shared `FilePreviewDialog` in `@object-ui/fields` (decision objectstack-ai#34781, option A), opened from a record's attachments and from a file field: - **Views, no new dependency.** Image (PNG, JPEG, GIF, WebP, and SVG through an `img` element only) via the lightbox's own image element (`LightboxImageView`, extracted from `ImageLightbox`); PDF in an `iframe` on the browser's own viewer, without a `sandbox` attribute; plain text as text; CSV as a table, read with the GBK-aware `decodeSpreadsheetText` and `parseDelimited`, which moved down from `@object-ui/plugin-grid` (it now imports them from `@object-ui/fields`; no copy). - **Download only.** Word, Excel, PowerPoint, HTML and every other type: "This file type cannot be previewed. Please download it." HTML was measured as a choice between "unsupported" and "source as text"; this PR takes **unsupported**: nothing is fetched, nothing is framed, nothing is drawn. A declared HTML type wins over a harmless name, and an `.html` name wins over a declared plain-text type. - **The PDF frame needs a PDF signal**: the declared `application/pdf`, or a `.pdf` name when no type is declared. A `.pdf` name with another declared type (for example `application/octet-stream`) is unsupported, so the frame never receives bytes the browser would read as anything else. - **Limits** (maintainer defaults): images and PDF 20 MB, text and CSV 2 MB, judged on the declared size before anything is fetched and on the bytes read when no size is declared; text and CSV show their first 1000 lines (CSV: header plus 1000 rows). Past a limit: "too large, please download" with a download button. - **Controls**: previous / next (and the arrow keys) across a record's attachments; download; open in a new tab. - **Same door as the download.** In the attachments panel the preview mints its link with the download's own call (`/files/:id/url` with the console's token, now one `signedUrlFor` both use), and a refusal shows the download's own copy. On a file field the preview uses the field's own link (the stable `/files/:id` endpoint) and first asks it with `redirect: 'manual'`: a redirect is the grant, a 401/403 is the refusal, so no byte moves twice. - **Phone**: below the `useIsMobile` breakpoint a PDF is offered in a new tab (the system viewer), never framed; image, text and CSV stay in the page. - **Cross-origin bucket** (the contract in objectstack-ai#36443 / objectstack-ai#36565): text and CSV are read with a `GET` on the signed link from the page; when the browser refuses that read (no bucket CORS rule for the console origin), the dialog offers "Open in new tab" instead. - **Wiring**: `RecordAttachmentsPanel`, the row's name is now a button that opens the preview (download stays in the row's menu); `FileValueAffordance` (`file-affordance.tsx`), a plain click opens the preview, a modified click keeps the link's own new tab, and a click inside the dialog does not bubble to the grid row behind its portal. - **Copy**: 15 new keys under `fields.filePreview` in all 12 packs (zh-Hant regenerated from zh-Hans by its generator). New public exports from `@object-ui/fields` (preferred names, built under them): `FilePreviewDialog`, `FilePreviewDialogProps`, `FilePreviewItem`, `decodeSpreadsheetText`, `parseDelimited`. Alternatives considered: `FileViewerDialog` / `FileViewerDialogProps` / `FileViewerItem`. New `@object-ui/i18n` keys (every pack): `fields.filePreview.title`, `fields.filePreview.previous`, `fields.filePreview.next`, `fields.filePreview.download`, `fields.filePreview.openInNewTab`, `fields.filePreview.loading`, `fields.filePreview.tooLarge`, `fields.filePreview.unsupported`, `fields.filePreview.denied`, `fields.filePreview.loadFailed`, `fields.filePreview.blocked`, `fields.filePreview.pdfOutside`, `fields.filePreview.truncatedRows`, `fields.filePreview.truncatedLines`, `fields.filePreview.empty`. Read first, by risk: `filePreviewKind` (which bytes may reach the `iframe`), `useResolver` in `FilePreviewDialog.tsx` (the refusal probe and the one-resolver-per-dialog rule), then `previewSignedUrl` / `signedUrlFor` in `RecordAttachmentsPanel.tsx`. Two-minute check: `pnpm --dir ui exec vitest run packages/fields/src/widgets/FilePreviewDialog-36442.test.tsx` shows 51 passing. ## Tests - New card-named file `ui/packages/fields/src/widgets/FilePreviewDialog-36442.test.tsx`: the kind table (Office, HTML, SVG, PDF-signal cases); each view and its element; SVG only as `img`, no `iframe`/`object`, bytes never fetched; text drawn as text (a script tag in the file stays text); GBK CSV; the 1000-row cap; Office and HTML download only with nothing resolved, fetched or framed; too large per kind, a control at exactly the limit, and a text file judged on its bytes; the refusal from `resolveUrl`, from the default probe (403), from the text read (403), with a redirect as the control; the CORS-blocked read offering the new tab; previous / next / arrow keys / wrap; download and new tab; phone PDF in a new tab and phone image in the page; the field link opening the preview, a modified click not, a refused field file, a Word field file. - Shared harness `RecordAttachmentsPanel.test.tsx`, new top-level `describe`: the name opens the preview on the signed link, next walks to the next row's own link, a refused reader gets the download's copy (and the link is asked once), a Word file offers only the download and that download is the row menu's, the row menu still carries Download. - Shared harness `importParsers.test.ts`, new `describe`: the wizard's `parseDelimited` / `decodeSpreadsheetText` are the very functions `@object-ui/fields` exports. - Tests changed because the product changed: none. Existing pins that query `getByText('report.pdf')` keep passing on the new name button. ## Acceptance notes - **Multi-file field values preview one file at a time.** A file field holding several files opens each file's own preview without previous / next across the value: the group lives at the call sites in `FileField.tsx` and the cell renderer in the fields barrel, outside this card's claimed file surface. The attachments panel walks its whole list. - "Phone" is the console's viewport breakpoint (`useIsMobile`, under 768 px), not a device check. - objectstack-ai#36518 (open): answers stored bytes outside an inline allow-list as attachments, keeps PDF and plain text inline. Effect here: none on the in-page views (the text and CSV views read bytes with `fetch`, which ignores the disposition; objectstack-ai#36565 measured Chromium mounting its PDF viewer under that PR's sandbox header). The "Open in new tab" for a CSV would download it rather than display it once objectstack-ai#36518 lands. - On S3, the PDF frame needs objectstack-ai#36565's `frame-src` and the text and CSV reads need the bucket CORS rule objectstack-ai#36443 documents; without them the dialog offers the new tab, as that card's contract states. - The pre-existing `FILE_DOWNLOAD_DENIED` (field-owned files) has no friendly copy in the attachments panel's mapper; the panel only maps `ATTACHMENT_DOWNLOAD_DENIED`. The preview shows exactly what the download shows. Observation only. ## Verification Screenshots: NOT MEASURED. Reason: the relay writes text bodies only and no write door here uploads an image to a pull request; a live Console run was not started in this container. <details><summary>Package suites on the merged head (ab1feda, then c131bca and 81b19aa for the census fixes)</summary> ``` pnpm --dir ui exec vitest run packages/fields/ packages/plugin-grid/ packages/i18n/ (merged head 538f09f) Test Files 1 failed | 735 passed | 1 skipped (737) the zh-Hant pack is generated: regenerated in ab1feda pnpm --dir ui exec vitest run packages/i18n/ FilePreviewDialog-36442 RecordAttachmentsPanel.test importParsers.test (ab1feda) Test Files 109 passed (109) Tests 2138 passed | 13 skipped (2151) pnpm --dir ui exec vitest run scripts/ packages/plugin-grid/src/importParsers.test.ts (c131bca) Test Files 173 passed | 2 skipped (175) Tests 5185 passed | 2 skipped (5187) pnpm --dir ui exec vitest run dialogViewportGutterCensus-12603 clickableNonControlCensus-13461 FilePreviewDialog-36442 fileCellDownload-9485 RecordAttachmentsPanel.test (81b19aa) Test Files 5 passed (5) Tests 129 passed (129) pnpm --filter @object-ui/{fields,i18n,plugin-grid,app-shell} type-check TC-OK on all four ``` </details> <details><summary>Ablation: delete the default probe's refusal (one line in useResolver)</summary> ``` ablation-replace: ok mutation landed: anchor 1 -> 0, blob 1697ea6 -> 6bf8a8ebcffc × by default, the stable storage endpoint is asked without following its redirect; a 403 is refused × a field file the reader may not download gets the refusal in the preview Tests 2 failed | 49 passed (51) ablation-replace: ok restored: blob == HEAD (1697ea6) and `git diff HEAD` is empty ``` </details> <details><summary>Derived gate list on 81b19aa: 42 of 42 run, all exit 0</summary> `node scripts/pm/dispatch-gates.mjs --repo objectstack-ai/objectstack --ran FILE`: "42 derived famil(ies) accounted for — 42 run, 0 NOT-MEASURED". `check:type-check-debt` and the ui `scripts/` suite ran under the shared verify lock. `node scripts/pm/overlap-check.mjs`: VERDICT clean exit 0. </details> CI on 81b19aa: every required check green (Lint & Repo Gates, TypeScript Type Check, Test Core, Governed Surface Queue Guard, Lint UI, Type Check UI, Test UI, Build & E2E UI, Live E2E UI, Dogfood Regression Gate; Build Core skipped by its selector). Two shared censuses the first CI round named are now satisfied without touching them: the dialog's width is `sm:max-w-[92vw] xl:max-w-5xl`, a viewport-relative cap that keeps a margin at every width (the gutter census counts it as not wide), and the dialog stops its own clicks at its content rather than through a clickable wrapper element (the clickable-non-control census). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01ADHkmRB34k9WUWeGpRnVNm <!-- signed: repo:objectstack#2 · os-steve · session_01ADHkmRB34k9WUWeGpRnVNm --> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>
Requested by Steve · project thread
Fixes #36443
Clause-②: no
Metadata-protocol: none
维护者速读
What changes
packages/cli/src/utils/console.ts, the Console document's content-security-policy:frame-srcnow names the storage origin beside'self'when the deployment stores files in S3 or an S3-compatible store. It is the one valueconnect-srcalready names for presigned uploads (readStorageUploadOrigin, read per document). The S3 adapter signs its download links (getPresignedDownload, behindmintDownloadUrl) with the same client options for the same bucket, so the signedGETthe preview frames carries that origin; a test asserts the equality against real signed links.OS_CONSOLE_CSP_CONNECT_SRChosts, never a scheme or wildcard. With local storage, or when the storage service cannot name its origin,frame-srcis written exactly as before: absent (left todefault-src 'self'), or'self'plus the Turnstile frame while that challenge is on. With Turnstile and S3 both on:frame-src 'self' https://challenges.cloudflare.com STORE_ORIGIN.http(s)origin (it was anyconnect-srcsource shape). One value feeds both directives, so a scheme-only, wildcard, path or WebSocket answer is left out of both and reported once atwarn. The adapters that ship answerURL.origin, so no deployment changes.OS_CONSOLE_CSP_CONNECT_SRCrestores uploads only.content/docs/deployment/self-hosting.mdx, after the "Uploads need S3" paragraph: the bucket CORS rule browser uploads and file previews need.AllowedOriginsis the Console's exact public origin, never*;AllowedMethodsGET,HEAD,PUT;AllowedHeaderscontent-type(or*);ExposeHeadersContent-Length,Content-Type,Content-Disposition,ETag;MaxAgeSeconds3000. It says why a text or CSV preview needs the rule (aGETfrom the page) and a PDF frame does not, and that without it the preview falls back to opening the file in a new tab. The generatedcontent/docs/references/system/object-storage.mdxis untouched.Read first, by risk:
consoleContentSecurityPolicy(theframeSrcblock),readStorageUploadOrigin(theSTORAGE_ORIGINcheck), then the newdescribeinconsole.content-security-policy.test.ts.Two-minute check:
pnpm --filter @objectstack/cli exec vitest run --project unit src/utils/console.content-security-policy.test.ts -t 'frame-src names the storage origin'shows 11 passing cases.Tests
New top-level
describein the shared harnesssrc/utils/console.content-security-policy.test.ts(real plugin, real Hono app, realStorageServicePlugin):frame-src,default-src 'self';frame-srcis exactly'self'plus the bucket origin;http://127.0.0.1:9000): the extra source equals the origin of a real signed download link for a PDF;'self', the Turnstile origin, the store origin, nothing more;OS_CONSOLE_CSP_CONNECT_SRChosts (including a barehttps:) never reachframe-src;https:,https://*.example.com, a path,wss:and a number: neither directive widens, one warning.Acceptance notes
content/docs/references/system/object-storage.mdx, whichbuild-docs.tsgenerates and must not be hand-edited (surface amended on the card).GETdoes, and so do the existing browser uploads (PUT).StorageServicePluginOptions.s3does not acceptforcePathStyle, thoughS3StorageAdapterdoes; a path-style case was therefore dropped from the signed-link test. Observation only, not filed.nosniffand keeps PDF inline. Measured in Chromium (below), a PDF served with that sandbox header still mounts the browser's PDF viewer inside the frame.Verification
Real Chromium: a cross-origin PDF in an iframe, before and after the frame-src change
Ablation 1: delete the frame-src storage push
Ablation 2: accept any connect-src shape again instead of an exact origin
Package test and typecheck
Measured at 28deaa2 (the merges since bring no change under packages/cli): CSP file 77/77; the cli unit layer's 7 stale-build failures re-ran green after a rebuild (8 files, 267 tests), the other 431 files passed;
pnpm --filter @objectstack/cli typecheckexit 0. Gate families for the current head are reconciled in the report on the card.🤖 Generated with Claude Code
https://claude.ai/code/session_01ADHkmRB34k9WUWeGpRnVNm