You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Design: resize remote photos before they reach the canvas - #9855
Designs with big camera photos shown as small thumbnails stutter when you pan, because Chrome decodes every full-size image while the canvas moves. Canvas frames now load remote images through a new endpoint that resizes them to at most 2048 px, and the original URLs are put back before anything is saved or exported.
Panning on design 9DaCvN3lsBHVCC3ygOVnK, production builds, 6 runs each:
main this branch
p95 frame 102-110 ms 9-10 ms
frames over 50 ms per run 4-8 0
What changes
1. Canvas images go through a resize proxy.
Remote <img>src/srcset and <picture> sources in canvas frames, interact previews and thumbnails point at /api/canvas-image instead of the original. A small script in the frame handles images added later, and falls back to the original URL if the proxy fails, so the worst case is the same as main. Private and local hosts are left alone.
<img src="https://images.example.test/photo.jpg">
-> in the frame
<img src="/api/canvas-image?src=https%3A%2F%2Fimages.example.test%2Fphoto.jpg&w=2048&u=…&exp=…&t=…">
One cost: on a cold cache the endpoint has to download the full original first, so screens with heavy photos finish loading a few seconds later. First paint is the same.
2. The /api/canvas-image endpoint.
Fetches through ssrfSafeFetch (private addresses get 403), resizes with sharp, and caps input at 40 MB / 100 MP. Images that are already small pass through untouched. Successful resizes are cached for a day, shared across Netlify edges (durable); failures aren't cached. Adds sharp to the Design template.
3. The endpoint requires a signed token.
Canvas frames can't send cookies, so the route is public, and without a check it would be an open image proxy. The editor now calls a get-canvas-image-token action once per load (signed-in users only) and appends the token to every proxy URL. The endpoint checks it before fetching anything and returns an uncached 403 otherwise. The token expires at UTC midnight and identifies the user by a hash, never the email. The CDN caches on src and w only (Netlify-Vary: query=src|w), so cached images are shared across users and tokens.
No token (signed out, shared link viewer, secret not set) means no rewrite: images load from their original URLs like on main.
Deploy: set DESIGN_CANVAS_IMAGE_SECRET (32+ chars, e.g. openssl rand -hex 32) on beta and production. Without it the proxy is off on hosted deploys. Local dev uses a random key per process.
4. Proxy URLs never get saved.
Saving, bridge messages, snapshot export and clipboard all turn proxy URLs (token included) back into the originals. PNG export uses the full-size original, not the 2048 px copy.
<img src="/api/canvas-image?src=…photo.jpg&w=2048&u=…&exp=…&t=…">
-> saved as
<img src="https://images.example.test/photo.jpg">
5. Typed "too large" error in core. readBoundedResponseBytes throws an exported RemoteArtifactTooLargeError so the endpoint can return 413 without matching the message. Changeset included.
The reason will be displayed to describe this comment to others. Learn more.
Approved under Steve’s standing instruction for verified BuilderIO members. This approval records that instruction and carries no independent review or merge-readiness assessment.
The reason will be displayed to describe this comment to others. Learn more.
Approved under Steve’s standing instruction for verified BuilderIO members. This approval records that instruction and carries no independent review or merge-readiness assessment.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Unresolved image-proxy defects can corrupt exported HTML, leak signed tokens into clipboard data, leave previews using stale credentials, alter background rendering, and cache failure responses.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Active issues include an HTML round-trip that enables event-handler injection, cross-realm image exports retaining resized proxy URLs, and image rewriting that changes intrinsic layout.
Every remote <img> is rewritten, including images whose layout uses their intrinsic dimensions. An image with no authored width, height or CSS sizing changes from 4096×2048 to 2048×1024, shrinking the element and moving surrounding content; restoring the original for export then produces a different layout. Preserve the original intrinsic geometry or leave intrinsically sized images untouched, including in the bootstrap's dynamic rewrite at lines 467–469.
Detect cross-realm root elements when preparing image exports
The host PNG-export path passes images cloned from a canvas iframe, so root instanceof Element is false for those cross-realm clones. Because querySelectorAll() excludes the root, a standalone <img> retains its proxy URLs and export preparation decodes the resized asset instead of the original. Use a realm-independent element check and regenerate templates/design/.generated/bridge/editor-chrome.generated.ts.
The reason will be displayed to describe this comment to others. Learn more.
Approved under Steve’s standing instruction for verified BuilderIO members. This approval records that instruction and carries no independent review or merge-readiness assessment.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Active issues include critical corruption of foreign protocol-relative URLs, altered image geometry, invalid CSS URL restoration, and an oversized-response rejection path that leaves the upstream body open.
No open issues 🎉
4 previously missed issues
In code that hasn't changed since last review
Check protocol-relative image URLs against the resolved origin
The matcher treats a foreign protocol-relative authority as part of a relative proxy path: //other.example.com/api/canvas-image?src=https%3A%2F%2Fimages.example.com%2Fphoto.jpg&w=2048 becomes /https://images.example.com/photo.jpg. Canonical source preparation therefore corrupts this authored URL on opening or saving, even though it was never rewritten. Recognize protocol-relative authorities and check their resolved origin before restoring them.
Cancel oversized response bodies before returning 413
When Content-Length exceeds 40 MB, readBoundedResponseBytes throws before reading or cancelling the response body (packages/core/src/ingestion/media.ts:259–261). Returning 413 here therefore leaves the upstream response open until the fetch timeout instead of releasing it immediately. Cancel the body on this rejection path, as the earlier content-type and upstream-status rejection paths already do.
Preserve intrinsic sizing when rewriting remote images
Every remote <img> is rewritten even when its layout depends on intrinsic dimensions: an unsized 4096×2048 image becomes 2048×1024 on the canvas, while exports restore the larger layout. Unchanged srcset density descriptors and object-fit: none can also change sizing or cropping. Preserve the original display geometry or skip images whose rendering depends on intrinsic dimensions, in both the markup rewrite and frame bootstrap.
Escape restored CSS URLs in computed background values
For an authored background such as url('https://images.example.com/a"b.jpg'), restoring the double-quoted computed proxy value produces invalid CSS: url("https://images.example.com/a"b.jpg"). Portable-style snapshots and bridge messages carry that broken value, so copying or moving the layer can lose its background. Restore CSS URLs with CSS-string escaping separately from bare URLs and serialized HTML.
The reason will be displayed to describe this comment to others. Learn more.
Approved under Steve’s standing instruction for verified BuilderIO members. This approval records that instruction and carries no independent review or merge-readiness assessment.
The reason will be displayed to describe this comment to others. Learn more.
Approved under Steve’s standing instruction for verified BuilderIO members. This approval records that instruction and carries no independent review or merge-readiness assessment.
Read through this with an eye on what ends up in design_files.content, since Design checkpoints now hash each screen's saved HTML (#9731). The restore holds on every path I traced. There's one place where nothing on the server catches a mistake. The risk is low today and I'm not asking to block on it, but the fix is small.
Every editor write runs prepareCanonicalSourceContent before writing, which calls restoreCanvasImageUrls: apply-file-content-update.ts, apply-local-content-update.ts, both writeCollabText calls in commit-visual-styles.ts, undo/redo, and the editor's prepared file list.
writeInlineSourceFile and writeInlineSourceFilesBatch run restoreSignedCanvasImageUrls, so update-file (including queued browser saves replayed from IndexedDB) and the agent source-edit actions are covered.
Cross-screen drag (MultiScreenCanvas.tsx, the captureCrossScreenSourceHtmlSnapshot(sourcePreviewIframe.contentDocument, ...) call) reads the live iframe DOM without restoring. The result goes through applyFileContentUpdate, so the restore at that boundary catches it.
I round-tripped 14 markup cases through withCanvasImageSizing and then restoreCanvasImageUrls, restoreSignedCanvasImageUrls, and a jsdom parse/serialize. All of them came back identical: plain URLs, & queries, srcset, inline background-image, <style> blocks, spaces, unicode, parentheses, +, fragments, protocol-relative. The one exception is cosmetic: a raw & in the original (?w=800&q=80) comes back as & from the markup restore. That's the same URL to the browser, and DOM serialization already does this on main, so I'm not asking for a change.
The gap: collaborative text has no server-side restore.
Live edits are written into the screen's Y.Text (writeCollabText). The collab layer saves that text to _collab_docs.text_snapshot, and it eventually lands in design_files.content. As far as I can tell, that path never goes through writeInlineSourceFile, so restoreSignedCanvasImageUrls doesn't run on it. I didn't trace the exact function that copies collab text back into design_files. Please confirm.
Why the risk is low: only a handful of call sites write Y.Text directly, they all canonicalize first, and new editor commands normally go through applyFileContentUpdate / applyLocalContentUpdate, which already restore. A leak needs a new direct writeCollabText call fed with markup read from the live canvas.
Why it's still worth closing: nothing enforces the convention, and since this PR any markup serialized from the live canvas contains proxy URLs. Before this PR that markup was safe to write back, so existing patterns don't account for it. If a future command does write it to Y.Text without prepareCanonicalSourceContent, it fails silently:
Proxy URLs carrying u, exp and t are stored in _collab_docs.text_snapshot, then in design_files.content.
The token is persisted, then copied into version history, exports and anything that reads source.
The token expires at UTC midnight. The saved HTML then points at a proxy URL that 403s, and outside the canvas (exports, shared links, other apps) nothing falls back to the original.
Design checkpoints read _collab_docs.text_snapshot directly for unsaved collaborative edits, and store screens by content hash. A leaked token makes an unchanged screen hash differently every day, so each checkpoint stores a fresh copy of it.
Suggested fix, smallest first:
Run the restore inside writeCollabText itself (app/pages/design-editor/collab-sync.ts), so no caller can skip it. It's a no-op on clean text (it returns early when /api/canvas-image isn't in the string).
Or, stronger: run restoreSignedCanvasImageUrls on the server where collab text is accepted or copied into design_files, the same way writeInlineSourceFile already does. That also covers clients other than the editor.
Add a test either way: write collab text containing a signed proxy URL, let it persist, then assert design_files.content holds the original URL and contains no t=.
Fine as a quick follow-up if you'd rather ship this first. Nothing leaks with today's code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Designs with big camera photos shown as small thumbnails stutter when you pan, because Chrome decodes every full-size image while the canvas moves. Canvas frames now load remote images through a new endpoint that resizes them to at most 2048 px, and the original URLs are put back before anything is saved or exported.
Panning on design
9DaCvN3lsBHVCC3ygOVnK, production builds, 6 runs each:What changes
1. Canvas images go through a resize proxy.
Remote
<img>src/srcsetand<picture>sources in canvas frames, interact previews and thumbnails point at/api/canvas-imageinstead of the original. A small script in the frame handles images added later, and falls back to the original URL if the proxy fails, so the worst case is the same as main. Private and local hosts are left alone.One cost: on a cold cache the endpoint has to download the full original first, so screens with heavy photos finish loading a few seconds later. First paint is the same.
2. The
/api/canvas-imageendpoint.Fetches through
ssrfSafeFetch(private addresses get 403), resizes withsharp, and caps input at 40 MB / 100 MP. Images that are already small pass through untouched. Successful resizes are cached for a day, shared across Netlify edges (durable); failures aren't cached. Addssharpto the Design template.3. The endpoint requires a signed token.
Canvas frames can't send cookies, so the route is public, and without a check it would be an open image proxy. The editor now calls a
get-canvas-image-tokenaction once per load (signed-in users only) and appends the token to every proxy URL. The endpoint checks it before fetching anything and returns an uncached 403 otherwise. The token expires at UTC midnight and identifies the user by a hash, never the email. The CDN caches onsrcandwonly (Netlify-Vary: query=src|w), so cached images are shared across users and tokens.No token (signed out, shared link viewer, secret not set) means no rewrite: images load from their original URLs like on main.
Deploy: set
DESIGN_CANVAS_IMAGE_SECRET(32+ chars, e.g.openssl rand -hex 32) on beta and production. Without it the proxy is off on hosted deploys. Local dev uses a random key per process.4. Proxy URLs never get saved.
Saving, bridge messages, snapshot export and clipboard all turn proxy URLs (token included) back into the originals. PNG export uses the full-size original, not the 2048 px copy.
5. Typed "too large" error in core.
readBoundedResponseBytesthrows an exportedRemoteArtifactTooLargeErrorso the endpoint can return 413 without matching the message. Changeset included.