Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
MUL-8579: feat(attachments): make the inline preview size configurable
Frezc1281b3817ad9
diff --git a/.env.example b/.env.exampleindex 572c6f3fe2..dd0f25358a 100644--- a/.env.example+++ b/.env.example@@ -399,6 +399,10 @@ AWS_ENDPOINT_URL=S3_USE_PATH_STYLE=ATTACHMENT_DOWNLOAD_MODE=autoATTACHMENT_DOWNLOAD_URL_TTL=30m+# Text/HTML preview body limit; bytes, KB/KiB, or MB/MiB. Maximum 16 MiB.+# Values above 16 MiB are clamped; invalid values use 2 MiB.+# Larger limits can slow browser previews. Upload and download limits are unchanged.+MULTICA_MAX_PREVIEW_SIZE=2MiBCLOUDFRONT_KEY_PAIR_ID=CLOUDFRONT_PRIVATE_KEY_SECRET=multica/cloudfront-signing-keyCLOUDFRONT_PRIVATE_KEY=diff --git a/apps/docs/content/docs/environment-variables.fr.mdx b/apps/docs/content/docs/environment-variables.fr.mdxindex e1df2bf930..8c8ea21916 100644--- a/apps/docs/content/docs/environment-variables.fr.mdx+++ b/apps/docs/content/docs/environment-variables.fr.mdx@@ -123,6 +123,10 @@ Pour l'ordre exact d'évaluation des listes d'autorisation, consultez [ConnexionLorsque `S3_BUCKET` n'est pas défini, Multica utilise le disque local.+| Variable | Défaut | Description |+|---|---|---|+| `MULTICA_MAX_PREVIEW_SIZE` | `2MiB` | Taille maximale du contenu des aperçus texte et HTML, plafonnée à `16MiB`. Accepte un entier positif en octets ou `KB`/`KiB`, `MB`/`MiB` (unités binaires). Les valeurs valides supérieures à `16MiB` sont ramenées à `16MiB` ; les valeurs invalides utilisent la valeur par défaut. Une limite plus élevée peut ralentir l’aperçu dans le navigateur, notamment la coloration syntaxique et le rendu Markdown. Redémarrer l’API après modification. Les limites de téléversement et de téléchargement restent inchangées. |+### S3 ou stockage compatible| Variable | Valeur par défaut | Description |diff --git a/apps/docs/content/docs/environment-variables.ja.mdx b/apps/docs/content/docs/environment-variables.ja.mdxindex 8572a51b25..7732d6a11c 100644--- a/apps/docs/content/docs/environment-variables.ja.mdx+++ b/apps/docs/content/docs/environment-variables.ja.mdx@@ -123,6 +123,10 @@ allowlist の正確な判定順序は[ログインとサインアップ](/auth-s`S3_BUCKET` が未設定の場合、Multica はローカルディスクを使います。+| 変数 | デフォルト | 説明 |+|---|---|---|+| `MULTICA_MAX_PREVIEW_SIZE` | `2MiB` | テキストと HTML のオンラインプレビュー本文の上限。最大 `16MiB`。正の整数のバイト数、`KB`/`KiB`、`MB`/`MiB`(二進単位)を指定できます。`16MiB` を超える有効な値は `16MiB` に制限され、不正な値はデフォルトに戻ります。上限を増やすと、特に構文ハイライトや Markdown の描画でブラウザーのプレビューが遅くなる場合があります。変更後は API を再起動してください。アップロードとダウンロードの制限は変わりません。 |+### S3 または互換ストレージ| 変数 | デフォルト | 説明 |diff --git a/apps/docs/content/docs/environment-variables.ko.mdx b/apps/docs/content/docs/environment-variables.ko.mdxindex 42f17d9995..024a2ea5d8 100644--- a/apps/docs/content/docs/environment-variables.ko.mdx+++ b/apps/docs/content/docs/environment-variables.ko.mdx@@ -123,6 +123,10 @@ allowlist의 정확한 판단 순서는 [로그인과 가입](/auth-setup#가입`S3_BUCKET`을 설정하지 않으면 Multica가 로컬 디스크를 사용합니다.+| 변수 | 기본값 | 설명 |+|---|---|---|+| `MULTICA_MAX_PREVIEW_SIZE` | `2MiB` | 텍스트 및 HTML 온라인 미리보기 본문의 최대 크기이며 상한은 `16MiB`입니다. 양의 정수 바이트 수 또는 `KB`/`KiB`, `MB`/`MiB`(이진 단위)를 지원합니다. `16MiB`를 초과하는 유효한 값은 `16MiB`로 제한되며 잘못된 값은 기본값을 사용합니다. 상한을 높이면 특히 구문 강조와 Markdown 렌더링 시 브라우저 미리보기가 느려질 수 있습니다. 변경 후 API를 재시작해야 하며 업로드 및 다운로드 제한은 바뀌지 않습니다. |+### S3 또는 호환 저장소| 변수 | 기본값 | 설명 |diff --git a/apps/docs/content/docs/environment-variables.mdx b/apps/docs/content/docs/environment-variables.mdxindex db44bcda35..e5e9ffa618 100644--- a/apps/docs/content/docs/environment-variables.mdx+++ b/apps/docs/content/docs/environment-variables.mdx@@ -123,6 +123,10 @@ For the exact allowlist evaluation order, see [Sign-in and signup](/auth-setup#sWhen `S3_BUCKET` is unset, Multica uses local disk.+| Variable | Default | Description |+|---|---|---|+| `MULTICA_MAX_PREVIEW_SIZE` | `2MiB` | Maximum body size for online text/HTML previews, up to `16MiB`. Accepts positive integer bytes or `KB`/`KiB`, `MB`/`MiB` (binary units). Valid values above `16MiB` are clamped to `16MiB`; invalid values use the default. Larger limits can slow browser previews, especially syntax highlighting and Markdown rendering. Restart the API after changing it. Upload and download limits are unchanged. |+### S3 or compatible storage| Variable | Default | Description |diff --git a/apps/docs/content/docs/environment-variables.zh.mdx b/apps/docs/content/docs/environment-variables.zh.mdxindex 245ece0572..ca0243b468 100644--- a/apps/docs/content/docs/environment-variables.zh.mdx+++ b/apps/docs/content/docs/environment-variables.zh.mdx@@ -123,6 +123,10 @@ MULTICA_PUBLIC_URL=https://api.multica.example.com没有设置 `S3_BUCKET` 时,Multica 使用本地磁盘。+| 变量 | 默认值 | 说明 |+|---|---|---|+| `MULTICA_MAX_PREVIEW_SIZE` | `2MiB` | 文本和 HTML 在线预览的正文大小上限,最大 `16MiB`。支持正整数字节数或 `KB`/`KiB`、`MB`/`MiB`(均按二进制单位计算)。超过 `16MiB` 的有效值截断为 `16MiB`,非法值回退到默认值。调大上限可能拖慢浏览器预览,尤其是语法高亮和 Markdown 渲染。修改后需重启 API;不改变上传或下载限制。 |+### S3 或兼容存储| 变量 | 默认值 | 说明 |diff --git a/deploy/helm/multica/templates/configmap.yaml b/deploy/helm/multica/templates/configmap.yamlindex 9912863cb0..b6cf25d077 100644--- a/deploy/helm/multica/templates/configmap.yaml+++ b/deploy/helm/multica/templates/configmap.yaml@@ -31,6 +31,7 @@ data:S3_REGION: {{ .Values.backend.config.s3Region | quote }}CLOUDFRONT_DOMAIN: {{ .Values.backend.config.cloudfrontDomain | quote }}CLOUDFRONT_KEY_PAIR_ID: {{ .Values.backend.config.cloudfrontKeyPairId | quote }}+ MULTICA_MAX_PREVIEW_SIZE: {{ .Values.backend.config.maxPreviewSize | quote }}LOCAL_UPLOAD_BASE_URL: {{ .Values.backend.config.localUploadBaseUrl | quote }}{{- if not .Values.postgres.external.enabled }}diff --git a/deploy/helm/multica/values.yaml b/deploy/helm/multica/values.yamlindex ce8bf8c73a..2d3efd3b6f 100644--- a/deploy/helm/multica/values.yaml+++ b/deploy/helm/multica/values.yaml@@ -170,6 +170,9 @@ backend:s3Region: us-west-2cloudfrontDomain: ""cloudfrontKeyPairId: ""+ # Text/HTML preview size only; values above 16 MiB are clamped.+ # Larger limits can slow browser previews.+ maxPreviewSize: 2MiBlocalUploadBaseUrl: http://api.multica.dev.lanresources:requests:diff --git a/docker-compose.selfhost.yml b/docker-compose.selfhost.ymlindex 97823391be..9b89bac181 100644--- a/docker-compose.selfhost.yml+++ b/docker-compose.selfhost.yml@@ -96,6 +96,7 @@ services:AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY:-}ATTACHMENT_DOWNLOAD_MODE: ${ATTACHMENT_DOWNLOAD_MODE:-auto}ATTACHMENT_DOWNLOAD_URL_TTL: ${ATTACHMENT_DOWNLOAD_URL_TTL:-30m}+ MULTICA_MAX_PREVIEW_SIZE: ${MULTICA_MAX_PREVIEW_SIZE:-2MiB}CLOUDFRONT_DOMAIN: ${CLOUDFRONT_DOMAIN:-}CLOUDFRONT_KEY_PAIR_ID: ${CLOUDFRONT_KEY_PAIR_ID:-}CLOUDFRONT_PRIVATE_KEY: ${CLOUDFRONT_PRIVATE_KEY:-}diff --git a/packages/core/api/client.ts b/packages/core/api/client.tsindex 9866a8f145..66cd2a0664 100644--- a/packages/core/api/client.ts+++ b/packages/core/api/client.ts@@ -659,7 +659,7 @@ export function clientErrorMessage(err: unknown): string | undefined {}// Thrown by getAttachmentTextContent when the server refuses to inline a-// file because it exceeds the 2 MB cap. UI maps to a "too large, please+// file because it exceeds the server-configured preview limit. UI maps to a "too large, please// download" affordance with the Download CTA still available.export class PreviewTooLargeError extends Error {constructor() {diff --git a/scripts/helm-config.test.sh b/scripts/helm-config.test.shindex b4f70b7702..2e560b8d9c 100644--- a/scripts/helm-config.test.sh+++ b/scripts/helm-config.test.sh@@ -36,6 +36,13 @@ require_rendered_value "$default_config" 'MULTICA_VCS_INTEGRATION_ENABLED: "truerequire_rendered_value "$default_config" 'MULTICA_CLOUD_URL: ""'require_rendered_value "$default_config" 'MULTICA_DATABASE_STARTUP_TIMEOUT: "3m"'require_rendered_value "$default_config" 'MULTICA_DATABASE_CONNECT_TIMEOUT: "5s"'+require_rendered_value "$default_config" 'MULTICA_MAX_PREVIEW_SIZE: "2MiB"'+preview_config="$(+ helm template multica "$CHART_DIR" \+ --show-only templates/configmap.yaml \+ --set-string backend.config.maxPreviewSize=8MiB+)"+require_rendered_value "$preview_config" 'MULTICA_MAX_PREVIEW_SIZE: "8MiB"'require_rendered_value "$default_config" 'MAINTENANCE_PORT: ""'maintenance_config="$(helm template multica "$CHART_DIR" --show-only templates/configmap.yaml --set-string backend.config.maintenancePort=6061)"diff --git a/server/cmd/server/router.go b/server/cmd/server/router.goindex 4418251b34..ac6cd49dc5 100644--- a/server/cmd/server/router.go+++ b/server/cmd/server/router.go@@ -21,6 +21,7 @@ import ("github.com/redis/go-redis/v9""github.com/multica-ai/multica/server/internal/analytics"+ "github.com/multica-ai/multica/server/internal/attachmentpreview""github.com/multica-ai/multica/server/internal/auth""github.com/multica-ai/multica/server/internal/cloudruntime""github.com/multica-ai/multica/server/internal/daemonws"@@ -440,6 +441,7 @@ func NewRouterWithOptions(pool *pgxpool.Pool, hub *realtime.Hub, bus *events.BusCloudTimeout: 35 * time.Second,AttachmentDownloadMode: os.Getenv("ATTACHMENT_DOWNLOAD_MODE"),AttachmentDownloadURLTTL: envDuration("ATTACHMENT_DOWNLOAD_URL_TTL", 30*time.Minute),+ MaxPreviewSizeBytes: attachmentpreview.ConfiguredMaxSizeBytes(os.Getenv("MULTICA_MAX_PREVIEW_SIZE")),AttachmentFrameAncestors: origins,PluginSurfaceOrigin: strings.TrimRight(strings.TrimSpace(os.Getenv("MULTICA_PLUGIN_SURFACE_ORIGIN")), "/"),LLMAPIKey: strings.TrimSpace(os.Getenv("MULTICA_LLM_API_KEY")),diff --git a/server/internal/attachmentpreview/size.go b/server/internal/attachmentpreview/size.gonew file mode 100644index 0000000000..7181dec9ba--- /dev/null+++ b/server/internal/attachmentpreview/size.go@@ -0,0 +1,62 @@+package attachmentpreview++import (+ "fmt"+ "log/slog"+ "strconv"+ "strings"+)++const (+ DefaultMaxSizeBytes int64 = 2 << 20+ // Text previews buffer the complete body and render it in the browser.+ MaxSizeBytes int64 = 16 << 20+)++func ConfiguredMaxSizeBytes(raw string) int64 {+ size, err := parseMaxSizeBytes(raw)+ if err != nil {+ slog.Warn("invalid MULTICA_MAX_PREVIEW_SIZE, using 2 MiB default", "error", err)+ return DefaultMaxSizeBytes+ }+ return size+}++// parseMaxSizeBytes accepts positive integer bytes, KB/KiB, or MB/MiB.+// KB and MB use binary units, matching the existing attachment size limits.+func parseMaxSizeBytes(raw string) (int64, error) {+ value := strings.TrimSpace(raw)+ if value == "" {+ return DefaultMaxSizeBytes, nil+ }+ i := 0+ for i < len(value) && value[i] >= '0' && value[i] <= '9' {+ i+++ }+ n, err := strconv.ParseInt(value[:i], 10, 64)+ if err != nil || n <= 0 {+ return 0, fmt.Errorf("preview size must be a positive integer")+ }+ multiplier := int64(1)+ switch strings.ToLower(strings.TrimSpace(value[i:])) {+ case "", "b":+ case "kb", "kib":+ multiplier = 1 << 10+ case "mb", "mib":+ multiplier = 1 << 20+ default:+ return 0, fmt.Errorf("preview size must use bytes, KB/KiB, or MB/MiB")+ }+ // Clamp before multiplying so even extreme valid values cannot overflow.+ if n > MaxSizeBytes/multiplier {+ return MaxSizeBytes, nil+ }+ return n * multiplier, nil+}++func EffectiveMaxSizeBytes(size int64) int64 {+ if size <= 0 {+ return DefaultMaxSizeBytes+ }+ return min(size, MaxSizeBytes)+}diff --git a/server/internal/attachmentpreview/size_test.go b/server/internal/attachmentpreview/size_test.gonew file mode 100644index 0000000000..c61a0531c7--- /dev/null+++ b/server/internal/attachmentpreview/size_test.go@@ -0,0 +1,62 @@+package attachmentpreview++import "testing"++func TestConfiguredMaxSizeBytes(t *testing.T) {+ for _, tc := range []struct {+ raw string+ want int64+ }{+ {"", 2 << 20}, {"8MiB", 8 << 20}, {"16MiB", 16 << 20},+ {"invalid", 2 << 20}, {"17MiB", 16 << 20}, {"32MiB", 16 << 20},+ {"9223372036854775807", 16 << 20}, {"9223372036854775808", 2 << 20},+ } {+ t.Run(tc.raw, func(t *testing.T) {+ if got := ConfiguredMaxSizeBytes(tc.raw); got != tc.want {+ t.Fatalf("ConfiguredMaxSizeBytes(%q) = %d, want %d", tc.raw, got, tc.want)+ }+ })+ }+}++func TestParseMaxSizeBytes(t *testing.T) {+ for _, tc := range []struct {+ raw string+ want int64+ }{+ {"", 2 << 20}, {" ", 2 << 20}, {"1", 1}, {"4096B", 4096},+ {"8KB", 8192}, {"8KiB", 8192}, {"8MB", 8 << 20},+ {" 8 MiB ", 8 << 20}, {"16mib", 16 << 20}, {"16777216", 16 << 20},+ {"17MiB", 16 << 20}, {"32MiB", 16 << 20}, {"16777217", 16 << 20},+ {"9223372036854775807", 16 << 20}, {"9223372036854775807MiB", 16 << 20},+ } {+ t.Run(tc.raw, func(t *testing.T) {+ got, err := parseMaxSizeBytes(tc.raw)+ if err != nil || got != tc.want {+ t.Fatalf("parseMaxSizeBytes(%q) = %d, %v; want %d", tc.raw, got, err, tc.want)+ }+ })+ }+ for _, raw := range []string{"0", "-1", "+1", "1.5MiB", "MiB", "16watts", "1GiB", "9223372036854775808"} {+ t.Run(raw, func(t *testing.T) {+ if _, err := parseMaxSizeBytes(raw); err == nil {+ t.Fatalf("parseMaxSizeBytes(%q) accepted invalid value", raw)+ }+ })+ }+}++func TestEffectiveMaxSizeBytes(t *testing.T) {+ for _, tc := range []struct {+ size int64+ want int64+ }{+ {0, 2 << 20}, {-1, 2 << 20}, {1, 1}, {8 << 20, 8 << 20},+ {16 << 20, 16 << 20}, {(16 << 20) + 1, 16 << 20},+ {32 << 20, 16 << 20}, {1<<63 - 1, 16 << 20},+ } {+ if got := EffectiveMaxSizeBytes(tc.size); got != tc.want {+ t.Fatalf("EffectiveMaxSizeBytes(%d) = %d, want %d", tc.size, got, tc.want)+ }+ }+}diff --git a/server/internal/handler/file.go b/server/internal/handler/file.goindex 2282f28e5f..bf9ae17867 100644--- a/server/internal/handler/file.go+++ b/server/internal/handler/file.go@@ -48,12 +48,6 @@ const (attachmentDownloadModeProxy attachmentDownloadMode = "proxy")-// maxPreviewTextSize caps the body the preview proxy will load into memory-// for text-based types. Anything larger returns 413 and the UI falls back-// to "please download". Sized so a typical README/source-file fits but a-// 100 MB log dump can't blow up the renderer.-const maxPreviewTextSize = 2 << 20 // 2 MB-// Response typestype AttachmentResponse struct {@@ -1283,8 +1277,8 @@ func normalizeFrameAncestorSource(raw string) (string, bool) {// the explicit /download route signs redirects as attachment downloads and// proxy mode streams with the same media-type policy as storage uploads.//-// Hard cap: 2 MB. Larger files return 413. Anything outside the text-// whitelist returns 415.+// Files above the configured preview limit return 413. Anything outside the+// text whitelist returns 415.func (h *Handler) GetAttachmentContent(w http.ResponseWriter, r *http.Request) {att, ok := h.loadAttachmentForRequest(w, r)@@ -1302,6 +1296,11 @@ func (h *Handler) GetAttachmentContent(w http.ResponseWriter, r *http.Request) {writeFeatureDisabled(w, "storage_not_configured", "storage not configured")return}+ limit := h.maxPreviewSizeBytes()+ if att.SizeBytes > limit {+ writeError(w, http.StatusRequestEntityTooLarge, "file too large for inline preview")+ return+ }key := h.Storage.KeyFromURL(att.Url)reader, err := h.Storage.GetReader(r.Context(), key)if err != nil {@@ -1311,15 +1310,15 @@ func (h *Handler) GetAttachmentContent(w http.ResponseWriter, r *http.Request) {}defer reader.Close()- // LimitReader to maxPreviewTextSize+1 so we can detect "exactly at the- // limit" vs "exceeds the limit" by checking the returned length.- body, err := io.ReadAll(io.LimitReader(reader, maxPreviewTextSize+1))+ // Check actual bytes as well as metadata. The hard maximum keeps limit+1+ // safe, while the extra byte distinguishes the exact boundary from overflow.+ body, err := io.ReadAll(io.LimitReader(reader, limit+1))if err != nil {slog.Error("failed to read attachment body for preview", "id", attachmentID, "error", err)writeError(w, http.StatusBadGateway, "failed to read attachment body")return}- if len(body) > maxPreviewTextSize {+ if int64(len(body)) > limit {writeError(w, http.StatusRequestEntityTooLarge, "file too large for inline preview")return}@@ -1332,7 +1331,7 @@ func (h *Handler) GetAttachmentContent(w http.ResponseWriter, r *http.Request) {// No-store: workspace membership / attachment ACL can change between// requests (member removed, attachment deleted). A cached body would// stay readable past the revocation window. The redundant request is- // fine here — bodies are capped at 2 MB and the endpoint is only hit+ // fine here — bodies are bounded by the preview limit and the endpoint is only hit// when a user explicitly opens a preview.w.Header().Set("Cache-Control", "no-store")w.Header().Set("X-Content-Type-Options", "nosniff")diff --git a/server/internal/handler/file_test.go b/server/internal/handler/file_test.goindex 8bdd4d4b8e..f283a318cc 100644--- a/server/internal/handler/file_test.go+++ b/server/internal/handler/file_test.go@@ -23,6 +23,7 @@ import ("time""github.com/go-chi/chi/v5"+ "github.com/multica-ai/multica/server/internal/attachmentpreview""github.com/multica-ai/multica/server/internal/auth""github.com/multica-ai/multica/server/internal/storage""github.com/multica-ai/multica/server/internal/testutil"@@ -1642,7 +1643,7 @@ func TestGetAttachmentContent_TooLarge(t *testing.T) {defer func() { testHandler.Storage = origStorage }()// One byte over the limit. Allocate ASCII so io.ReadAll has work to do.- big := bytes.Repeat([]byte("a"), maxPreviewTextSize+1)+ big := bytes.Repeat([]byte("a"), int(attachmentpreview.DefaultMaxSizeBytes)+1)id := seedPreviewAttachment(t, store, "huge-key.txt", "huge.txt", "text/plain", big)req, w := newPreviewRequest(t, id, testWorkspaceID)@@ -1652,6 +1653,55 @@ func TestGetAttachmentContent_TooLarge(t *testing.T) {}}+func TestGetAttachmentContent_ConfiguredLimit(t *testing.T) {+ for _, tc := range []struct {+ name string+ limit int64+ size int+ recordedSize int64+ status int+ }{+ {"default exact", 0, 2 << 20, 2 << 20, http.StatusOK},+ {"default over", 0, (2 << 20) + 1, (2 << 20) + 1, http.StatusRequestEntityTooLarge},+ {"larger HTML", 8 << 20, 3 << 20, 3 << 20, http.StatusOK},+ {"custom exact", 8 << 20, 8 << 20, 8 << 20, http.StatusOK},+ {"custom over", 8 << 20, (8 << 20) + 1, (8 << 20) + 1, http.StatusRequestEntityTooLarge},+ {"smaller exact", 1024, 1024, 1024, http.StatusOK},+ {"underreported body", 1024, 1025, 1, http.StatusRequestEntityTooLarge},+ {"oversized metadata", 1024, 1, 1025, http.StatusRequestEntityTooLarge},+ {"maximum exact", 16 << 20, 16 << 20, 16 << 20, http.StatusOK},+ {"clamped maximum exact", 32 << 20, 16 << 20, 16 << 20, http.StatusOK},+ {"clamped maximum over", 32 << 20, (16 << 20) + 1, 1, http.StatusRequestEntityTooLarge},+ } {+ t.Run(tc.name, func(t *testing.T) {+ store := &mockStorage{}+ h := *testHandler+ h.Storage = store+ h.cfg.MaxPreviewSizeBytes = tc.limit+ body := bytes.Repeat([]byte("a"), tc.size)+ copy(body, "<!doctype html><h1>Preview size test</h1>")+ id := seedPreviewAttachment(t, store, "configured-preview.html", "preview.html", "text/html", body)+ if _, err := testPool.Exec(context.Background(), "UPDATE attachment SET size_bytes = $1 WHERE id = $2", tc.recordedSize, id); err != nil {+ t.Fatal(err)+ }+ req, w := newPreviewRequest(t, id, testWorkspaceID)+ h.GetAttachmentContent(w, req)+ if w.Code != tc.status {+ t.Fatalf("status = %d, want %d", w.Code, tc.status)+ }+ if tc.status == http.StatusOK {+ if !bytes.Equal(w.Body.Bytes(), body) {+ t.Fatal("preview did not preserve the complete body")+ }+ if w.Header().Get("Content-Type") != "text/plain; charset=utf-8" || w.Header().Get("X-Original-Content-Type") != "text/html" {+ t.Fatal("HTML preview content-type isolation changed")+ }+ requireAttachmentPreviewCSP(t, w.Header())+ }+ })+ }+}+func TestGetAttachmentContent_ForeignWorkspace(t *testing.T) {store := &mockStorage{}origStorage := testHandler.Storagediff --git a/server/internal/handler/handler.go b/server/internal/handler/handler.goindex 9df440adb5..de551221c1 100644--- a/server/internal/handler/handler.go+++ b/server/internal/handler/handler.go@@ -123,6 +123,9 @@ type Config struct {CloudTimeout time.DurationAttachmentDownloadMode stringAttachmentDownloadURLTTL time.Duration+ // MaxPreviewSizeBytes bounds text-backed attachment previews independently+ // of upload/download limits. Zero selects the default 2 MiB limit.+ MaxPreviewSizeBytes int64// AttachmentFrameAncestors are trusted browser origins allowed to embed// attachment preview responses. In production this should mirror the// frontend/CORS origin allowlist so split app/api self-hosted deploymentsdiff --git a/server/internal/handler/preview_size.go b/server/internal/handler/preview_size.gonew file mode 100644index 0000000000..f416233114--- /dev/null+++ b/server/internal/handler/preview_size.go@@ -0,0 +1,7 @@+package handler++import "github.com/multica-ai/multica/server/internal/attachmentpreview"++func (h *Handler) maxPreviewSizeBytes() int64 {+ return attachmentpreview.EffectiveMaxSizeBytes(h.cfg.MaxPreviewSizeBytes)+}