Inkling
All docs

Integrating

Plugins (API v0, experimental)

Sandboxed iframe plugins: manifest, runtime API, security model.

Rendered from docs/PLUGINS.md in the repository. Markdown source

Inkling can run small third-party plugins that add command palette entries and custom blocks, read or (with confirmation) write pages, and keep a little per-user data. Security comes first: every plugin runs in a sandboxed iframe with an opaque origin, no network access and no access to the app's cookies, DOM or storage. Only the server operator can install plugins. 한국어: PLUGINS.ko.md.

Status: experimental. Enable with EXPERIMENTAL_FEATURES=plugins. With the flag off, no plugin route is registered and no plugin UI is shown; plugin blocks already in documents render as inert placeholders and keep their data.

Non-goals: Obsidian compatibility

Inkling's plugin API does not try to run Obsidian plugins, and is not designed to grow into that. The reasons are structural, not a matter of effort:

  1. Different editor and storage model. Obsidian plugins manipulate a CodeMirror editor and a folder of Markdown files (app.vault, app.workspace, MarkdownView…). Inkling documents are Yjs CRDTs rendered by BlockNote/ProseMirror and shared live between users; "the file" does not exist and most Obsidian APIs have no meaningful equivalent.
  2. Electron/Node dependence. Obsidian plugins run with full Node.js and Electron privileges (filesystem, child processes, arbitrary network). A web app that serves many users cannot hand that to third-party code, and a browser cannot provide it anyway.
  3. Multi-user security. Obsidian's model is "one user, one machine, trust what you install". An Inkling server is shared: a plugin runs in every user's browser, against data with per-user visibility (private sections, workspace membership). That demands sandboxing, explicit permissions and administrator approval — the opposite of Obsidian's open model.

Installing a plugin (operators)

Plugins are installed only by the server operator; there is no upload or in-app install in v0.

  1. Enable the experiment: EXPERIMENTAL_FEATURES=plugins (comma-separated with other experiments).

  2. Put each plugin in its own directory under PLUGINS_DIR (default ./data/plugins, i.e. DATA_DIR/plugins):

    data/plugins/
      word-stats/
        manifest.json
        main.js          # the single pre-bundled entry named in manifest.json
    

    The directory name must equal the manifest id. Symlinked directories/files are ignored. Nothing else in the directory is ever read or served.

  3. Open Admin → Plugins (experimental). Review the description, the requested permissions and the declared commands/blocks. Untick any permission you do not want to grant, then Approve & enable.

Approval is pinned to a SHA-256 of manifest.json + the entry bundle. If either file changes on disk (an update, or tampering), the plugin immediately stops being served or listed and shows Changed — needs re-approval until an administrator approves the new content. Disable turns a plugin off; Forget & delete data removes the approval and every user's stored data for it.

