Cache plugin package hashes, add a content security policy, and limit browser windows
Plugin runtime cost: - Remove the timed plugin scan. Windows scan at start, on focus, on Refresh, and on plugins-changed. - Keep one package check for each plugin folder. Read and hash the files again only when the entry names, sizes, or modification times change. Enable and load always read all files. An asset read checks the SHA-256 hash of its file. - A changed package still stops and needs a new enable decision. Add tests for the cache, for changes that keep the metadata, and for the enable decision. - Replace the 50 ms wait loops of update and removal with a condition variable. The limit stays at 10 seconds. Command names, arguments, and results do not change. Content security policy: - Set app.security.csp in tauri.conf.json. Keep Tauri from adding nonces to style-src. - Add CSP mode to the smoke tests (pnpm smoke --csp). The dev server sends the same policy with each HTML page, and the harness fails a test on a policy violation. - Decode data URLs without fetch in the background frame test. Capabilities: - Give browser windows their own capability. They load no installed plugin. Add a unit test and a browser window smoke test for the command set. Document the scans, the hash cache, the policy, and the window capabilities.
This commit is contained in:
+18
-1
@@ -36,7 +36,7 @@ Do not start a separate `pnpm dev` for this workflow.
|
||||
| Rust code in `src-tauri/src/` | Cargo rebuilds the changed code, and Tauri restarts the app. |
|
||||
| Rust dependencies or build settings | Cargo compiles the affected crates. This can take several minutes. |
|
||||
| JavaScript dependencies, after a pull | Stop the session, run `pnpm install --frozen-lockfile`, and start it again. |
|
||||
| Tauri configuration, capabilities, or Vite configuration | Restart `pnpm tauri dev`. |
|
||||
| Tauri configuration, capabilities, or Vite configuration | Restart `pnpm tauri dev`. The content security policy applies only to a built app, not to `pnpm tauri dev`. See [Content security policy](plugin-host.md#content-security-policy). |
|
||||
| A plugin in a sibling repository | Build and package that plugin, then install the new ZIP through Settings. See [Build examples](plugin-development.md#build-examples). |
|
||||
| Installer or release behavior | Use the [build guide](builds.md). |
|
||||
|
||||
@@ -74,6 +74,7 @@ Windows is the primary platform. macOS and Linux builds are experimental.
|
||||
|
||||
The interface calls Rust commands through Tauri `invoke`. Most calls go through the wrappers in `src/lib/workspace/api.ts`.
|
||||
A new command needs an entry in `generate_handler!` in `lib.rs`, in the command list in `src-tauri/build.rs`, and in the capability files in `src-tauri/capabilities/`.
|
||||
`default.json` must list every command. `settings.json` and `browser.json` list subsets. See [Window capabilities](plugin-host.md#window-capabilities).
|
||||
|
||||
### Interface: `src/lib/`
|
||||
|
||||
@@ -193,6 +194,7 @@ They do not replace tests in the native app. Real folder access, file writes, an
|
||||
| `pnpm smoke` | All smoke tests, four at a time |
|
||||
| `pnpm smoke tabs tables/drag` | The tests whose path contains one of the filters |
|
||||
| `pnpm smoke --list` | Nothing. It lists each test, its requirements, and why a test would skip. |
|
||||
| `pnpm smoke --csp` | All smoke tests under the content security policy of the app. A test fails on any policy violation. |
|
||||
|
||||
The runner starts the Vite server when nothing serves `SMOKE_URL`, and stops it at the end.
|
||||
Use `--no-serve` to require a running server, `--jobs <n>` to change the number of parallel tests, and `--timeout <seconds>` to change the limit for each test (default 180).
|
||||
@@ -216,6 +218,7 @@ A test states what it needs near its top. The runner skips the test, with the re
|
||||
| `SMOKE_URL` | The frontend address. The default is `http://127.0.0.1:1420`. When the runner starts Vite, it uses the port of this address, so two checkouts can run tests at the same time. |
|
||||
| `RUNESTONE_PLUGIN_REPOS` | The folder of the sibling plugin checkouts. The default is the parent folder of this repository. |
|
||||
| `RUNESTONE_TERMINAL_DIST` | The compiled Terminal plugin. The default is `RuneStone_Terminal/dist` in that folder. |
|
||||
| `RUNESTONE_CSP` | `1` sends and checks the content security policy. `--csp` sets it. |
|
||||
| `CHROME_PATH` | A Chromium browser for Playwright |
|
||||
| `PLAYWRIGHT_MODULE` | A different Playwright package |
|
||||
|
||||
@@ -227,6 +230,20 @@ To read or change a section later, use `window.__TEST__.settings(section)` and `
|
||||
A failed test saves `failure.png` in its output folder and prints the page console errors and warnings.
|
||||
You can also run one test file directly while `pnpm dev` runs, for example `node tests/smoke/tabs/order.smoke.mjs`.
|
||||
|
||||
### CSP mode
|
||||
|
||||
`--csp` sets `RUNESTONE_CSP=1`. With this variable, `vite.config.js` sends the policy from `src-tauri/tauri.conf.json` as a `Content-Security-Policy` header with each HTML page, as the installed app does.
|
||||
It adds only what the dev server needs:
|
||||
|
||||
| Directive | Addition | Reason |
|
||||
| --- | --- | --- |
|
||||
| `script-src` | The SHA-256 hash of each inline script in the page | Tauri adds the same hashes in the installed app. The SvelteKit start script is inline. |
|
||||
| `connect-src` | `ws://<address of the page>` | The Vite hot-reload WebSocket |
|
||||
|
||||
The harness records the `securitypolicyviolation` events of each page and frame, and fails the test when there is one. Violations inside workers do not reach the harness.
|
||||
The runner refuses to use a server at `SMOKE_URL` that does not send the policy. Stop that server, or set `SMOKE_URL` to a free port.
|
||||
The smoke tests do not replace a check in the installed app. The page there is the Tauri web view, and some plugins are not in the smoke tests. See [Content security policy](plugin-host.md#content-security-policy).
|
||||
|
||||
The tests in `tests/native/` attach to a running desktop app through the WebView2 remote-debugging port, and `pnpm smoke` does not run them.
|
||||
Set `NATIVE_CDP_URL` to the debugging address, for example `http://127.0.0.1:9224`.
|
||||
Before you start the app, set `WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS=--remote-debugging-port=<port>`. Each file states its port and variables at the top.
|
||||
|
||||
+75
-3
@@ -6,6 +6,8 @@ This reference describes how RuneStone stores, installs, downloads, and removes
|
||||
|
||||
- [Storage and recovery](#storage-and-recovery)
|
||||
- [Gitea downloads](#gitea-downloads)
|
||||
- [Content security policy](#content-security-policy)
|
||||
- [Window capabilities](#window-capabilities)
|
||||
- [Modules and checks](#modules-and-checks)
|
||||
|
||||
## Storage and recovery
|
||||
@@ -37,17 +39,37 @@ Each window asks for a new snapshot at these times:
|
||||
| --- | --- |
|
||||
| Window start | `startExternalPlugins` in `src/lib/plugins/external.ts` |
|
||||
| Window focus | The same function |
|
||||
| Every 5 seconds | The same function. It finds changes from a file manager. |
|
||||
| **Refresh** in Settings → Plug-ins | `PluginManager.svelte` |
|
||||
| `plugins-changed` event | Any change from another window |
|
||||
|
||||
A scan reads files and hashes only. It does not run code, install dependencies, or run scripts.
|
||||
There is no timed scan. A change from a file manager appears at the next focus or **Refresh**. RuneStone does not support packages that users copy into the folder.
|
||||
|
||||
A scan reads file metadata, and reads and hashes files only when necessary. It does not run code, install dependencies, or run scripts.
|
||||
|
||||
- A package with a changed hash gets an error and becomes disabled. The user must review it and enable it again.
|
||||
- When a package folder is missing, the service removes its catalog entry. It never restores a missing package.
|
||||
- A valid package that someone copies directly into `plugins/` appears as disabled, with an unknown install time.
|
||||
- The service never scans `plugin-staging/`.
|
||||
|
||||
### Package hashes
|
||||
|
||||
The package hash is a SHA-256 hash of all file names and contents. To avoid a full read of each package at each scan, the service keeps a cache in memory:
|
||||
|
||||
| Step | Reads |
|
||||
| --- | --- |
|
||||
| Scan (`plugins_snapshot`), `plugins_data`, and the row checks of other commands | The metadata of the package folder: entry names, file sizes, and modification times. The service reads and hashes the files again only when this metadata changed. |
|
||||
| Enable (`plugins_set_enabled`) and load (`plugins_load`) | All files. The hash must agree with the hash that the user saw (enable) or the installed hash (load). The cache cannot approve code. |
|
||||
| Asset (`plugins_asset`) | The metadata, then the one file. The file must have the SHA-256 hash from the last full read. |
|
||||
| Install, update, and removal | All files, as before. These steps also clear the cache entry of the package. |
|
||||
|
||||
The cache keeps the metadata from before each read. A file that changes during a read thus causes a new read at the next check.
|
||||
An edit that keeps the file size and the modification time stays hidden from a scan. The next load or asset read finds it, and the plugin then becomes disabled at the next scan.
|
||||
|
||||
### Waits for other windows
|
||||
|
||||
An update and a removal disable the plugin, then wait until no window holds a lease, at most 10 seconds.
|
||||
The wait uses a condition variable that `plugins_release` and window close signal. It does not keep the plugin lock while it waits.
|
||||
|
||||
### Install and update
|
||||
|
||||
1. The ZIP picker accepts at most 100 `.zip` files. Folders and loose manifests are not installation inputs.
|
||||
@@ -124,6 +146,55 @@ The review shows the repository, the tag, and the attachment link without its qu
|
||||
A change to the remote release after review does not change the pending installation.
|
||||
The same ID, enable, update, and removal rules apply to local and remote packages.
|
||||
|
||||
## Content security policy
|
||||
|
||||
`app.security.csp` in `src-tauri/tauri.conf.json` holds the policy. It limits what a page can load. It does not isolate plugins: a plugin module runs in the app window with the same access as the app.
|
||||
The policy stops a script that comes in through rendered content, for example a `<script>` element or an event attribute in a Markdown document.
|
||||
|
||||
| Directive | Sources | Reason |
|
||||
| --- | --- | --- |
|
||||
| `default-src` | `'self'` | All other types come only from the app. |
|
||||
| `script-src` | `'self' blob: 'wasm-unsafe-eval'` | `blob:`: plugin entry modules, which `external.ts` loads from Blob URLs. `'wasm-unsafe-eval'`: the PDF Viewer decodes JPEG 2000 and JBIG2 images and color profiles with WebAssembly in its worker. It does not permit `eval`. |
|
||||
| `style-src` | `'self' 'unsafe-inline'` | Svelte `style` attributes, the `style` attribute in `src/app.html`, Mermaid SVG styles, and the `<style>` elements of Monaco, the Vite dev server, and plugins (Terminal, CSV Viewer, PDF Viewer, Background Slideshow). |
|
||||
| `img-src` | `'self' data: blob: https: http:` | `data:`: workspace images, browser frames, tab and site icons, and icons in CSS. `blob:`: background images. `https:` and `http:`: remote images in Markdown previews. |
|
||||
| `font-src` | `'self' data:` | The Monaco icon font, and fonts that the PDF Viewer embeds. |
|
||||
| `connect-src` | `'self' ipc: http://ipc.localhost blob:` | `ipc:` and `http://ipc.localhost`: Tauri commands. `blob:`: the Background Slideshow worker reads its image from a Blob URL. |
|
||||
| `worker-src` | `'self' blob:` | `'self'`: Monaco workers. `blob:`: the PDF Viewer and Background Slideshow workers. |
|
||||
| `object-src` | `'none'` | RuneStone uses no plugins of the web view. |
|
||||
| `base-uri` | `'self'` | |
|
||||
| `form-action` | `'none'` | No form sends data to an address. |
|
||||
| `frame-ancestors` | `'none'` | |
|
||||
|
||||
No source permits `'unsafe-eval'`. The app, Monaco, Mermaid, and the current plugins do not use `eval` or `new Function`.
|
||||
`style-src` needs `'unsafe-inline'`, because style attributes and generated `<style>` elements have no nonce.
|
||||
|
||||
Tauri sends the policy as a header with each HTML page of the installed app. It adds the SHA-256 hash of the inline start script of SvelteKit to `script-src`.
|
||||
`dangerousDisableAssetCspModification: ["style-src"]` stops Tauri from adding nonces to `style-src`, because a nonce disables `'unsafe-inline'`. Tauri still adds the script hashes.
|
||||
`pnpm tauri dev` loads the page from the Vite server. Tauri does not apply the policy there. Use the [CSP mode](development.md#csp-mode) of the smoke tests, or an installed build.
|
||||
|
||||
Workers that the app loads from its own files get no policy. Workers from Blob URLs get the policy of the page.
|
||||
|
||||
## Window capabilities
|
||||
|
||||
`src-tauri/capabilities/` gives commands to window labels. A plugin can call every command that its window allows.
|
||||
|
||||
| Capability | Windows | Plugins | Commands |
|
||||
| --- | --- | --- | --- |
|
||||
| `default.json` | `main`, `workspace-*`, `terminal-*` | All enabled plugins | All app commands |
|
||||
| `settings.json` | `settings-main`, `settings-workspace-*` | All enabled plugins | Settings, plugins, backgrounds, completion, browser |
|
||||
| `browser.json` | `browser-*` | Only the built-in browser (`src/routes/+page.svelte`) | Browser, `plugins_snapshot`, settings, spelling, and window controls |
|
||||
|
||||
A browser window loads no installed plugin, so its capability has no workspace, file, Git, terminal, or plugin package commands. `tests/unit/plugins/windowCapabilities.spec.ts` and `tests/smoke/browser/window.smoke.mjs` check this.
|
||||
|
||||
The other windows load every enabled plugin. A smaller command set for them would limit only the app code, not the plugins. That split belongs to the plugin isolation work. Findings for that work:
|
||||
|
||||
- Terminal windows use the plugin host commands, `pty_*` through the Terminal plugin, and `core:window:allow-destroy`. Other plugins in the same window expect the full host API.
|
||||
- Settings windows use no `workspace_*`, `git_*`, or `pty_*` commands, but plugin settings views run there.
|
||||
- Commands that need a workspace (`workspace_*`, `git_*`, `pty_open`, `pty_new_window`) fail in a window without a bound workspace.
|
||||
- `pty_write`, `pty_resize`, and `pty_close` do not check the window that opened the terminal.
|
||||
- `backgrounds_*`, and `browser_request` without a browser session token, need a plugin lease of the calling window.
|
||||
- A new command for plugins goes in `default.json` and, if settings views need it, in `settings.json`. Add it to `browser.json` only when the built-in browser needs it.
|
||||
|
||||
## Modules and checks
|
||||
|
||||
| Module | Owns |
|
||||
@@ -154,7 +225,7 @@ To make it without a release ZIP, run `node scripts/build.mjs --no-package` in t
|
||||
Unit tests:
|
||||
|
||||
```powershell
|
||||
node --experimental-strip-types --test tests/unit/plugins/plugins.spec.ts tests/unit/plugins/externalPlugins.spec.ts tests/unit/plugins/pluginPackaging.spec.ts tests/unit/plugins/pluginHostExtensions.spec.ts tests/unit/plugins/pluginDocuments.spec.ts tests/unit/plugins/pluginAccess.spec.ts tests/unit/plugins/completion.spec.ts tests/unit/theme/backgrounds.spec.ts
|
||||
node --experimental-strip-types --test tests/unit/plugins/plugins.spec.ts tests/unit/plugins/externalPlugins.spec.ts tests/unit/plugins/pluginPackaging.spec.ts tests/unit/plugins/pluginHostExtensions.spec.ts tests/unit/plugins/pluginDocuments.spec.ts tests/unit/plugins/pluginAccess.spec.ts tests/unit/plugins/completion.spec.ts tests/unit/plugins/windowCapabilities.spec.ts tests/unit/theme/backgrounds.spec.ts
|
||||
```
|
||||
|
||||
Native tests use real temporary files and archives:
|
||||
@@ -173,6 +244,7 @@ node tests/smoke/plugins/choiceMenus.smoke.mjs
|
||||
node tests/smoke/find/pluginViews.smoke.mjs
|
||||
node tests/smoke/tabs/lastTabAndSiteIcons.smoke.mjs
|
||||
node tests/smoke/settings/general.smoke.mjs
|
||||
node tests/smoke/browser/window.smoke.mjs
|
||||
```
|
||||
|
||||
`pluginInstall.smoke.mjs` covers the link form, download errors, token clearing, cancel, focus, and disabled installation.
|
||||
|
||||
Reference in New Issue
Block a user