Skip to content

Access grants

Every bridge call is gated by a deny-by-default access system. Your manifest's access array declares which host and cross-plugin surfaces your plugin may use. Grants are sealed at manifest parse time; you cannot escalate at runtime.

Grant grammar

Each entry is <verb>:<key>:

Verb What it gates
data: ctx.data.get(key) / ctx.data.on(key, cb): reads of host data, own-plugin data, and foreign-plugin data
events: ctx.events.on(key, cb): host event subscriptions, own-plugin events, and foreign-plugin events
call: ctx.commands.call(key, args) / ctx.commands.stream(key, args, cbs): host commands, own-plugin commands, and cross-plugin command invocations

The three verbs in practice

data: - read and subscribe

// ── main side ──
// Expose a key under your own plugin prefix (no grant needed).
const handle = ctx.data.expose("myKey", initialValue);
handle.set(newValue);

// Read it back with a bare key. It expands to plugin:<self>/myKey.
const v = await ctx.data.get("myKey");
ctx.data.on("myKey", (value) => { /* ... */ });

// Read a host key (requires a data: grant).
const repo = await ctx.data.get("repository.current");

// Read a foreign plugin's key (requires a data:plugin:<id>/<key> grant).
const stats = await ctx.data.get("plugin:@other/plugin/stats");

Cross-process reads work: the renderer can read what main exposed, and the other way around. The access check is the same regardless of which process the reader runs in.

events: - emit and subscribe

// ── main side ──
// Emit with a BARE key. The host adds the plugin:<self>/ prefix.
ctx.events.emit("branchCreated", { branch: "main" });
// Emitted as "plugin:@acme/my-plugin/branchCreated".

// Passing an already-prefixed key to emit throws:
ctx.events.emit("plugin:@acme/my-plugin/branchCreated", {});
// → TypeError: events.emit(): key "plugin:@acme/my-plugin/branchCreated"
//   must be a bare key, received a "plugin:"-prefixed key. …

// Subscribe using the FULLY-QUALIFIED key.
ctx.events.on("plugin:@acme/my-plugin/branchCreated", (payloads) => {
  // ...
});

Note the asymmetry: emit takes a bare key and on takes the fully-qualified key. This is intentional, because it prevents a plugin from forging another plugin's event prefix, but it is easy to trip over.

call: - invoke commands

// ── main side ──
// Call your own command (no grant needed).
await ctx.commands.call("plugin:@acme/my-plugin/refresh", {});

// Call a host command (requires a call: grant).
await ctx.commands.call("repository.users", {});

// Call a foreign plugin's command (requires a call:plugin:<id>/<key> grant).
await ctx.commands.call("plugin:@other/plugin/doThing", { x: 1 });

The renderer can call a command the main side registered via defineDomain. Foreign calls are gate-checked.

Examples

"access": [
  "data:repository.current",              // exact host data key
  "data:repository.*",                    // wildcard: all repository.* data keys
  "data:app.language",                    // host UI language + locale
  "data:workspace.view",                  // current repository view (read-only)
  "events:branches.updated",             // exact host event
  "events:workspace.viewChanged",        // declared, but never emits today
  "events:plugin:@other/plugin/*",       // wildcard: all public events from @other/plugin
  "call:repository.switch",             // exact host command
  "call:workspace.requestView",         // ask the host to open the view dialog
  "call:plugin:@other/plugin/doThing",  // exact cross-plugin command
  "call:plugin:@other/plugin/*"         // wildcard: all public commands on @other/plugin
]

Wildcard rules

Verb Key space Form Allowed Notes
data: host data:repository.*, data:* yes Prefix match; never crosses into plugin: keys
data: plugin data:plugin:other/*, data:plugin:other/foo* yes Partial wildcards allowed
events: host events:repository.*, events:* yes Same boundary rule
events: plugin events:plugin:other/*, events:plugin:other/foo* yes Partial wildcards allowed
call: host call:repository.* no Rejected: host-key call grants must be exact
call: plugin call:plugin:other/* yes Whole-suffix only
call: plugin call:plugin:other/foo* no Rejected: partial wildcard

The wildcard * must be the last character of the key. A plugin-scoped wildcard must include the complete plugin:<id>/ prefix.

Two cross-cutting rules apply:

  • Plugin-boundary scoping. A host-space wildcard never matches a plugin: key, and the reverse. data:* does not grant access to plugin:other/x.
  • _ privacy. A wildcard never matches an _-prefixed plugin key. events:plugin:other/* will not match plugin:other/_internal.

Implicit self-access

Every plugin implicitly has full access to its own plugin:<self>/ prefix across all three verbs, including _-prefixed keys (privacy restricts only foreign access). You don't need to declare anything:

// All of these work without any access declaration.
ctx.data.expose("_privateKey", value);
ctx.data.get("_privateKey");
ctx.events.emit("_internalTick", {});
ctx.events.on("plugin:@acme/my-plugin/_internalTick", (p) => {});
await ctx.commands.call("plugin:@acme/my-plugin/_setup", {});

Deny by default

If your plugin calls ctx.data.get("repository.branches") without data:repository.branches (or a matching wildcard) in its access array, the call throws GrantDenied. The error names the missing grant:

Plugin @acme/my-plugin denied: missing grant "data:repository.branches" (data "repository.branches")

This is the fastest way to discover which grant you need: trigger the call, read the error, and add the grant to your manifest.

Malformed grants fail the plugin at load

A grant with an unknown verb, an empty key, a non-trailing wildcard, or any other grammar violation produces an invalid-access manifest error. The plugin never activates, and the error is logged.

The _ prefix privacy convention

Keys starting with _ are own-plugin-only. A foreign grant that explicitly names a _-prefixed key (for example events:plugin:@other/plugin/_internal) is rejected at parse time. Wildcards never match _-prefixed keys at runtime, so events:plugin:@other/plugin/* does not match plugin:@other/plugin/_secret. Your own plugin can always access its own _ keys.

Grants govern the bridge, not Node or the DOM

A plugin backend is regular Node.js code, and a plugin page is regular renderer code. Grants only gate what flows through the bridge (ctx.data, ctx.events, ctx.commands). They do not restrict require(), fetch(), or any other Node or DOM API. Packaged builds do turn off a few Node features; see Node features in packaged builds. The access system is an application-level policy layer, not a sandbox.

Next

Backend: main process →