fix(desktop): allow R2 in the renderer CSP so cloud attachments upload
Problem
Attaching an image in the new-workspace modal for a cloud workspace has failed since #7633. The renderer PUTs the bytes straight to a presigned R2 URL, and the renderer CSP's connect-src never listed R2's S3 endpoint, so Chromium blocks the request:
Connecting to 'https://.r2.cloudflarestorage.com/…' violates the following Content Security Policy directive: "connect-src …"
Mobile (#7378) and the CLI do the same PUT with no CSP, which is why only the desktop broke.
Fix
Add https://*.r2.cloudflarestorage.com to connect-src in apps/desktop/src/renderer/index.html. A presigned PUT is only valid on the S3 API host; an R2 custom domain serves GET/HEAD only, and routing uploads through the usercontent Worker would push 200 MB attachments through Cloudflare's 100 MB edge body limit (the reason the direct PUT exists). The wildcard keeps the account id out of the client bundle.
Verification
Driven over CDP against this worktree's dev renderer on the new-workspace route, with a securitypolicyviolation listener and a PUT to an R2 host:
| index.html | violation event | fetch |
|---|---|---|
| HEAD | fired, connect-src, R2 URL blocked | Failed to fetch |
| this PR | none | Failed to fetch (DNS, fake dev account) |
Not exercised: the upload landing in the bucket. Local dev has fake R2 credentials, so the PUT cannot reach real storage from here. The packaged app runs from a file:// origin, so the private bucket needs a CORS rule permitting PUT + content-type from it; that lives in the Cloudflare dashboard, not this repo.
Summary by cubic
Fixes cloud workspace image attachments in the desktop app failing since #7633, when the renderer's PUT to a presigned R2 URL was blocked by the CSP connect-src directive. Adds https://*.r2.cloudflarestorage.com to connect-src in apps/desktop/src/renderer/index.html.
A presigned PUT only works on the S3 API host; an R2 custom domain serves GET/HEAD only, and routing uploads through the usercontent Worker would exceed Cloudflare's 100 MB edge body limit. The wildcard keeps the account id out of the client bundle.
Summary by CodeRabbit
- Bug Fixes
- Cloud-workspace attachments can now connect to Cloudflare R2 storage using secure upload links, including before a workspace sandbox is available. This supports uploading attachments during workspace setup, so users don’t have to wait for the sandbox to be ready before the upload can proceed.