Skip to content

feat(design): native Figma transfer and FigCraft copy/paste - #1103

Open
eliasx45 wants to merge 11 commits into
storytold:mainfrom
eliasx45:upstream/figma-transfer
Open

eliasx45 wants to merge 11 commits into
storytold:mainfrom
eliasx45:upstream/figma-transfer

Conversation

@eliasx45

@eliasx45 eliasx45 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What

Transfer designs into native, editable EffectCraft layers from Figma or FigCraft. This extends the existing Figma transfer contribution (the Figma part of #858) with one-time FigCraft Copy/Paste and shared rendering fixes.

  • Figma: file.importFigma accepts node JSON from the transfer plug-in/MCP, or a Figma link through the REST API. The plug-in in integrations/figma/plugin uses the local effectcraft-cli figma-bridge HTTP endpoint to forward into the app's control channel. Supported shapes/text become editable layers; unsupported Figma nodes use PNG renders.
  • FigCraft: ordinary Copy/Cmd+C produces SVG with bounded native metadata. EffectCraft Paste/Cmd+V routes it to edit.pasteFigCraft; explicit JSON is accepted too. Each paste is independent and one undo step, with no live link. Text editing and ordinary SVG paste retain their own routes. Frames create compositions; other selections use the active composition and its timing.
  • Fidelity: original PNG/JPEG fills become footage plus native crop mattes, preserving editable text/vector children. Shared mapping/rendering fixes retain overflow bounds, multiple shadows, affine radial/linear gradients, angular/diamond gradients, and source text baseline/line-height. Redo restores the newly created composition when the viewer has no active composition.

Companion FigCraft Copy/export support: storytold/figcraft#535.

Validation and security

  • Version 2 embeds validated original PNG/JPEG bytes; version 1 remains accepted. Carrier/JSON sizes, node count/depth and bitmap bytes/dimensions/pixels are bounded before project mutation. Bitmaps are decoded and importer-probed before one project edit. Malformed marked payloads fail without falling back to stale clipboard contents or flattened SVG.
  • Clipboard payloads cannot name local files or URLs. Figma payload images retain the existing inline-only rule. Automation sessions with file-access confinement reject edit.pasteFigCraft, because checking the project path alone does not prevent sibling asset-directory symlinks from escaping the write root. Ordinary desktop paste is unaffected.
  • Existing feat(design): native Figma transfer and FigCraft copy/paste #1103 security fixes remain: token-bearing requests never follow redirects; HTTPS is required except strictly parsed loopback test endpoints; secret files are created private; the bridge uses a 60-bit random pairing code, loopback Host checks, bounded requests and private payload files. Wrong pairing codes do not lock out legitimate clients.
  • No private design assets, screenshots, fork tooling or unrelated fork features are included.

How tested

The original Figma contribution recorded 12 focused engine tests and 6 bridge tests. For this extension, the already-integrated fork was verified through the native apps: 529/529 frames pasted and passed Undo, with no blank targets or size-limit failures; 953 stored bitmap files matched their original bytes, and four saved/reopened projects rendered identically. Synthetic sampled gradient interiors differed by at most 1/255 per channel and both text lines occupied matching ink bands. These are scoped observations, not universal pixel-parity claims.

This upstream branch was adapted to #1103's older PNG-only Figma mapper while preserving its security fixes. Fresh branch checks passed: rustfmt --check, git diff --check, and strict all-target Clippy (which compiles test targets) for effectcraft-project, effectcraft-render, effectcraft-engine, effectcraft-ui-egui and effectcraft-automation. Added regression coverage includes malformed carriers/assets, bitmap placement, overflow, multiple shadows, gradients, text metrics, text-edit paste routing and automation confinement including a sibling-directory symlink regression.

Not run for this update: full CI, Rust regression execution (the fork's daytime policy requires compilation only), a new native build/UI pass on this upstream branch, or the Figma plug-in end to end. Pattern/tiled fills, image colour filters/strokes and some advanced text/effects remain warned unsupported; minor rasterization differences remain.

Review hardening update

Integrated current upstream main and retained the latest native clipboard/bitmap contributions. REST downloads now use bounded stdout pipes instead of predictable shared temporary files. Import dry runs report exact output paths, and confinement checks those paths (including dangling symlinks); clipboard paste remains refused under confinement.

Final-tree formatting and strict workspace/all-target release Clippy passed. Focused downloader and confinement regressions passed, including both confinement tests after the latest clipboard integration. Full runtime CI and visual clipboard QA were not rerun for this update. The local HTTP bridge/curl architecture remains a maintainer decision.

0Elias71 and others added 2 commits October 12, 2026 19:22
file.importFigma brings Figma frames and layers in as native, editable
layers (comps/precomps, group nulls, shape layers with editable paths,
fills, gradients, strokes, text with style runs, track mattes, layer
styles, Gaussian Blur), from a Figma link via the REST API (system curl,
token from FIGMA_TOKEN / figma.setToken, never journaled) or from node
JSON passed in. Image fills and unsupported nodes come in as 2x PNG
renders. One undo step per import. effectcraft-cli figma-bridge is the
local HTTP endpoint for the Figma plug-in in integrations/figma.

Co-Authored-By: Claude <noreply@anthropic.com>

(cherry picked from commit 8836faa)

(cherry picked from commit ae6f1da39093854a2539696fbfe025cd20843c01)
(cherry picked from commit 5989be7)

(cherry picked from commit 56f4d2aaccfd6985486f2da5fa00440864786b56)
…d bridge pairing

From the review of storytold#858:
- Requests that carry X-Figma-Token never pass -L (curl forwards custom headers to redirect
  targets; Figma's API doesn't redirect). Only the token-less pre-signed image download follows
  redirects (at most 5). Every request is HTTPS-only (--proto/--proto-redir =https); plain HTTP
  only for a loopback apiBase (tests). The options come from curl_args, unit-tested.
- figma.setToken and the bridge's pairing-code file are created with mode 0600
  (figma::write_private: OpenOptions + mode; an existing wider file is narrowed first) instead
  of write-then-chmod.
- figma-bridge: pairing code from the OS CSPRNG (getrandom, rejection-sampled, 12 of 32
  letters); after 5 wrong codes in a row codes are refused for 60 s (429), a right code resets
  the count; bodies capped at 64 MB (413); --code needs 8+ characters; the Host header must be
  the loopback address (no DNS rebinding).

Tests: engine figma (12), cli figma_bridge (6).

(cherry picked from commit 589a910, adapted to the bridge in apps/effectcraft-cli)

(cherry picked from commit 6ebb351b9a8a680cfd19aa9cfcd2089b629c1a3f)
@echelon

echelon commented Oct 13, 2026

Copy link
Copy Markdown
Member

Thank you for this, @eliasx45!

We've held this one, because it's a large bundle (~4.8k lines) with some security problems to fix first:

  • Token leak: fetch::loopback() takes everything before the last : as the host, so apiBase: "http://127.0.0.1:80@evil.com" passes check_api_base and curl sends X-Figma-Token to evil.com over plain HTTP. Please parse the URL properly and check that the resolved IP is loopback.
  • Local file reads: images.{id}.path in a forwarded payload makes the app read any local path.
  • The bridge's /status can be reached by any website through a sandboxed iframe (Origin null) and used to trigger the pairing lockout. Payloads go to a world-readable shared temp directory.
  • The new Figma commands aren't covered by the agent file confinement in confine.rs.

Separately, the maintainers still need to decide whether a local HTTP bridge and curl-based Figma fetching belong in core.

If you are not on our Discord yet, please join us: https://discord.gg/artcraft

…ckout, private payloads, confinement

Review on storytold#1103:
- apiBase is parsed strictly: only http:// to a loopback IP literal with a numeric port, so
  http://127.0.0.1:80@evil.com (and host names) never get X-Figma-Token.
- Payload images must be inline base64 / data URLs: a forwarded payload can't make the app read a
  local file.
- No lockout after wrong pairing codes (any sandboxed page could lock the plug-in out); the
  60-bit code is the protection, and --code now needs 12 characters.
- Payloads go to a per-user 0700 folder under random names, created exclusively, 0600.
- Confinement: file.importFigma's payloadPath is read-checked and its image folder (beside the
  project) write-checked; figma.setToken is refused while confined.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014d65YdNxQmjRkbXRtP2NwH
@eliasx45

Copy link
Copy Markdown
Contributor Author

@echelon Thanks. Fixed all four: the token only goes to a loopback IP literal, payload images must be inline, there's no pairing lockout (and a 12-character code), payloads are private (0700/0600), and confinement covers the import and figma.setToken.

Add a bounded native-only clipboard receiver and normal Paste routing, with actionable unsupported-visual warnings and one-step undo. Preserve destination timing, standalone rendered bounds, affine linear gradient direction, and redo focus when no composition remains active.

Validation: scoped engine/UI cargo check and clippy --all-targets with warnings denied, native app build, and actual cross-app UI clipboard/edit/undo/redo/render/save-reopen checks passed. Regression tests compiled but were not executed under the fork daytime rule; no full CI. Text metrics remain visibly different and warned; parity scores are unchanged.
(cherry picked from commit f01f2e0)
Recognize the bounded FigCraft metadata carrier before generic SVG paste, preserve explicit JSON and text-editing routes, and reject damaged or ambiguous metadata without fallback. Permit SVG path strings only in native geometry entries.

Validation: scoped engine/UI check and clippy --all-targets with warnings denied and native app build passed. Actual right-click Copy and Cmd+C through the OS clipboard pasted ten native editable layers, with no images; undo/redo, independent copies, malformed-carrier rejection, save/reopen and stroke/shadow bounds passed native QA. Regression tests compiled but were not executed under daytime rules; no full CI. Text-metric differences remain warned.
(cherry picked from commit 3a3a1a9)
@eliasx45 eliasx45 changed the title feat(figma): Figma → EffectCraft transfer plug-in, bridge and file.importFigma feat(design): native Figma transfer and FigCraft copy/paste Oct 15, 2026
A writable project path does not prove sibling asset directories stay inside the write roots: a symlink can escape. Reject native FigCraft paste in confined automation until assets can be checked at their actual destination. Desktop paste remains available. Adds a symlink regression, compiled by strict all-target automation Clippy; tests not executed under daytime policy.
@eliasx45

Copy link
Copy Markdown
Contributor Author

@echelon The follow-up hardening is pushed: REST downloads use bounded stdout pipes, dry-run plans expose the exact asset destinations for confinement checks, and unresolved symlinks are rejected. Latest native clipboard contributions are preserved; clipboard paste is refused while confined.

Formatting and strict workspace/all-target Clippy pass. Focused downloader and confinement regressions pass, including both post-integration confinement tests. Full runtime CI and visual clipboard QA were not rerun. The HTTP bridge/curl-in-core policy question remains for maintainers.

@bflatastic

Copy link
Copy Markdown
Member

Hi @eliasx45, thanks for this PR! main has changed a lot since it was opened, and it now conflicts with main, so it needs a rebase before we can review it for merging.

Most of the conflict comes from the shared module layout (#2491), which moved or split files this PR touches:

  • crates/engine/src/commands/mod.rs: its folder moved to crates/engine/src/cmd/
  • crates/engine/src/lib.rs was split: most of its code is now in session/*.rs and siblings
  • crates/render/src/tests_styles.rs → crates/render/src/tests/styles.rs
  • crates/ui-egui/src/menus.rs was split: most of its code is now in menus/*.rs
  • crates/ui-egui/tests/ui_text_edit.rs: its folder moved to crates/ui-egui/tests/it/
  • crates/ui-egui/tests/ui_timeline_shapes.rs → crates/ui-egui/tests/it/ui_timeline_shapes.rs

When you rebase, please also make sure it fits the other recent changes:

CI (cargo xtask ci) now runs on PRs. Once it's green on the rebased branch, we'll take a look. Thank you!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants