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
iframewhosesandboxattribute isallow-scripts, whosereferrerpolicyisno-referrerand whose document is insrcdoc, and nothing else. It has an opaque origin, so it cannot reach the parent page and it has nolocalStorage,sessionStorage, IndexedDB or cookies. Its requests carryOrigin: null. The sandbox never includesallow-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-readymessage that comes from the frame's own window, and it answers by handing that window one end of aMessageChannel. From then on the frame talks only over its port. The host ignores messages that arrive throughwindow.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 remotescript-srcorigin, 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:
- The host creates the frame with the composed policy and waits for a message of type
ws-shell-readyfrom that frame's window. - The host posts a message of type
ws-shell-portto the frame and transfers one end of a newMessageChannelwith it. The shell runs its canary and answers with ahellomessage. - The host checks the
hellomessage. 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. - The host fetches the files and verifies them against the approved digest, and then it sends a
loadmessage. A file that fails its digest ends the frame as an integrity failure. - The shell evaluates the module and runs
initializeand thenrender, as Plugin module contract describes, and it sendsloaded. 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.
helloThe shell is running and reports the result of its self-check.
runtimenumberrequiredafmstringrequiredat most 16 characterscanaryarray of objectrequiredat most 32 items3 nested properties
namestringrequiredat most 64 charactersokbooleanrequireddetailstringat most 300 characters
loadedinitialize and render have finished. The names are the members that initialize returned.
exportsarray of stringrequiredat most 16 items
errorSomething 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"requiredmessagestringrequiredat most 2,000 characters
writeThe module called save_changes. The host answers with an echo message.
traitsobjectrequired
invokeThe module calls a command.
idintegerrequiredat least 0namestringrequiredat most 64 charactersmsganyrequiredbuffersarray of anyat most 8 items
export-resultThe module answers a call-export message.
idintegerrequiredat least 0okbooleanrequiredvalueanyerrorobject2 nested properties
namestringrequiredat most 64 charactersmessagestringrequiredat most 2,000 characters
pongThe module answers a ping.
seqintegerrequired
cspThe policy blocked a request.
directivestringrequiredat most 32 charactersoriginstringrequiredat most 255 characters
logThe module wrote a log line.
level"debug" | "info" | "warn" | "error"requiredtextstringrequiredat most 2,000 characters
disposedno fieldsThe 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
loadThe host delivers the module and its starting state.
entryanyrequiredThe module's bytes.
stylesarray of stringrequiredThe stylesheets of the plugin.
stateobjectrequiredThe initial value of each bound trait.
writablearray of stringrequiredThe traits that the module may write.
permissionsarray of stringrequiredThe permissions that the widget holds.
timeoutsobjectrequiredHow long initialize and render may take, in milliseconds.
2 nested properties
initializenumberrequiredrendernumberrequired
pushThe host reports changed trait values, and each change fires change:<trait> in the module.
traitsobjectrequired
echoThe host reports the writes that it accepted. A refused write comes back with the previous value.
traitsobjectrequired
resultThe host answers an invoke message.
idnumberrequiredokbooleanrequiredvalueanybuffersarray of anyerrorobject2 nested properties
namestringrequiredmessagestringrequired
eventThe host sends an event to the module's msg:custom listeners, for example a refresh or a visibility change.
contentanyrequiredbuffersarray of any
call-exportThe host calls a member of the module's exports.
idnumberrequiredmember"exportOptions" | "exportData" | "copilotContext" | "copilotRows"requiredargsarray of anyrequiredtimeoutnumberrequired
pingThe host checks that the frame is alive.
seqnumberrequired
schemeThe site's color mode changed.
mode"light" | "dark"required
disposeno fieldsThe 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:
| Limit | Value |
|---|---|
| Size of one message from the frame | 1 MiB, counting buffers, strings and keys. |
| Size of one export | 25 MiB. |
| Rate of messages from the frame | About 100 messages per second, with bursts of up to 200. |
| Commands that wait for an answer | At most 32. |
| Violations that end the frame | 3 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. |
| Liveness | The host pings every 5 seconds and ends a frame that misses 3 pings in a row. |
| Loading | initialize has 15 seconds and render has 15 seconds. |
| Navigation | A second load event of the iframe means that the frame navigated itself, and the host ends it. |
| Policy reports | At 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.