Example plugins live in examples/plugins/: word-stats (command + notice

Writing a plugin

A plugin is one plain JavaScript file plus a manifest. The app injects a frozen global inkling (the SDK) before your script runs. There is no build step requirement; if you use dependencies, bundle them into the single entry file (≤ 1 MB). The script runs in a sandboxed document with:

// main.js — a command
inkling.commands.register('count-words', async (ctx) => {
  if (!ctx.pageId) return inkling.ui.notice('Open a page first.')
  const page = await inkling.pages.get(ctx.pageId)        // needs "read:pages"
  const words = (page.markdown.match(/\p{L}+/gu) || []).length
  await inkling.ui.notice(`${words} words`)
})
// main.js — a block
inkling.blocks.register('counter', {
  render(root, { data, editable, setData }) {
    root.textContent = ''
    const b = document.createElement('button')
    b.textContent = `Count: ${data.count ?? 0}`
    b.disabled = !editable
    b.onclick = () => setData({ ...data, count: (data.count ?? 0) + 1 })
    root.append(b)
  },
  // optional: update(root, props) — called instead of render() on later data changes
})

Every command id and block type you register must be declared in manifest.json; anything else is refused.

manifest.json reference

{
  "id": "progress-bar",
  "name": "Progress Blocks",
  "version": "1.0.0",
  "minAppVersion": "0.1.0",
  "description": "Optional, ≤ 300 chars",
  "author": "Optional, ≤ 100 chars",
  "entry": "main.js",
  "permissions": ["blocks"],
  "commands": [{ "id": "count-words", "title": "Word stats: count words" }],
  "blocks": [
    {
      "type": "progress",
      "title": "Progress bar",
      "description": "Optional slash-menu subtitle",
      "defaultData": { "value": 30, "max": 100 },
      "height": 72
    }
  ]
}
FieldRules
id^[a-z0-9][a-z0-9-]{1,63}$, equal to the directory name
name1–60 chars
version, minAppVersionsemver x.y.z; minAppVersion greater than the server's version is rejected
entrybare file name ending in .js (no /, \, ..), regular file, ≤ 1 MB
permissionssubset of commands, read:pages, write:pages, blocks, storage; no repeats
commands≤ 20; id ^[a-z0-9][a-z0-9-]{0,63}$, title 1–80 chars; requires commands
blocks≤ 10; type same pattern, title 1–60; defaultData JSON object ≤ 4 KB; height 40–800 px; requires blocks

Unknown keys are rejected (strict schema). manifest.json itself must be ≤ 64 KB.

Runtime API reference

All methods return Promises. Failures reject with an Error whose code is one of PERMISSION_DENIED, BAD_REQUEST, NOT_DECLARED, BUSY, RATE_LIMITED, DENIED, TIMEOUT, READ_ONLY, or a server error code (NOT_FOUND, PLUGIN_PERMISSION, PLUGIN_STORAGE_QUOTA…).

APIPermissionNotes
inkling.ready–Promise resolving to the context after the handshake
inkling.context()–{ pluginId, mode: 'worker'|'block', workspaceId, pageId, theme, blockType, data, editable }
inkling.commands.register(id, handler)commandshandler(ctx) gets { workspaceId, pageId } of the page the user ran it on
inkling.blocks.register(type, { render, update? })blocksrender(root, { data, editable, setData })
setData(data) (inside a block)blocksSaves the block's JSON (≤ 16 KB) into the document; refused when read-only; coalesced to ≤ 4 writes/s
inkling.pages.get(pageId)read:pages{ id, workspaceId, title, kind, updatedAt, markdown }; exactly the user's visibility
inkling.pages.search(query, workspaceId?)read:pages≤ 20 results { id, title, kind, updatedAt, snippet }; defaults to the current workspace
inkling.pages.update(pageId, markdown, { mode })write:pagesmode: replace (default) or append. The user confirms every call; replace keeps a snapshot
inkling.storage.get(key) / set(key, value) / delete(key) / keys()storagePer plugin and per user; key ^[A-Za-z0-9_.:-]{1,128}$, JSON value
inkling.ui.notice(message)–Toast, prefixed with the plugin name, ≤ 300 chars, ≤ 1/s

Block frames resize themselves automatically (the SDK reports the body height; clamped to 40–1200 px). Theme changes are applied as data-theme="light|dark" on <html>.

REST endpoints (used by the app, not by plugins)

See API.md. Plugins cannot call the server: the app (parent window) calls these with the user's own session after checking the approved permissions.

Limits

LimitValueEnforced in
Incoming message size256 KB (strings only)parent broker
Message rate per frameburst 60, 30/s steadyparent broker
Violations before kill100 (or 3 oversized messages)parent broker
Concurrent RPCs per frame16parent broker
Heartbeatping every 4 s, killed after 12 s without pongparent host
Handshake / command registration10 s / 5 sparent host
Plugin frames alive at once8 (idle command workers evicted first)parent host
Idle command workertorn down after 60 sparent host
Block framescreated only when (nearly) on screen, removed 3 s after leaving itparent host
pages.updateone pending confirmation per plugin, ≥ 3 s apart; 30/min/IP server-sideparent host + server
Storagevalue 64 KB, 500 keys, 1 MB total per plugin per userserver
Bundle / manifest1 MB / 64 KB, ≤ 50 plugin directories scannedserver

Security model

flowchart LR
  subgraph Browser
    subgraph App["App window (inkling origin, session cookie)"]
      H["host.ts — frames, heartbeat, slots"]
      B["broker.ts — size, rate, schema, permission"]
    end
    subgraph F["iframe sandbox=allow-scripts (opaque origin)"]
      SDK["SDK (nonce)"] --- P["plugin main.js (nonce)"]
    end
  end
  S["Server /api/plugins/* — re-checks approval + permission, then user visibility"]
  P -- "MessagePort (JSON strings)" --> B
  B --> H -- "fetch with the user's session" --> S

Trust boundaries. The administrator decides which code runs (approval pinned to a hash). The sandbox decides what that code can touch: nothing but one MessagePort. The parent decides which requests are honoured (approved permissions, declared contributions, limits). The server decides which data the user may see (the same visibility/membership checks as the rest of the app), and independently re-checks that the plugin is active and holds the permission.

  1. Isolation. <iframe sandbox="allow-scripts"> — never allow-same-origin, so the frame has an opaque origin: no cookies, no Web Storage, no access to window.parent's DOM. The frame document is served with its own CSP that repeats sandbox allow-scripts (so it is opaque even when opened as a top-level page), default-src 'none', script-src 'nonce-…' (fresh nonce per response; only the SDK and the approved bundle run), connect-src 'none', form-action 'none', base-uri 'none', frame-ancestors 'self', plus nosniff, Referrer-Policy: no-referrer and a deny-all Permissions-Policy. The iframe also gets allow="", referrerpolicy="no-referrer" and credentialless where supported.
  2. Channel. On the frame's first load, the parent transfers a MessagePort with postMessage(…, '*', [port]) to that exact contentWindow (an opaque origin cannot be named, so '*' is required; the capability is the port, not the origin). All further traffic uses the port, so other windows cannot inject messages and the parent never broadcasts. A second load (the plugin navigated its frame) kills the frame.
  3. Parent broker. Every message must be a JSON string ≤ 256 KB (checked before parsing), pass the token bucket, carry a positive integer request id and a known method with valid params (UUIDs for page ids, so nothing can be injected into proxied URLs), and the method's permission must be in the approved set. Responses carry the request id.
  4. Server. /api/plugins/:id/* routes are cookie-session only (no MCP bearer tokens), return 404 unless the plugin is approved, enabled and its on-disk hash still matches, check the permission again, then call the same guards the app uses (findVisiblePage + requireMembership, or an internal request to the existing route with the user's own cookie). There are no plugin tokens: a plugin can never act as anyone but the signed-in user, and never see more than that user can.
  5. Supply chain. No install API; files are read from PLUGINS_DIR only, symlinks refused, entry confined to the plugin directory, approval bound to content hash, admin approves the hash they reviewed (409 if the files changed in between).

Threat checklist and verification status

"Browser" rows were exercised with the real parent broker and real server-served frames in headless Chrome 157 (harness in apps/server/src/plugins/browser-harness/). "Server" rows are covered by plugins.test.ts and the HTTP smoke. Other browsers are not verified.

Malicious behaviourExpectedStatus
Read parent DOM (window.parent.document, top.document)SecurityErrorBrowser ✔ (Chrome)
Read/write document.cookieSecurityErrorBrowser ✔ (Chrome)
localStorageSecurityErrorBrowser ✔ (Chrome)
fetch same-origin API / external, XHR, WebSocketblocked by CSPBrowser ✔ (Chrome)
Inject <script> without nonce, evalblocked by CSPBrowser ✔ (Chrome)
window.open popup, remote image beaconblocked (sandbox / CSP)Browser ✔ (Chrome)
Frame URL opened top-levelopaque origin (self.origin === "null"), no cookie/storageBrowser ✔ (Chrome)
pages.update without write:pagesPERMISSION_DENIED in parent; 403 serverBrowser ✔ + Server ✔ + unit
Undeclared command/blockNOT_DECLAREDunit
Oversized messages (2 MB × 5)dropped before parse, frame killed after 3Browser ✔ + unit
Message flood (20 000 messages)≤ burst reaches handlers, frame killedBrowser ✔ + unit
Infinite loopno pong for 12 s → frame removed, app stays responsiveBrowser ✔ (Chrome runs the sandboxed frame out of process); unverified elsewhere
Navigate own framesecond load → frame killedBrowser ✔ (Chrome)
Read another user's private page via plugin404Server ✔
Plugin storage of another user / pluginisolated by (plugin, user) keyServer ✔
Swap the bundle after approvalnot served / listed until re-approvedServer ✔
Path traversal / symlink in plugin dir, entry, URLrefused / 404Server ✔
Approve with stale hash or unrequested permission409 / 400Server ✔
Spoofing app toastsnotices always prefixed with plugin namestructural
Spamming write confirmationsone pending per plugin, ≥ 3 s apartstructural (not browser-tested)
App integration: slash menu inserts pluginBlock, block frame renders and auto-resizes, palette command runs in a hidden worker frame and shows its notice, admin section rendersworksBrowser ✔ (Chrome, vite dev against a disposable server)
pages.update with write:pages (confirm dialog → snapshot → write)user confirmsunverified in a browser (server route covered by the existing content route)
setData round-trip from a click inside a block; collaborator change pushed back into the framedocument updated / frame re-rendersunverified in a browser
More than 8 visible plugin frames (slot cap, LRU worker eviction, "paused" placeholder)cappedunverified in a browser
Firefox / Safari behaviour of everything above—unverified

Known limitations and residual risks

Verifying the sandbox yourself

  1. Start a disposable server with EXPERIMENTAL_FEATURES=plugins, PLUGINS_DIR pointing at a scratch directory holding copies of both examples/plugins/* and apps/server/src/plugins/fixtures/*, and WEB_DIST=<harness dir>; register admin@example.com / password123; approve security-probe (commands, read:pages) and progress-bar.
  2. apps/server/src/plugins/browser-harness/run.sh <harness dir> (copies the harness and bundles the real broker.ts with esbuild), restart the server so the files are served.
  3. Start headless Chrome with --remote-debugging-port=9613, then node cdp.mjs. Every probe in escape must print :ok; write must be PERMISSION_DENIED; huge/flood/navigate/loop must report oversize/flood/navigated/unresponsive.

Unit tests: cd apps/server && npx tsx --test src/plugins/plugins.test.ts ../web/src/plugins/broker.test.ts.

Markdown sourceView on GitHubAll docs