Skip to content
GalleryOpen Garphield

Security and self-hosting

Configure framing, messaging, and command access separately. Use the same exact host origins across all three layers.

VITE_PUBLIC_EMBED_ORIGINS=https://product.example,https://staging.example

Use origins only (scheme, hostname, and optional port) with no path. The renderer always accepts its own origin for same-site integrations.

Serve the embed route with a matching frame-ancestors policy:

Content-Security-Policy: frame-ancestors 'self' https://product.example

Keep the full workbench unframeable and scope this policy to /embed and /embed/*. The host page may also need:

Content-Security-Policy: frame-src https://garphield.com

An allowed origin with no entry in VITE_PUBLIC_EMBED_CAPABILITIES gets the default grant. Every command in it changes only how the loaded document is drawn:

Command Driver method
setDocument setDocument()
setTheme setTheme()
setEdgeFilter setEdgeFilter()
setBindingEnabled setBindingEnabled()
filter.time setTimeFilter() (a time filter’s dates)
storyboard.next, storyboard.prev, storyboard.goto nextStep(), prevStep(), goToStep()
layout.set setLayout()
layout.levels setLevels()
view.group setGroups()
view.merge setMerge()
view.backbone, view.detail setBackbone(), setDetail()
edges.style setLinkStyle()
edges.routing setLinkRouting() (bundled or direct links, and bundle strength)
labels.placement, labels.size setLabelPlacement(), setLabelSize()
channel.bind, channel.unbind, channel.scale bind(), unbind(), setScale()
camera.fit, camera.frame, camera.focus fit(), frame(), focus()
selection.select, selection.clear select(), clearSelection()

A default host cannot:

  • Read anything back. Workbench commands reply with an acknowledgement and no value; setEdgeFilter returns only the count of links it left visible.
  • Learn about the document from errors. When a workbench command fails, a default host gets only its code and a fixed message, such as garphield: the command was rejected (VALIDATION), never the command’s own message, so an error cannot say which fields or node ids exist. The built-in methods’ errors are fixed messages or repeat the host’s own input.
  • Receive events about the reader. It gets the payload-free ready event and a generic error event; nodeClick and stepChange need an explicit grant.
  • Run commands that read the document or its history (view.inspect, quality.report, history.*, layout.wait), touch storage or the network (session.*, file.*, data.open, sources.browse, artifact.*, storyboard.share, storyboard.capture), edit data (set.*, filter.*, transform.*, selection.hide, selection.keepOnly), or open the full app (openInApp).

Set an origin-specific command list when a host needs more:

VITE_PUBLIC_EMBED_CAPABILITIES={"https://product.example":["setDocument","setTheme","camera.frame","view.inspect"]}

A configured list replaces the default for that origin, so repeat any default commands the host still uses. A host granted a workbench command this way gets the command’s value back, and its full error message when it fails. Keep the grant as small as the integration allows.

Events are opt-in too. A host receives nodeClick or stepChange only when its exact origin’s list includes events.nodeClick or events.stepChange:

VITE_PUBLIC_EMBED_CAPABILITIES={"https://product.example":["setDocument","setTheme","setEdgeFilter","setBindingEnabled","storyboard.next","storyboard.prev","storyboard.goto","layout.set","layout.levels","view.group","view.backbone","view.merge","view.detail","filter.time","channel.bind","channel.unbind","channel.scale","edges.style","edges.routing","labels.placement","labels.size","camera.fit","camera.frame","camera.focus","selection.select","selection.clear","events.nodeClick"]}

http://localhost:3000 and http://localhost:4321 are different origins. Use the development host’s exact origin in the renderer allowlist and command grant, and pass the renderer’s absolute URL to createGarphield().

The driver and renderer both use exact postMessage origins. Requests with an unknown method, invalid version, untrusted origin, or missing capability are refused.