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:
- Absent or empty
capabilitiesallows everything. Opting in is the only way to be restricted. - Present and non-empty denies by default. A label with no entry in
grantsholds no capabilities and may call nothing. - A grant is per window label, bound to the token when its document was served. A page may put any
windowin its own invoke body — that field only routes the command (ctx.window), never grants it authority. One window cannot inherit another window's grants by naming it.
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:
| pattern | covers |
|---|---|
dialog:* | every command in the dialog plugin |
fs:read* | fs:readTextFile, fs:readFile, … |
shell:spawn | exactly shell.spawn |
shell:* | every shell command |
pty:open | exactly pty.open |
preview:show | exactly preview.show |
browser:open | exactly 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:
app:notes.save— the narrow form,app:<name>; covers only that command.app:invoke— the broad alias; still covers every app command, so an app that granted it earlier keeps working without a config edit.
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:
security.capabilities[0].actions— an empty or missing action list.security.capabilities[1].name— a capability name used twice, which would makegrantsambiguous.security.capabilities[0].actions[0]— a pattern that is notplugin:command, including the dotted form.security.grants.main[0]— a grant naming a capability that does not exist.