Skip to main content

Plugin frame protocol

This page describes how the host, which is the FINOS Workspace page, and a plugin's frame talk to each other. The protocol runs at runtime version 1 and AFM version 0.11. The host defines the messages in frontend/src/plugins/protocol.ts, and the frame's shell is frontend/src/plugins/shell/shell.js. The message tables on this page are generated from the schemas in protocol.ts, and a test keeps the data equal to the code.

The frame​

A plugin's widget runs in an iframe that the host creates with these properties:

  • Sandbox. The frame is an iframe whose sandbox attribute is allow-scripts, whose referrerpolicy is no-referrer and whose document is in srcdoc, and nothing else. It has an opaque origin, so it cannot reach the parent page and it has no localStorage, sessionStorage, IndexedDB or cookies. Its requests carry Origin: null. The sandbox never includes allow-same-origin, popups, top navigation, forms, modals or downloads. The frame's Content Security Policy is described on Plugin frame policy.
  • A private channel. The host answers only the ws-shell-ready message that comes from the frame's own window, and it answers by handing that window one end of a MessageChannel. From then on the frame talks only over its port. The host ignores messages that arrive through window.postMessage, it identifies the sender by the port and never by a field inside a message, and it validates every message against a schema.
  • No ambient authority. The user's session never enters the frame. The host makes every authenticated call, and a request that the policy lets the frame make carries no credentials. Secrets stay on the server.
  • Verified code. The host fetches the plugin's files with the user's session and checks the SHA-256 of each file against the approved digest. It then sends the bytes into the frame, which evaluates them from a blob: URL. A remote script-src origin, which only a superuser can add, lets in code that this check does not cover.
  • Confinement to the card. A frame draws only inside its own card. A notice from a plugin is shown as plain text, it is rate limited, and it is labelled with the plugin's name. Links that a plugin opens go through the external-link confirmation.

Starting a frame​

A frame starts in five steps:

  1. The host creates the frame with the composed policy and waits for a message of type ws-shell-ready from that frame's window.
  2. The host posts a message of type ws-shell-port to the frame and transfers one end of a new MessageChannel with it. The shell runs its canary and answers with a hello message.
  3. The host checks the hello message. Every canary check must have passed, the runtime and AFM versions must be the host's own, and the frame's document must not be readable from the page. When any of these conditions fails, the host ends the frame and the card shows "Plugin sandbox unavailable" with the check that failed. A frame that is not a proper sandbox never receives any code.
  4. The host fetches the files and verifies them against the approved digest, and then it sends a load message. A file that fails its digest ends the frame as an integrity failure.
  5. The shell evaluates the module and runs initialize and then render, as Plugin module contract describes, and it sends loaded. From then on the host pushes traits and answers commands.

The canary runs before any plugin code is in the frame. It checks that self.origin is "null", that localStorage, sessionStorage, indexedDB.open and cookies are unavailable, and that reading parent.document throws. For every directive that the policy denies, it also triggers a probe that must raise a violation. The probes are a fetch and an image request to a reserved .invalid host, a call to new Function when eval is not approved, and an inline script. WebKit raises no event for a refused eval, so the canary accepts the EvalError that WebKit throws as proof.

Messages from the frame​

Every message has a field t that names its type. A message of any other form, or a message that fails its schema, counts as a protocol violation.

  • hello

    The shell is running and reports the result of its self-check.

    • runtimenumberrequired
    • afmstringrequiredat most 16 characters
    • canaryarray of objectrequiredat most 32 items
      3 nested properties
      • namestringrequiredat most 64 characters
      • okbooleanrequired
      • detailstringat most 300 characters
  • loaded

    initialize and render have finished. The names are the members that initialize returned.

    • exportsarray of stringrequiredat most 16 items
  • error

    Something failed. The host only logs an error in the runtime phase and ends the frame for every other phase.

    • phase"load" | "initialize" | "render" | "runtime" | "export"required
    • messagestringrequiredat most 2,000 characters
  • write

    The module called save_changes. The host answers with an echo message.

    • traitsobjectrequired
  • invoke

    The module calls a command.

    • idintegerrequiredat least 0
    • namestringrequiredat most 64 characters
    • msganyrequired
    • buffersarray of anyat most 8 items
  • export-result

    The module answers a call-export message.

    • idintegerrequiredat least 0
    • okbooleanrequired
    • valueany
    • errorobject
      2 nested properties
      • namestringrequiredat most 64 characters
      • messagestringrequiredat most 2,000 characters
  • pong

    The module answers a ping.

    • seqintegerrequired
  • csp

    The policy blocked a request.

    • directivestringrequiredat most 32 characters
    • originstringrequiredat most 255 characters
  • log

    The module wrote a log line.

    • level"debug" | "info" | "warn" | "error"required
    • textstringrequiredat most 2,000 characters
  • disposedno fields

    The module's cleanup has finished.

An invoke message calls a command, which Plugin permissions and commands lists. A csp message reports a blocked request, as Plugin frame policy describes.

Messages from the host​

  • load

    The host delivers the module and its starting state.

    • entryanyrequired

      The module's bytes.

    • stylesarray of stringrequired

      The stylesheets of the plugin.

    • stateobjectrequired

      The initial value of each bound trait.

    • writablearray of stringrequired

      The traits that the module may write.

    • permissionsarray of stringrequired

      The permissions that the widget holds.

    • timeoutsobjectrequired

      How long initialize and render may take, in milliseconds.

      2 nested properties
      • initializenumberrequired
      • rendernumberrequired
  • push

    The host reports changed trait values, and each change fires change:<trait> in the module.

    • traitsobjectrequired
  • echo

    The host reports the writes that it accepted. A refused write comes back with the previous value.

    • traitsobjectrequired
  • result

    The host answers an invoke message.

    • idnumberrequired
    • okbooleanrequired
    • valueany
    • buffersarray of any
    • errorobject
      2 nested properties
      • namestringrequired
      • messagestringrequired
  • event

    The host sends an event to the module's msg:custom listeners, for example a refresh or a visibility change.

    • contentanyrequired
    • buffersarray of any
  • call-export

    The host calls a member of the module's exports.

    • idnumberrequired
    • member"exportOptions" | "exportData" | "copilotContext" | "copilotRows"required
    • argsarray of anyrequired
    • timeoutnumberrequired
  • ping

    The host checks that the frame is alive.

    • seqnumberrequired
  • scheme

    The site's color mode changed.

    • mode"light" | "dark"required
  • disposeno fields

    The host ends the widget, which aborts signal and runs the cleanups.

When the host refuses an invoke message, the error.name of its answer is one of not_granted, invalid_args, out_of_scope, rate_limited, too_large, unknown_command, timeout or unavailable. The member of a call-export message is one of exportOptions, exportData, copilotContext or copilotRows.

Limits​

The host enforces the following limits on the frame:

LimitValue
Size of one message from the frame1 MiB, counting buffers, strings and keys.
Size of one export25 MiB.
Rate of messages from the frameAbout 100 messages per second, with bursts of up to 200.
Commands that wait for an answerAt most 32.
Violations that end the frame3 within 10 seconds. A message over the rate or size limit, a message outside the schema, and a message whose handling fails each count as one violation.
LivenessThe host pings every 5 seconds and ends a frame that misses 3 pings in a row.
Loadinginitialize has 15 seconds and render has 15 seconds.
NavigationA second load event of the iframe means that the frame navigated itself, and the host ends it.
Policy reportsAt most 50 reports every 5 seconds.

The host creates a plugin widget's frame when its card comes near the viewport, and it releases the frame when the card is scrolled far away or its tab is not active.