Permissions

Decide which window may call which command. Authenticating a page is not the same question as authorising it: the token says a page is this app's own and binds it to one window label, and capabilities say what that label may do.

// crust.config.ts
security: {
	capabilities: [
		{ name: "fs-read", actions: ["fs:read*"] },
		{ name: "panels", actions: ["dialog:*"] },
		{ name: "shell", actions: ["shell:spawn"] },
	],
	grants: {
		settings: ["fs-read", "panels"],
		chat: ["panels"],
	},
},

No security.capabilities means every command is allowed, which is what every app written before this existed sees. That is the one compatibility guarantee, and nothing here changes what an app that does not opt in gets.

What the model guarantees

Three rules, all checked at the bridge rather than inside a plugin:

The check lives in the invoke path, ahead of the handler, so both payload kinds (JSON and a binary body) and every plugin — built-in, mounted, or a third-party extension — take the same gate. A plugin cannot forget to add it.

The token is the authority, not the body's window field. The document route mints a fresh token per document and records the ?window= it served, so the bridge authorises on that bound label. A process token for a dev-server page is bound to main, and a request that names no window in its body still uses its token's label. The label in a request is a routing hint: a page that writes "window":"admin" can address the admin window but cannot hold the admin window's grants, which belong only to the token minted for that document.

Dev is not a boundary

That binding is a built-app fact. Under crust dev the dev server injects the token and selects it from the page's ?window=<label>; a page on the dev origin can name another label and hold its grants. Per-label grants in dev preview the built app, they do not enforce it — see Dev server.

Actions

An action is plugin:command. * is the only metacharacter and matches any run of characters, including none:

patterncovers
dialog:*every command in the dialog plugin
fs:read*fs:readTextFile, fs:readFile, …
shell:spawnexactly shell.spawn
shell:*every shell command
pty:openexactly pty.open
preview:showexactly preview.show
browser:openexactly browser.open

pty:open is the terminal (Pty) and is never implied by a shell grant: shell:spawn runs an allowlisted program, and a pty is an interactive shell. preview:show shows the embedded panel and browser:open loads an origin the browser allow list names — each is its own surface, granted per label.

The colon is part of the match, so dialog:* does not cover dialogx.openPanel. Names are compared case-sensitively. The dotted spelling (shell.spawn) is refused at startup rather than accepted as a second spelling — one action with two spellings is how a grant looks right and covers nothing.

grants names capabilities; a name that no capability declares is a config error, and a grant on a label no window uses is simply unused.

App commands

A page calls its own commands through app.invoke({ name: "notes.save" }). That one wire handler is a dispatcher, so the gate checks the action the name selects: app:notes.save, not the wire key app:invoke. The finest matching action is the one a refusal names.

There are two ways to grant an app command:

A grant of either authorizes the call. Every scaffold grants the narrow form instead — app:greet, the one command its page calls — with a comment saying a new command needs its own action there, or app:invoke if the app deliberately wants the broad alias. A scaffold therefore starts at least privilege, and widening is a decision the author makes.

The * caveat matters here. app:notes.* matches every command under that prefix, delete as well as save. So this grant:

capabilities: [{ name: "notes", actions: ["app:notes.save"] }],

allows app:notes.save but refuses app:notes.delete with app:notes.delete is not granted to window …. Scoping one command needs the exact action; a wildcard cannot tell two commands under one prefix apart.

The refusal

A command the label does not hold answers forbidden (HTTP 403) and names all three things an author needs at 2am: the action, the window, and the capability that would have allowed it.

shell:spawn is not granted to window "chat": capability "shell" would allow it — add it to that label's grants
test:secret is not granted to window "main": no configured capability lists this action

The refusal happens before the handler runs, so nothing was started, read or written.

What it does not do

This is authorisation, not a sandbox. A label that holds fs:* may read and write every path the fs plugin itself can reach — capabilities do not narrow an argument, they only pick which commands a page may call at all. Narrow a command's reach with the plugin's own limits (fs.scope, shell.allow), and treat a capability as "this page is trusted with this plugin", not "this page is trusted with part of it".

Nor is it a boundary against arbitrary code in the page's own window: a page that holds shell:spawn can spawn. The point is that a page which holds nothing cannot do anything, which is the difference between an injected script being harmless and it being able to spawn a process.

In-process calls

app.invoke is not gated. It is the app calling itself from main.ts, not a page, so it holds every command — the gate is about what the page can ask the app to do.

Validation

Capabilities are validated at startup, and every failure names the key: