Plug-ins: an edited grants file grants nothing, and its plug-ins ask again

grants.json now holds {"version": 1, "grants": [...], "mac": "..."}, where
mac is an HMAC-SHA-256 of the grants and of the plug-in folder, made with a
random 32-byte key kept in the system key store: the Keychain on macOS,
Credential Manager on Windows, the Secret Service on Linux and the BSDs. The
MAC is compared in constant time. A file without a valid MAC for its folder
(an edited or added grant, a removed or changed MAC, a file copied from
another folder) grants nothing, and its plug-ins ask for approval again.

This changes the default for existing files: a grants.json written by an
earlier version is a plain list without a MAC, so its plug-ins ask once
more, and the next approval replaces it with a signed file.

When the key store can't be reached, an approval lasts for the session
only, nothing claims to persist, and the existing file is left as it is.
The first key is made under a per-user lock and read back, so processes
that approve their first plug-in at the same time keep one key. The web
build keeps no grants file.

New native-only dependencies of vectorcraft-engine: hmac, sha2, getrandom
and keyring (all MIT OR Apache-2.0).
This commit is contained in:
dotCooCoo committed 2026-11-21 06:19:05 -08:00
1 parent 9fff48d88f
commit 0eaf435d6a
13 files changed
+1209 -94

No files matched your search

+4 -1
View File
@@ -13223,7 +13223,10 @@ naming the permissions needed. With `VECTORCRAFT_NO_PREFS` set there is no store
flag lasts for that session only. In other sessions the approval, or a `grant` accepted under the flag, is kept with the module's
hash, counts as approved in later sessions and in the desktop app, and covers only that module: the
same bytes install again without one, also from a headless session that reads the same `grants.json`, and a module
with other bytes has `needsApproval: true` and needs a new one even when it lists the same permissions. `plugin.remove`
with other bytes has `needsApproval: true` and needs a new one even when it lists the same permissions. A
`grants.json` that does not carry VectorCraft's MAC for its folder (see [plug-ins](plugins.md#grants-file-integrity))
grants nothing, and its plug-ins have `needsApproval: true` again. When the system key store can't be reached, an
approval lasts for that session only and the file is left as it is. `plugin.remove`
forgets the approval, and so does installing a module that lists no permissions under that id: the earlier bytes then
need a new approval. A refused install keeps the grant. A failed write of the module to the plug-in store leaves the
grant in the store. A stored module that is disabled, or not read in Safe Mode, keeps the grant for its id. When
+41 -6
View File
@@ -261,8 +261,10 @@ capability model proposed for PhotoCraft plug-ins
`grants.json`, and installs a module that lists permissions only under a grant recorded for this very module,
also when it loads the Additional Plug-ins Folder. The approval does not protect against native code linked into
VectorCraft or against another program running as the same user, which can change the files in the `Plug-ins`
folder. `grants.json` is not signed, so such a program can add a grant to it. `--allow-plugin-grants` is a choice
the person starting a headless session makes.
folder. `grants.json` carries a MAC made with a key kept in the system key store ([grants file
integrity](#grants-file-integrity)), so a program that only edits the file can't add a grant to it; one running as
the same user can still read the key or change VectorCraft. `--allow-plugin-grants` is a choice the person starting
a headless session makes.
- **Replacing asks first.** When the file is another module than the plug-in installed with its id, or, with none
installed, its id has settings and a cache in the `Plug-ins` folder, Install Plug-in… and File › Open show its id
and SHA-256 and ask whether to install it in place of that plug-in, which gives it the settings and cache kept for
@@ -300,8 +302,8 @@ capability model proposed for PhotoCraft plug-ins
it held and `grants.json` keeps the grant. The new module runs until the session ends. When the grant can't be
removed and the module already stored can't be read back or written back, the new module stays in the folder, and
the grant stops counting. The grant also stops counting when the folder held no module for that id. A
`grants.json` larger than 1 MiB, or one that is not a JSON list, grants nothing: the new module stays in the folder,
and `plugin.remove` removes the plug-in. A `grants.json` that can't be opened or read counts as a grant that can't be
`grants.json` larger than 1 MiB, or one that is neither a grants object nor a JSON list, grants nothing: the new
module stays in the folder, and `plugin.remove` removes the plug-in. A `grants.json` that can't be opened or read counts as a grant that can't be
removed. When VectorCraft loads the `Plug-ins` folder, it forgets any grant for an id whose stored module lists no
permissions. When it can't remove that grant from `grants.json`, or can't read the file, the grant stops counting,
including for the next load, which tries the removal again. A grant that stops counting in either of these cases
@@ -315,8 +317,8 @@ capability model proposed for PhotoCraft plug-ins
covers. An entry of `grants.json` that this version can't use (a permission it doesn't know, an invalid id) is
skipped and stays in the file until its plug-in is granted again, replaced by a module that lists no permissions, or
removed. When such an entry can't be removed from the file, `plugin.install` and `plugin.remove` treat it as a grant
that can't be removed. A `grants.json` that is not a JSON list is never overwritten, and the file is never written
larger than 1 MiB, the most that is read. When a `Plug-ins` folder is in use, only the grants kept in it count for
that can't be removed. A `grants.json` that is neither a grants object nor a JSON list is never overwritten, and
the file is never written larger than 1 MiB, the most that is read. When a `Plug-ins` folder is in use, only the grants kept in it count for
`plugin.install`, `plugin.inspect`, `plugin.reload` and the Additional Plug-ins Folder. At startup, a stored plug-in
is skipped when no grant covers its bytes and the permissions it lists. The Additional Plug-ins Folder and
`plugin.reload` install only plug-ins that such a grant covers, and report the others. A module without a
@@ -354,6 +356,39 @@ geometry, fill rule, reference box and the paints the effect is given: a plug-in
changes. Failures are cached too. The swatches and patterns a painted result names are checked against the document
each time it is drawn, and a paint linked to a global swatch is drawn in that swatch's current color at its own tint.
#### Grants file integrity
`grants.json` holds the grants in a JSON object, `{"version": 1, "grants": [...], "mac": "..."}`. `mac` is an
HMAC-SHA-256 ([RFC 2104](https://www.rfc-editor.org/rfc/rfc2104)), in lower-case hexadecimal, of the `grants` list
written as compact JSON and of the folder the file is in. The key is 32 random bytes that VectorCraft makes when it
records the first grant. VectorCraft keeps the key in the system key store, as the secret of the account
`hmac-sha256-v1` of the service `org.storytold.vectorcraft.plugin-grants`, and never in a file:
- On macOS the key is in the user's Keychain.
- On Windows the key is a generic credential in Credential Manager.
- On Linux and the BSDs the key is in the Secret Service, for example GNOME Keyring. When its collection is locked,
the desktop may ask to unlock it.
VectorCraft makes the key while it holds `vectorcraft-plugin-grant-key.lock` in the temporary folder on Windows and
macOS, and in `$XDG_RUNTIME_DIR` elsewhere. When that file can't be locked, or `$XDG_RUNTIME_DIR` is not set, no key
is made, and approvals last for the session only, as when the key store can't be reached.
VectorCraft compares the MAC in constant time. A `grants.json` without the MAC of its grants and its folder grants
nothing, and each plug-in it names that lists permissions asks for approval again. This covers a file that an earlier
version wrote (a plain JSON list), a grant that another program edited or added, a file whose `mac` was removed or
changed, a file copied from another `Plug-ins` folder or another computer, and a file whose key is no longer in the key
store. The next approval replaces such a file with a signed file that holds that grant alone, making a key first when
the key store has none. When a grant is forgotten without an approval (`plugin.remove`, installing a module that lists
no permissions under that id, or a folder load that forgets the grant), VectorCraft takes that entry out of such a file
and leaves the rest unsigned.
When the key store can't be reached (it is locked, or a headless Linux session has no Secret Service), no
`grants.json` grants anything and VectorCraft writes none: an approval lasts for the session only, the module stored
for the id is not replaced, and `plugin.remove` of a plug-in that the file names returns an error, as for a grant that
can't be removed. With `VECTORCRAFT_NO_PREFS` set there is no plug-in store, and the web build keeps no grants file. The
MAC does not protect against another program running as the same user, which can read the key from the key store or
change VectorCraft itself.
## ABI v1
A plug-in is a core WebAssembly module (MVP + these post-MVP features: mutable globals, sign extension, saturating
+2 -1
View File
@@ -2653,13 +2653,14 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
- **Plug-in grants cover one module (G17):** a grant counts only for the module with the id and SHA-256 it records. A module that lists permissions and has other bytes under the same id needs a new approval, even with the same permissions: `plugin.inspect` reports `needsApproval`, `plugin.install` refuses it without `grant`, Install Plug-in… and File › Open ask again, and the plug-in store and plug-in folders skip it. A module with a missing or empty permissions list needs no grant; without the list, it gets its kind's implied permissions. A grant with a malformed hash covers nothing. Regressions: `crates/plugins/src/permissions.rs`, `crates/engine/src/tests/plugins.rs`, `crates/ui-egui/src/tests/plugins.rs`. Scores and hours unchanged.
- **Plug-in approval needs a person (G17):** a plug-in's permissions and heavy budget are approved in a dialog that only a person can confirm: the control channel, MCP and injected input are refused, and `plugin.install` takes `grant` or `allowHeavy` only with that approval. `vectorcraft-cli mcp` and `run` refuse them unless started with `--allow-plugin-grants`. Regressions: `crates/engine/src/tests/plugins.rs`, `crates/ui-egui/src/tests/automation.rs`, `apps/vectorcraft-cli/tests/it/cli.rs`. Scores and hours unchanged.
- **A dialog's OK runs what it was opened for:** `ui.dialog.set`, and MCP's `answer_dialog` through it, can set a `__` field only when it is a control of that kind of dialog (a section or tab shown, a link between two fields, a name or search being typed). Every other `__` field, such as the `__command` and `__params` of a confirmation or the generic parameter dialog, a plug-in command dialog's `__command` and `__plugin`, or the paste a swatch conflict waits to finish, is refused with "the `<kind>` dialog cannot set protected field `<field>`"; the request sets no field, and with `action: "confirm"` OK does not run. Regressions: `crates/ui-egui/src/tests/automation.rs`, `crates/ui-egui/src/control/tests.rs`. Scores and hours unchanged.
- **Only an approval records a plug-in grant (G17):** `vectorcraft_plugins::registry::grant` takes a `GrantToken`, which the engine makes after an approval and when it loads `grants.json`, and `registry::install`, `install_bytes` and folder loads refuse a module that lists permissions no recorded grant gives this very module (`Error::NeedsApproval`), leaving the plug-in under its id and the revision as they were. A module without `permissions`, or with an empty list, installs as before. `docs/plugins.md` says what the approval does not protect against (native code linked into the app, another program running as the same user, the unsigned `grants.json`). Regressions: `crates/plugins/src/registry.rs`, `crates/plugins/tests/grant_sites.rs`, `crates/engine/src/tests/plugins.rs`. Scores and hours unchanged.
- **Only an approval records a plug-in grant (G17):** `vectorcraft_plugins::registry::grant` takes a `GrantToken`, which the engine makes after an approval and when it loads `grants.json`, and `registry::install`, `install_bytes` and folder loads refuse a module that lists permissions no recorded grant gives this very module (`Error::NeedsApproval`), leaving the plug-in under its id and the revision as they were. A module without `permissions`, or with an empty list, installs as before. `docs/plugins.md` says what the approval does not protect against (native code linked into the app, another program running as the same user). Regressions: `crates/plugins/src/registry.rs`, `crates/plugins/tests/grant_sites.rs`, `crates/engine/src/tests/plugins.rs`. Scores and hours unchanged.
- **A refused plug-in install writes nothing (G17):** `plugin.install` checks the plug-in installed under the module's id and its grant again while it records the grant and installs the module (`registry::install_checked`), and only then writes the module and its grant to the `Plug-ins` folder, attaches its settings and cache and turns a disabled plug-in on. When another session installed a plug-in with the id that would need `replace: true`, or changed the grant the checks relied on, the install is refused and the folder, `grants.json`, the disabled list and the installed plug-in stay as they were. Without a plug-in store, the approval comes from the grant the install checks again. A `plugin.remove`, or a load of the folder or of a plug-ins folder, in another session waits until the install has written the folder. VectorCraft's own rule. Regressions: `crates/engine/src/tests/plugins.rs`. Scores and hours unchanged.
- **Windows and processes take turns on the Plug-ins folder:** each one locks `disabled.lock` in the `Plug-ins` folder while it reads and changes the stored modules, `grants.json`, `disabled.json` and the plug-ins' settings and caches, so two installs of one id keep each module with its own grant, and grants or settings written by two processes are all kept. When the file can't be locked, `plugin.install` and `plugin.remove` fail and change nothing. VectorCraft's own rule. Regressions: `crates/engine/src/tests/plugins.rs`. Scores and hours unchanged.
- **Plug-in approval waits before OK (G17):** the approval dialog's OK stays disabled until its question has been on screen in the focused window for half a second, VectorCraft's own value; a click, Enter, Space, or a press begun before then installs nothing, and the dialog stays open. The wait starts over for every new question, even one that reads the same, and when the window gets the focus back, so a question swapped in just before a click is not approved by it. Cancel works at once. Regressions: `crates/ui-egui/src/tests/plugins.rs`. Scores and hours unchanged.
- **An install automation asked for needs the person to start it (G17):** an approval question that a control request, MCP, injected input or a file dialog one of them opened leads to keeps OK disabled and refuses every confirm, a person's click included; it says to choose Object › Plug-ins › Install Plug-in…, and `ui.installPlugin` answers `approval: "personMustStartInstall"`. The person's own Install Plug-in…, File › Open or drop inspects the module again and asks a new question. Automation's `replace: true` no longer skips the question about taking another module's place, and that question now opens in the approval dialog for everyone. VectorCraft's own rule. Regressions: `crates/ui-egui/src/tests/automation.rs`, `crates/ui-egui/src/tests/plugins.rs`. Scores and hours unchanged.
- **A plug-in with no permissions ends its id's grant (G17):** installing a module that lists no permissions under a granted id forgets the grant, in the process and in `grants.json`, so the formerly approved bytes need a new approval. Attaching a `Plug-ins` folder whose module for that id lists no permissions forgets it too, and plug-in folders forget the process's grant. A refused install leaves the grant. Regressions: `crates/engine/src/tests/plugins.rs`, `crates/engine/tests/plugin_safe_mode.rs`. Scores and hours unchanged.
- **A grant that can't be forgotten stops counting in the whole process (G17):** when such a grant can't be removed from `grants.json`, no session in the process that uses the same `Plug-ins` folder, by any path to it, counts it for `plugin.inspect`, `plugin.install` or loading plug-ins, until `grants.json` can be written for that plug-in; another process on the folder reads `grants.json` as it is. Regressions: `crates/engine/src/tests/plugins.rs`. Scores and hours unchanged.
- **An edited grants file grants nothing (G17):** `grants.json` carries an HMAC-SHA-256 of its grants and its folder, made with a random key kept in the system key store (Keychain, Credential Manager, the Secret Service) and compared in constant time. A file without that MAC (an earlier version's plain list, an edited or added grant, a removed or changed MAC, a file copied from another folder) grants nothing, and its plug-ins ask for approval again; the next approval replaces it with a signed file. When the key store can't be reached, an approval lasts for the session only and the file is left as it is. VectorCraft's own rule. Regressions: `crates/engine/src/tests/plugins.rs`. Scores and hours unchanged.
- **Plug-in commands (G17):** a filter or live effect may declare up to 32 `commands` (`{id, label, params?}`); each is the command `plugin.<id>.<command>` while the plug-in is installed, in a submenu named after the plug-in under Object › Plug-ins (Effect › Plug-ins for a live effect) whatever menu the manifest names, with its label escaped. Commands are recorded in actions, listed in Keyboard Shortcuts for the user to give a shortcut, and run through `run` and MCP with their parameters checked first (a command with parameters opens a dialog from its menu item or shortcut). A run uses the plug-in's permissions (a live effect with commands may also hold `doc.write` and `state`, and gets them without a `permissions` list), is one undo step named after the command, and on failure (a trap or an exhausted instruction budget) leaves the document and the undo history as they were with an error naming the plug-in and the command. For a command and for `plugin.run`, an `ids` that is not a list of object ids is an error rather than the selection. A malformed entry is refused by name when the module is installed. Regressions: `crates/plugins/src/manifest.rs`, `crates/plugins/src/permissions.rs`, `crates/engine/src/tests/plugins.rs`, `crates/engine/tests/plugin_fuzz.rs`, `crates/ui-egui/src/tests/plugins.rs`. Scores and hours unchanged.
- **Filter plug-ins call commands (G17, #2186):** a filter at plug-in API level 2 with the `commands` permission names the commands it may run in its manifest's `commandAllowlist` and runs them with `env.vc_call`, reading each result with `env.vc_call_result`. Each call sees what the calls before it changed; the calls and the filter's output are one undo step, and a run that fails, is canceled or makes a call that fails leaves every document, its selection and its history as they were. Commands that read or write files, use the clipboard, change preferences or the view, run scripts, actions or plug-ins, switch documents or undo are never called, and a manifest that lists one is refused when the module is installed. A command counts as taking a file or folder when its params description or schema names a file key as a param; a word in the description's prose or result does not count. Each exemption for a key that names part of the document names a param its command takes, which `every_command_is_sorted` checks, and Image Trace's path fidelity setting (`params.paths`, `savedPreset.paths`) is exempt only inside those settings. The install dialog lists the allowed commands. A run makes at most 1,000 calls, and each call costs 10,000 instructions of its budget. Regressions: `crates/plugins/tests/call.rs`, `crates/engine/tests/plugin_call.rs`, `crates/engine/src/cmd/plugin_call.rs`. Scores and hours unchanged.
- **The command sweep sends file and folder params into its temp folder by the command catalog:** the sweeps in `crates/engine/tests/command_sweep.rs` take each command's file and folder keys from the catalog (`cmd::location_keys`, the same key list the plug-in call rules use, less the keys that name part of the document in a command), read every key a params description names (`{path | name …}`, `{folder? (…)}` included) and its schema's params, and send every string under such a key, in arrays and in objects inside them (`paths: [{ids, path}]`), as a location in the temp folder, so a command added later is swept and checked without editing the sweep. `diffPath` counts as a file key, and Slice Options' `url` and Export for Screens' `folders` do not. Regressions: `sweep_cases_name_files_only_inside_the_temp_folder` and `sweep_cases_send_the_file_keys_of_the_command_catalog` in `command_sweep`, `location_keys_come_from_the_command_catalog` in `cmd::plugin_call`. Scores and hours unchanged.