Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix: allow framed attachment redirects (#4635)
Bohan Jiang24754f091b59
diff --git a/server/internal/handler/file.go b/server/internal/handler/file.goindex 7c3e1377e3..0f7e2376c8 100644--- a/server/internal/handler/file.go+++ b/server/internal/handler/file.go@@ -633,6 +633,7 @@ func (h *Handler) DownloadAttachment(w http.ResponseWriter, r *http.Request) {writeError(w, http.StatusInternalServerError, "cloudfront attachment downloads are not configured")return}+ h.setAttachmentPreviewSecurityHeaders(w)http.Redirect(w,r,@@ -660,6 +661,7 @@ func (h *Handler) DownloadAttachment(w http.ResponseWriter, r *http.Request) {writeError(w, http.StatusBadGateway, "failed to create download URL")return}+ h.setAttachmentPreviewSecurityHeaders(w)http.Redirect(w, r, signedURL, http.StatusFound)case attachmentDownloadModeProxy:h.proxyAttachmentDownload(w, r, att, key)diff --git a/server/internal/handler/file_test.go b/server/internal/handler/file_test.goindex 8ece0d084f..1eeacbb48d 100644--- a/server/internal/handler/file_test.go+++ b/server/internal/handler/file_test.go@@ -561,6 +561,7 @@ func TestDownloadAttachment_CloudFrontRedirectSignsAttachmentDisposition(t *testorigSigner := testHandler.CFSignertestHandler.Storage = &mockStorage{}testHandler.cfg.AttachmentDownloadMode = "cloudfront"+ testHandler.cfg.AttachmentFrameAncestors = []string{"https://app.example.test"}testHandler.CFSigner = testCloudFrontSigner(t)t.Cleanup(func() {testHandler.Storage = origStorage@@ -571,6 +572,7 @@ func TestDownloadAttachment_CloudFrontRedirectSignsAttachmentDisposition(t *testid := seedAttachmentURL(t, "https://static.example.test/downloads/cloudfront.md", "cloud front.md", "text/markdown", 10)req, w := newDownloadRequest(t, id, testWorkspaceID)+ w.Header().Set("Content-Security-Policy", "default-src 'self'; frame-ancestors 'none'")testHandler.DownloadAttachment(w, req)if w.Code != http.StatusFound {@@ -587,6 +589,7 @@ func TestDownloadAttachment_CloudFrontRedirectSignsAttachmentDisposition(t *testif got := parsed.Query().Get("Key-Pair-Id"); got != "KTEST" {t.Fatalf("Key-Pair-Id = %q", got)}+ requireAttachmentPreviewCSP(t, w.Header(), "https://app.example.test")}func TestDownloadAttachment_BareNavigationWithWorkspaceSlugQueryPassesMiddleware(t *testing.T) {@@ -788,6 +791,7 @@ func TestDownloadAttachment_AutoPublicEndpointPresigns(t *testing.T) {origSigner := testHandler.CFSignertestHandler.Storage = storetestHandler.cfg.AttachmentDownloadMode = "auto"+ testHandler.cfg.AttachmentFrameAncestors = []string{"https://app.example.test"}testHandler.CFSigner = nilt.Cleanup(func() {testHandler.Storage = origStorage@@ -799,6 +803,7 @@ func TestDownloadAttachment_AutoPublicEndpointPresigns(t *testing.T) {id := seedAttachmentURL(t, "https://s3.example.com/test-bucket/"+key, "public.txt", "text/plain", 10)req, w := newDownloadRequest(t, id, testWorkspaceID)+ w.Header().Set("Content-Security-Policy", "default-src 'self'; frame-ancestors 'none'")testHandler.DownloadAttachment(w, req)if w.Code != http.StatusFound {@@ -821,6 +826,7 @@ func TestDownloadAttachment_AutoPublicEndpointPresigns(t *testing.T) {if len(store.presignDispositions) != 1 || store.presignDispositions[0] != `attachment; filename="public.txt"` {t.Fatalf("presign dispositions = %v", store.presignDispositions)}+ requireAttachmentPreviewCSP(t, w.Header(), "https://app.example.test")}func TestDownloadAttachment_ExplicitProxyStreamsPublicEndpoint(t *testing.T) {