Skip to content

feat(plugins): let a plugin ask to reach a network origin at runtime - #2963

Closed
LordMelkor wants to merge 1 commit into
block:mainfrom
LordMelkor:clod/plugin-runtime-origins
Closed

LordMelkor wants to merge 1 commit into
block:mainfrom
LordMelkor:clod/plugin-runtime-origins

Conversation

@LordMelkor

@LordMelkor LordMelkor commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Problem: host.request reaches only the origins fixed in a plugin's manifest, so a public plugin can't reach a self-hosted server whose address differs for each person, such as a Plane board.
  • Change: host.requestOrigin?(origin): Promise<boolean> asks Buzz to let the calling plugin reach one exact https://host[:port] origin. Before it saves anything, Buzz shows a native dialog that names the plugin and the origin, with Allow and Don't Allow. The call resolves true when the person allows it, and false when they decline. Approved origins are kept apart from the manifest's grants: only host.request, its byte reads and uploads see them. They are kept across restarts and updates from the same source and publisher, and forgotten when the plugin is removed. What this plugin can do in Settings lists them, and so does the dialog where the owner reviews an agent's request to enable the plugin. No FOUNDATION file is edited.
  • Size: production +286/−18; tests +496/−1; docs +60. The test logs are in Validation, at the end.

Problem

A plugin can call host.request only for origins fixed in its manifest. That rules out a public plugin for a self-hosted service, such as a Plane project board, where each person's server URL is different. Today such a plugin needs a per-user manifest edit and an install from a folder, or a server that rewrites the manifest.

Change

  • host.requestOrigin?(origin): Promise<boolean>. The calling plugin asks to reach one more exact https://host[:port] origin with its request, byte and upload calls.
    • It resolves true when the person allows it, and at once, with no dialog, when the manifest declares the origin or the person already approved it. A plugin can call it on every start.
    • It resolves false when the person declines. Nothing is saved, and the origin stays refused.
    • It rejects on a malformed or wildcard origin, outside an installed desktop plugin, in safe mode, when the plugin was disabled or updated, and while another network access dialog is open.
  • Buzz asks natively. A dedicated command, plugin_host_request_origin, checks the origin and the calling plugin, then shows a native message dialog parented to the app window: "Allow network access?", "Let “Board client” connect to https://plane.example.org:8443? The plugin can then make HTTPS requests to this address until you remove it.", Allow and Don't Allow. It saves the origin only after Allow.
    • Why native. Plugin modules are loaded with import() into the main web view, so plugin code shares the host's JavaScript realm and can call every command the host can. Any prompt drawn in the web view, or any token minted there, is one plugin code could draw, skip or forge itself. A dialog shown by the native command, before it saves, is one plugin code can neither draw nor skip.
    • Order. Check, then dialog, then save. The save repeats its checks under the registry lock (installed, enabled, same revision, not safe mode), so a plugin disabled, updated or removed while the dialog is open saves nothing.
    • One dialog at a time. While one is open, another call rejects with "Another network access request is open" instead of stacking dialogs.
  • Grants stay split. host_grants returns the manifest's grants only, as on main. A separate read, request_grants, adds the approved origins, and only the three host.request checks use it: requests, byte reads and uploads. Gateway forwarding, federated identity, MCP, processes and files still read the manifest alone, so an approved origin can't enable gateway forwarding.
  • Storage. Approved origins are stored per plugin in the plugin registry (approved_origins), not in the manifest, up to 64 per plugin.
  • Updates. An install, update, reload or rollback keeps the approved origins only when the new code comes from the same location and the same publisher. Same location means the same plugin folder, the same Git repository and path (whatever the commit or reference), or the same URL. Same publisher means both unsigned, or the same signer. Otherwise the list starts empty. A package with no recorded source, such as a dropped folder, never keeps the list. A URL install updated from a different URL, or a managed update that replaces a Git install with a URL, also starts empty, so the plugin asks again. Reloading a folder applies the same rule, so a folder that is now signed starts empty.
  • plugin_change is as on main. The management command no longer saves origins, so it again retires the plugin's registrations around every action.
  • Access reviews. "What this plugin can do" in Settings lists approved origins beside the declared ones, and so does the dialog where the owner reviews an agent's request to enable the plugin.
  • Docs. docs/plugin-authoring-guide.md documents the call and gives a settings-card recipe for the self-hosted case: the person types their server address in the plugin's own settings, the plugin calls requestOrigin, Buzz asks, and on true the plugin calls request. docs/plugin-architecture.md has the contract.

Intent

The person agrees to let one named plugin reach one exact origin at runtime, in a prompt Buzz draws. That answer is remembered for that plugin, and host.request then reaches the origin. An origin they decline stays blocked.

  • Out of scope: SSE and streaming responses, revocation UI beyond what Settings can list, wildcard origins, IP or private-address filtering, and any change to how manifest origins work.
  • Acceptance: before approval, host.request to the origin is refused, and after it, allowed. Declining keeps it refused. Approval survives a restart. Another plugin isn't granted. No path that plugin code can reach saves an origin without the person's answer in the Buzz-drawn dialog.

Known limitations

  • Loopback and private hosts are allowed. The runtime path accepts the same origins as the manifest path (valid_origin, crates/plugin-manager/src/lib.rs:351), including https://localhost, private and link-local addresses. Self-hosted servers on a LAN or on the same machine are the use case, and the dialog names the exact origin the person allows. This PR adds no IP filtering. A plainer warning in the dialog for these hosts, such as "This address is on your own computer or network" when the host is loopback, link-local, private or an IP literal, would help; it isn't in this PR.
  • An image read that spans the dialog. A plugin with host.publicImages starts an image read from an origin it hasn't declared, then gets that origin approved before the read finishes. The completion check (src-tauri/src/host_request.rs:476 on main) sees the reach change from public image to declared and fails the read with "Host request origin is not declared". Nothing is let through that shouldn't be, and a retry succeeds.
  • No per-origin revoke. Removing the plugin is the only way to forget an approved origin. Settings lists them; revocation UI beyond that is out of scope.
  • Update reviews show the manifest change only. An update from the same location and publisher keeps the plugin's approved origins, but the update and import reviews compare the old and new manifests and don't list them. Settings and the agent enable dialog do. If a later version declares an origin the person had already approved, both access lists show it twice.
  • The dialog trusts the caller's plugin id. Like every host command, plugin_host_request_origin takes the plugin id and revision from its caller, and plugin code shares the main web view. So one plugin can raise the dialog under another installed plugin's name, and on Allow the origin is saved for that other plugin. The first plugin can then reach it through the other plugin's id, as it already can with that plugin's manifest origins. It can't save an origin without the person's answer. Binding host calls to the calling plugin would change every host command, not just this one.
  • The dialog names the plugin by its manifest name only, as the access review and the agent enable dialog do. It doesn't show the id or the source.
  • A decline isn't remembered. After Don't Allow, the plugin can ask again. Only one dialog can be open at a time.
  • Bidirectional format characters in a plugin name. The dialog gets the name without control characters, but format characters such as U+202E (right-to-left override) stay, and they can reorder the text after the name. That takes a manifest name built to do it.
  • No test for the Linux % escape. The dialog can't be shown in tests, and the escape is one line inside the command that shows it (host_request.rs:249).
  • One dialog for the whole app. The one-at-a-time rule spans plugins: while one plugin's dialog is open, another plugin's call rejects rather than waits. The plugin can show the error and let the person try again.
  • Feature detection on the web build. The guide's typeof ctx.host.requestOrigin check detects older desktop hosts. On the web build the method exists and rejects, so a plugin should also handle the rejection.
  • Automated agent review. An independent agent reviewed this round; it found five things. Four are fixed: the GTK format string in the dialog message, a folder reload that skipped the carry-over rule, a folder source compared by its scan root rather than the plugin folder, and a NUL character in a plugin name. The manifest accepts one; the Linux dialog backend panicked on it, and the Windows one ended the message there, so the origin wasn't shown. The dialog now gets the name without control characters; a review of that fix found one more, the bidirectional characters item above. One is left:
    • A byte-identical reinstall while the dialog is open. The save rechecks the plugin's id, enabled state and revision, which is a hash of the package. If the same package is installed again from another folder, or removed, reinstalled and re-enabled, while the dialog is still open, Allow then saves to the new installation. That takes a second management path, such as the CLI, racing an open dialog.

Core change check

Each core change is measured against this project rule: a feature a plugin can build belongs in a plugin, and core adds only the smallest general capability a plugin needs to own that feature.

Core change Necessity Minimality
crates/plugin-manager/src/lib.rs (+156/−8 outside tests): approved_origins per plugin (:687), the check origin_request (:1674) and save approve_origin (:1684) sharing unreached_origin (:1693), request_grants (:1658), and the carry-over rule same_publisher_and_location (:367) used by install (:1377), rollback (:1470) and folder reload (:1597) On main, host_grants returns only the manifest's host (crates/plugin-manager/src/lib.rs:1570-1587), and every native request path refuses other origins with "Host request origin is not declared" (src-tauri/src/host_request.rs:252, :552, :560, :656). A plugin's origins are fixed at install: a changed manifest.host waits for the owner's update review. No management action adds an origin: plugin code that tries ends at "Unknown management action" (lib.rs:1423). So no plugin can reach a URL the person types. One list per plugin. One check and one save, so the native command can ask between them without holding the registry lock; both apply the same checks through one helper. One grant read for the request paths; host_grants (:1637) is unchanged from main, so gateway forwarding (src-tauri/src/host_forward.rs:917-937) and every other reader of network_origins see the manifest only. One rule for carry-over, used at the three places the current source or signature changes. The 64-origin cap bounds the list that every request reads. Nothing names a plugin or a service.
src-tauri/src/host_request.rs (+82/−5): the plugin_host_request_origin command (:233) with its native dialog (:250), the check-ask-save logic request_origin (:271), the one-dialog lock (:227, :288), and request_grants at the request (:319), byte (:612) and upload (:682) checks Plugin modules are loaded with import() into the main web view (src/plugins/modules.ts:26 on main), so plugin code shares the host's JavaScript realm and can invoke every Tauri command the host can. A consent prompt drawn in that view, or a token minted there, is one plugin code can draw, skip or forge; HostCalls::consume (host_request.rs:80) accepts caller-chosen ids, so it guards against replay and proves nothing about consent. A plugin can't produce consent the host can trust. Only a dialog the saving command shows itself can. One native confirm inside the one command that saves an origin. No web-view UI, no queue and no FOUNDATION file: a call while a dialog is open rejects. On Linux the message escapes % (:249), because the GTK backend reads it as a printf format. The three request checks change one call each; byte reads and uploads already share the request's origin rule.
src-tauri/src/lib.rs (+3/−1), src-tauri/build.rs (+1) and src-tauri/capabilities/default.json (+1): register the command A Tauri command needs a handler entry, a generated permission and a capability grant, like every plugin_host_* command beside it. One name in each list. plugin_change (lib.rs:673) is unchanged from main.
src/features/host/service.ts (+22): host.requestOrigin (:253, :707) On main, Host has request and no call that adds an origin (src/features/host/service.ts:244). Every documented host call binds to the caller through ctx.pluginOwner, as request does (service.ts:687). One optional method that forwards the caller's own id and revision with the origin and returns the native answer. It draws no UI and keeps no state.
src/app/PluginAccessReview.tsx (+15), src/app/PluginMenu.tsx (+2/−2) and src/app/AgentPluginRequests.tsx (+2/−2): approved origins in the access reviews On main, "What this plugin can do" (src/app/PluginMenu.tsx:132) and the agent enable dialog (src/app/AgentPluginRequests.tsx:300) render only the manifest's grants, so the owner couldn't see an approved origin. A plugin can't add to the host's access review. One function that merges the stored list into the manifest view both existing reviews already render.
src/plugins/types.ts (+2) The renderer's PluginInfo (src/plugins/types.ts:3) mirrors the native PluginInfo (crates/plugin-manager/src/lib.rs:903 on main), which now carries the list. One optional field.
crates/plugin-manager/src/managed.rs (+1) A test fixture only: it sets the new field. One line.
Tests and docs: src-tauri/src/host_request/origin_tests.rs, replay_tests.rs, host_forward/tests.rs, the tests in crates/plugin-manager/src/lib.rs, service.test.ts, PluginUpdates.test.tsx, AgentPluginRequests.test.tsx, author.test.mjs, docs/plugin-architecture.md, docs/plugin-authoring-guide.md Not runtime code. Not runtime code.

Line numbers are at the head unless marked "on main". Names: a grep of the core diff for every src/bundled directory name finds two plugin IDs, both test fixtures. buzz.reminders in the lib.rs tests checks that a bundled plugin can't request an origin, and buzz.channels in service.test.ts checks the same in the host service. No FOUNDATION file is changed.

Merge order

Independent: this PR depends on no other open PR, and no open PR depends on it. It can merge in any order.

Validation

The head f04fa100f is one commit on main e9f6f53ff. It squashes four commits: the earlier head efa7dde12 rebased with no conflicts as 4dc4754ee, then this round's 6d8adf001 and 782d88fff, and a last fix that removes control characters from the plugin name before the dialog is built. That fix changes one line in src-tauri/src/host_request.rs and the route test's fixture.

Run on a separate Linux machine at f04fa100f:

  • cargo fmt --all --check: pass.
  • cargo test --lib in src-tauri, filtered: host_request 59 passed, host_forward 18 passed, federated_identity::access 6 passed and browser_permissions 1 passed. None failed.
  • With the name filter undone, the route test fails with left: "Origins\0 fixture", right: "Origins fixture".
  • The three pre-push lanes (scripts/check-push.mjs, --design, --clippy): all three pass. The types lane ran tsc and 2,422 related tests in 61 files, none failed (12 skipped). The Clippy lane found nothing.

The landmines Oxlint rules, on the lines this PR adds against e9f6f53ff, report two no-test-doubles findings, src/features/host/service.test.ts:1857 (vi.mocked(invoke).mockResolvedValue) and :1881 (vi.mocked(isTauri).mockReturnValue), which stay because they follow that file's own way of standing in for the Tauri bridge in unit tests (main's copy sets return values on the mocked invoke or isTauri 94 times).

Run at 782d88fff, the tree before that last fix:

  • cargo test -p buzzodz-plugins: 203 passed, none failed.
  • cargo test --lib in src-tauri, filtered: host_request 59 passed, host_forward 18 passed, federated_identity::access 6 passed and browser_permissions 1 passed (it checks the command ACL). None failed.
  • pnpm exec tsc --noEmit, pnpm exec biome check --error-on-warnings . and pnpm run design:check: pass.
  • pnpm exec vitest run on the host-service, access-review, agent-request, plugin-update, managed-plugin and author-package suites: 215 passed in 6 files, none failed.
  • Full pnpm exec vitest run: 23,616 tests passed in 1,163 files, none failed (31 tests and 9 files skipped).
  • The three pre-push lanes (scripts/check-push.mjs, --design, --clippy) at this SHA: all three pass. The types lane ran tsc and 2,422 related tests in 61 files, none failed (12 skipped). The Clippy lane found nothing.
  • The same set also passed at 6d8adf001, before the review fixes.

The gateway test fails on the earlier head. On efa7dde12, with the same test approving the origin through that head's allow-origin action, it fails with left: Ok(()), right: Err("The agent gateway is not declared"): the approved origin let the plugin forward.

What the tests cover:

  • Real command IPC (src-tauri/src/host_request/replay_tests.rs): plugin_host_request to a loopback origin fails with "Host request origin is not declared". The check-ask-save route with a declining answer returns false, and the same request is still refused. With an allowing answer it returns true, and the request passes the origin check: it reaches the listener and fails at its untrusted TLS ("Host request failed"). The native dialog itself is replaced by the answer; the mock app has no dialog.
  • The route (src-tauri/src/host_request/origin_tests.rs): an origin already declared or approved returns true and never asks, and the dialog gets the plugin's name without control characters (the fixture's name contains a NUL). A malformed, wildcard or http origin errors before asking. A plugin disabled or updated while the dialog is open saves nothing. A second request while one is open rejects, and the next one after it can ask.
  • Gateway forwarding (src-tauri/src/host_forward/tests.rs): an external plugin with an approved gateway origin fails granted() with "The agent gateway is not declared".
  • Plugin manager (crates/plugin-manager/src/lib.rs):
    • An approved origin extends only that plugin's request grants, and another plugin isn't granted. It survives reopening the registry and an update from the same folder. Asking is refused for a stale revision, in safe mode and for a disabled plugin. Removing the plugin forgets it.
    • A same-folder update keeps the list. An install that adds a signer, an install from another folder, a rollback to code from another folder, and a reload of a folder that is now signed each clear it.
    • Malformed origins are refused: http, a path, a trailing slash, a query, credentials, the default port, a wildcard, ftp, a missing scheme and an empty string. The 65th origin is refused, and so is a bundled plugin.
  • Host service (src/features/host/service.test.ts): requestOrigin calls plugin_host_request_origin with the calling plugin's id, running revision and the origin, and returns the native true or false. A bundled plugin, a context with no plugin and the browser are refused without a native call. These tests set return values on the mocked invoke and isTauri, as the file already does in many other places.
  • Settings (src/app/PluginUpdates.test.tsx) and agent enable request (src/app/AgentPluginRequests.test.tsx): the access reviews list an approved origin.

Removed: the tests for allow-origin through plugin_change and for the predicate that kept registrations for it, which no longer exist.

End-user test (AGENTS.md step 3)

An end-user test by the maintainer's agent on a separate Linux machine. It used the real desktop app (a debug build from pnpm tauri build --debug --no-bundle) under Xvfb with the openbox window manager, driven by a WebDriver script, against a real local relay. Buzz's consent prompt is a native GTK dialog, outside the web view, so the script found it in the window manager's client list (_NET_CLIENT_LIST) and clicked its buttons with xdotool. Each step is scripted and has a screenshot; the step 11 screenshot is a full-display capture with the dialog open.

  • Builds: PR head f04fa100faa31f3a7eae1ad459ff8e34e768f856. The control is the merge base on main, e9f6f53ff4e082bf145ea0dc54efd4112f4cd7ae. Main did not change, so the control run is reused from the earlier run of this test at head 69cf37bed546e93c4c010d2941735f276780e990; steps 1 to 10 were run again on the new head, and step 11 is new.
  • Relay: block/buzz a26eacde491b39c3ebc0084622d66d2df2b10803, behind a local TLS proxy at wss://localhost that uses a throwaway CA. The app used a new throwaway identity and joined the localhost community.
  • Target server: nginx on the same machine at https://localhost:8443. Its certificate comes from the same throwaway CA, which is in the system trust store. GET /api/me returns {"user":"tester","server":"board-test"}. Its access log shows which requests reached it.
  • Plugins: three folders. None declares networkOrigins, and all three inject host, react and settingsCards. Each was installed the way a person installs one: Settings → Manage plugins → Add → Browse, pick the folder in the folder chooser, review the access shown, then Install plugin.
    • "Board client" has the settings-card recipe from docs/plugin-authoring-guide.md, unchanged apart from its title. It also has a test section with its own URL field and three buttons. "Test request" calls host.request for <origin>/api/me. "Ask as typed" calls requestOrigin with the raw text. "Ask twice" makes two requestOrigin calls at once.
    • "Other client" has a URL field and a "Test request" button. It never calls requestOrigin.
    • "Null client" (step 11) is a copy of Board client with its own plugin id and the manifest name "Null client" with a NUL character (U+0000) after "Null", written as a JSON escape in manifest.json.

On head:

  1. Install both plugins. Both access reviews showed "Computer access" and "No additional capabilities declared". Both plugins installed, and their cards appeared in Settings.
  2. Board client, "Test request" before asking. It failed with Error: Host request origin is not declared. The server got no request.
  3. Connect, then Don't Allow. With https://localhost:8443 typed, Connect opened one new window: Buzz's native dialog, titled "Allow network access?", saying "Let “Board client” connect to https://localhost:8443? The plugin can then make HTTPS requests to this address until you remove it.", with the buttons Allow and Don't Allow. After a click on Don't Allow, the dialog closed and the card showed the recipe's "Not connected: Buzz was not allowed to reach it." (so requestOrigin resolved false). "Test request" still failed with Host request origin is not declared, the server got no request, and the access review still showed "No additional capabilities declared".
  4. Connect again, then Allow. The dialog opened again. After a click on Allow, the card showed "Connected (200)" and the server logged the request (User-Agent Buzz/1.0.1). "Test request" then returned status 200 with the JSON body.
  5. Access review. "What this plugin can do" for Board client listed "Connect to https://localhost:8443: Buzz can make HTTPS requests to this address for the plugin." It was there the first time the review was opened, 7.7 s after Allow (that includes the follow-up request), with no restart. The review for Other client still showed "No additional capabilities declared".
  6. Ask again for the allowed origin. "Ask as typed" with https://localhost:8443 resolved true, and no new window appeared in the 3 s the script watched the window list.
  7. Other client, same URL. It failed with Error: Host request origin is not declared. The server got no request.
  8. Restart. The app was quit and started again with the same state. It got a new process, and it signed back in without a new sign-in. In Board client, "Test request" returned status 200, and no dialog appeared. In Other client, it still failed with Host request origin is not declared. The access review still listed the origin.
  9. Malformed origins. requestOrigin("https://board.example.org/path"), ("http://localhost:8443") and ("https://localhost:443") rejected with Invalid HTTPS origin: use https://host[:port], with no path. requestOrigin("https://*.example.org") rejected with Wildcard origins cannot be approved. No dialog appeared for any of them.
  10. Two asks at once. "Ask twice" with a new origin, https://board.example.org, opened exactly one dialog. After Don't Allow, one call resolved false and the other had rejected with Another network access request is open. The access review still listed only https://localhost:8443.
  11. A plugin name with a NUL in it. Null client installed through the same path (its review read "Review Null client", and its Settings entry reads "Null client"). With https://localhost:8444 typed (nothing serves that address), Connect opened one native dialog, titled "Allow network access?", reading "Let “Null client” connect to https://localhost:8444? The plugin can then make HTTPS requests to this address until you remove it." The app's process was the same before, during and after, and the web view still answered. After a click on Don't Allow, the dialog closed, the card showed "Not connected: Buzz was not allowed to reach it." (requestOrigin resolved false), and the access review for Null client showed "No additional capabilities declared", with no origin listed. This run didn't try the name on the earlier head. There, the dialog library's Linux backend builds the message with CString::new(…).unwrap(), which panics on a NUL.

In the whole head run, the target server logged three requests from the app (none for localhost:8444), and all of them came from Board client after Allow: one at Connect, one from "Test request" after it, and one after the restart. No refused request reached the server.

On main (control): Board client installed the same way. Its card showed the recipe's "Update Buzz to connect your server." branch, because requestOrigin is absent there ("Ask as typed" reported requestOrigin is absent, and no dialog appeared). "Test request" failed with Error: Host request origin is not declared, and the server got no request. The access review showed "No additional capabilities declared".

The dialog was clicked on Linux only. On macOS and Windows, the mapping from button to result was read in the dialog libraries' source (tauri-plugin-dialog 2.8.3 and rfd 0.16.0): Allow resolves true, and Don't Allow, closing the dialog or Escape resolve false.

Try it

  1. In a dev plugin with no networkOrigins, call await ctx.host.request({ url: "https://httpbin.org/get" }). Expected: it throws "Host request origin is not declared".
  2. Call await ctx.host.requestOrigin("https://httpbin.org"). Expected: Buzz shows "Allow network access?", naming the plugin and https://httpbin.org.
  3. Click Don't Allow. Expected: the call resolves false, and the request in step 1 still throws.
  4. Call it again and click Allow. Expected: the call resolves true, the request succeeds, and Settings → Plugins → Manage plugins → the plugin row's "More actions" menu → "Review access" lists https://httpbin.org. A third call resolves true with no dialog.
  5. Restart Buzz. Expected: the request still succeeds with no dialog. A second plugin's request to the same URL is refused.

🤖 Generated with Claude Code

@LordMelkor
LordMelkor requested a review from a team as a code owner November 7, 2026 02:29
@kazemek21

Copy link
Copy Markdown
Contributor

instructions to get the build to run: buzz://message?channel=5909b3f1-fbe6-4f63-9cd2-06440e58b4a1&id=41538c84fc77a64cc0d124407b31805e3d485d331654a91b5185d62dc9245b05&thread=71a8d710754540d5c562226840389021badb3398752eb76d821d2a5b6c2b16ba

@LordMelkor
LordMelkor force-pushed the clod/plugin-runtime-origins branch from f7892f3 to 5fca0f9 Compare November 10, 2026 15:55
@man15h

man15h commented Nov 11, 2026

Copy link
Copy Markdown

+1, and a concrete use case: a plugin for a self hosted project board (Plane) or any self hosted service, where each user's server URL is different. Today the only options are a per user manifest edit plus install from folder, or a server that rewrites the manifest. requestOrigin with consent would let one public plugin work for everyone.

@LordMelkor
LordMelkor force-pushed the clod/plugin-runtime-origins branch 2 times, most recently from 76bd4f9 to a2abb2b Compare November 17, 2026 20:00
@LordMelkor LordMelkor changed the title feat(plugins): let the owner approve network origins at runtime feat(plugins): let a plugin add network origins at runtime Nov 17, 2026
@LordMelkor
LordMelkor requested a review from joahg November 18, 2026 19:29
@LordMelkor
LordMelkor force-pushed the clod/plugin-runtime-origins branch 2 times, most recently from 5704d41 to efa7dde Compare November 18, 2026 21:45

@joahg joahg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Requesting changes for the two P1s inline.

The grant mechanics are sound:

  • Storage is per plugin, merged only into that plugin's host_grants, and enforced in Rust.
  • Only bare https origins are accepted: no wildcard, path, credentials, default port or punycode form.
  • There's a cap of 64 origins.
  • Revision, enabled and safe-mode are rechecked under the lock.
  • Origins are dropped when the plugin is removed.
  • Rust, replay-IPC and TS tests cover it.

The problem is that the host-drawn consent was removed, so the manifest no longer caps network reach. Any installed plugin can approve itself for any https origin, including loopback and private addresses. It can also approve the agent-gateway origin, which gates host forwarding. I read this from the code and did not run the tests.

A human maintainer needs to review this PR. The permissions dialog changes are user-visible, so it also needs a design reviewer.

Comment thread crates/plugin-manager/src/lib.rs Outdated
p.enabled = true;
}
"disable" => p.enabled = false,
_ if action.starts_with(ALLOW_ORIGIN) => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 P1: The allow-origin action has no consent gate. Buzz shows no prompt (the PR says so), and the native command trusts any caller. plugin_change takes a caller-supplied id and revision, so host.allowOrigin binding to ctx.pluginOwner is a convenience, not a boundary. A plugin that installed with 'No additional capabilities declared' can call this for any https://host[:port], then read responses and POST data to it. valid_origin also accepts https://localhost, https://127.0.0.1, https://169.254.169.254, RFC1918 literals and https://[::1]. The private-IP filtering in host_request/public_image.rs applies only to public image reads, so declared and approved origins get no SSRF guard. The manifest therefore stops being an upper bound on network reach, and the install and update reviews no longer describe what the plugin can do. The first version of this PR drew a host prompt; removing it moved the security decision into plugin code. Suggest one of: (a) restore a host-drawn confirmation that mints a one-time token the native action requires; or (b) at minimum make runtime origins a manifest-declared capability (for example host.runtimeOrigins: true, shown in the install review) and reject loopback, private, link-local and IP-literal hosts in the runtime path. Add negative tests for those hosts.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 @joahg Fixed in f04fa10. Buzz now shows a native dialog before it saves anything: "Allow network access?", naming the plugin and the exact origin, with Allow and Don't Allow.

I used a native dialog rather than a web prompt with a one-time token. Plugin modules are loaded with import() into the main web view (src/plugins/modules.ts:26), so plugin code can call every command the host can. A token minted in that view could be minted by the plugin too: HostCalls::consume accepts caller-chosen ids. The dialog is shown by the only command that saves an origin, plugin_host_request_origin, so plugin code can neither draw it nor skip it. allow-origin is gone from plugin_change, so plugin_change matches main again.

  • The JS call is now host.requestOrigin(origin): Promise<boolean>. It resolves false when the person declines, and nothing is saved.
  • The command checks, then shows the dialog, then saves. The save rechecks installed, enabled, revision and safe mode under the registry lock. Only one dialog can be open at a time.
  • An origin the plugin already reaches returns true with no dialog. A malformed, wildcard or http origin errors before the dialog opens.
  • The PR body's end-user test section has the run in the real desktop app on Linux, with the dialog, Allow, Don't Allow and a restart.

About option (b): runtime origins pass the same valid_origin check as manifest origins, so this path accepts nothing a manifest can't declare. Loopback and LAN hosts are the use case: a self-hosted server on the same machine or network. The dialog names the exact origin, so I kept them allowed and listed that under Known limitations.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 The consent gate holds. allow-origin is gone from plugin_change. The dialog is drawn by plugin_host_request_origin itself, which is the only path that saves an origin. A plugin cannot skip it or answer it, and a forged id or revision cannot bypass it. A wrong or stale revision errors under the registry lock, and the save is re-checked after the dialog returns. Wildcard, http, path and default-port origins error before the dialog opens. Two things remain, both P2 and not blockers. (a) Loopback, private, link-local and IP-literal hosts are still accepted, so that half of my comment was not fixed, only mitigated by the consent gate. A stronger dialog warning for those hosts would be good. (b) The dialog names the plugin only by its manifest name. id is caller-chosen, so plugin A can raise the dialog under plugin B's name, and a declined prompt can be repeated in a loop. Please show the id and publisher, and throttle after a decline.

let mut grants = artifact.manifest.host.unwrap_or_default();
// The native request check reads only these, so an origin allowed at
// runtime reaches every request path and no other plugin's.
for origin in approved {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 P1: Merging approved origins into host_grants().network_origins widens every consumer of that list, not only host.request. src-tauri/src/host_forward.rs granted() (lines ~916-937, used by plugin_host_forward_admission and plugin_host_forward_open) allows a plugin to use the agent-gateway forwarder if network_origins contains the gateway origin, a manifest-declared grant the owner reviewed. A plugin can now call allowOrigin(<gateway origin>) and gain gateway forwarding, which composes Buzz context headers, without declaring it. Keep approved origins out of host_grants and add them only in the host_request request, byte and upload checks (allows_origin / reach), or explicitly exclude the gateway origin. Add a test that an approved gateway origin does not pass granted(). I read this from the code and did not run it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 @joahg Fixed in f04fa10. host_grants is manifest-only again, as on main. A separate request_grants adds approved origins, and only the request, byte-read and upload checks in host_request.rs call it. granted() and every other grant reader see the manifest alone.

an_origin_approved_at_runtime_does_not_grant_forwarding in src-tauri/src/host_forward/tests.rs covers this. On efa7dde12, the same test fails with left: Ok(()).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Fixed. host_grants is manifest-only again. Approved origins go through the new request_grants, and only plugin_host_request, the byte reads and the upload path call it. I checked every other host_grants reader and none of them sees approved origins: host_forward granted(), host_mcp, host_files, host_command, host_process, federated_identity, and the CSP, which is static in tauri.conf.json. an_origin_approved_at_runtime_does_not_grant_forwarding passes.

Comment thread crates/plugin-manager/src/lib.rs Outdated
});
let enabled = enable || old.is_some_and(|p| p.enabled);
let update_checks = old.and_then(|p| p.update_checks);
let approved_origins = old.map_or_else(Vec::new, |p| p.approved_origins.clone());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 P2: approved_origins is copied from old on every install over an existing id, so it survives update, reinstall and an install from a different source or publisher, and host_grants applies it to the new revision's code. The update and import reviews compare manifests only, so the owner never sees that new code inherits these origins (the PR lists this as a known limitation). Combined with the missing consent gate, an update can reuse network reach that was never reviewed for that code. Consider clearing approved origins when the install source or publisher changes, and listing carried-over origins in the update review.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 @joahg Fixed in f04fa10. Approved origins now carry over only when the new code comes from the same location and the same publisher:

  • Same location: the same plugin folder, the same Git repository and path (whatever the commit), or the same URL.
  • Same publisher: both unsigned, or the same signer.

Otherwise the list starts empty. The rule applies at install, update, rollback and folder reload. Listing carried-over origins in the update review isn't in this round; that's under Known limitations.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Fixed. Origins carry over only when same_publisher_and_location is true, meaning the same signer (or both unsigned) and the same folder, the same Git repository and path, or the same URL. An unknown source matches nothing, so legacy entries clear. It is applied at all three sites that change current: install/update, rollback and folder reload. The new test covers unsigned to signed, a different folder and rollback. Removing a plugin drops its origins, so a reinstall starts empty.

A public plugin for a self-hosted service can't reach the server the
person types, because host.request reaches only the origins fixed in the
plugin's manifest.

Add host.requestOrigin(origin): Promise<boolean>. A dedicated native
command checks the origin and the calling plugin, shows a native dialog
naming the plugin and the origin, and saves the origin only when the
person allows it. Plugin code shares the host's web view, so only a
dialog the saving command shows proves the person answered. The save
repeats its checks under the registry lock, so a plugin disabled,
updated or removed while the dialog is open saves nothing. An origin the
plugin already reaches resolves true with no dialog, declining resolves
false, and a call while a dialog is open rejects. The dialog gets the
plugin's name without control characters, which the Linux backend
refuses and the Windows one ends the text at. On Linux the message
escapes `%`, because GTK reads it as a printf format.

Approved origins are stored per plugin and kept apart from host_grants:
a separate grant read adds them only for host.request, byte reads and
uploads, so gateway forwarding and every other grant check read the
manifest alone. An install, update, reload or rollback keeps them only
when the code comes from the same location and publisher. Settings and
the agent enable dialog list them in the plugin's access review.

Co-authored-by: Clod <c7b21872e9ddb79ca62967d0e21e6a4518a669eb04648e963cdfb2426e62fafb@buzz.block.builderlab.xyz>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: LordMelkor <kray@squareup.com>
@LordMelkor
LordMelkor force-pushed the clod/plugin-runtime-origins branch from efa7dde to f04fa10 Compare November 19, 2026 05:51
@LordMelkor LordMelkor changed the title feat(plugins): let a plugin add network origins at runtime feat(plugins): let a plugin ask to reach a network origin at runtime Nov 19, 2026

@joahg joahg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Follow-up on efa7dde. f04fa10 resolves both P1s:

  • Consent: a native dialog is drawn by plugin_host_request_origin, which is the only command that saves an origin.
  • Grant split: host_grants is manifest-only again. granted(), the CSP and every other grant reader see the manifest alone.
  • Carry-over: install, rollback and folder reload all clear approved origins when the location or publisher changes.

Two P2s remain inline. Neither blocks:

  • Loopback, private and IP-literal hosts are still accepted, so a stronger warning in the dialog would help.
  • The dialog identifies the plugin only by a self-declared name that the caller can choose, and a decline isn't remembered.

The buzzodz-plugins cargo tests, the src-tauri origin and forwarding tests, and the touched vitest suites pass locally.

This needs a human maintainer's review.

request_origin(manager, &ASKING, id, revision, origin, |name| {
let (sender, receiver) = tokio::sync::oneshot::channel();
let message = format!(
"Let \u{201c}{name}\u{201d} connect to {shown}? The plugin can then make HTTPS \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 P2: The dialog is a real gate, but it is weaker as a trust signal than it looks. (1) id and revision are caller-supplied, like every other host command (HostCalls::consume binds them only to the call, not to a plugin). Plugin code shares the main web view, so plugin A can invoke('plugin_host_request_origin', {id: 'B', revision: <B's revision from the catalog>, origin}). The dialog then reads "Let B connect to evil", and on Allow the origin goes to B. A then reaches it through B's id, as it already can with B's manifest origins. It cannot forge consent, but it can borrow another plugin's name. (2) The only identity shown is the self-declared manifest name (<=80 bytes, only Cc control chars stripped). Any plugin can call itself "Buzz". Bidi format characters such as U+202E are not stripped either, so they can reorder the text around the origin. Show the plugin id plus publisher or source, and strip Cf characters. (3) A "Don't Allow" is not remembered, so a plugin can re-prompt in a loop and the dialog is parented to the window. Add a per-plugin cooldown or deny-until-restart after a decline. Not a blocker.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 @joahg Thanks. I'm keeping all three out of this PR. Each one is now under Known limitations in the description:

  1. Another plugin's id. Agreed. Every host command takes id and revision from its caller, so plugin A can raise the dialog under plugin B's name. On Allow, the origin is saved for B, and A can then reach it through B's id, as it already can with B's manifest origins. Binding host calls to the calling plugin would change every host command, not just this one.
  2. The name alone. The dialog uses the manifest name, as the access review and the agent enable dialog do. Showing the id and the source would fit all three. Bidi format characters such as U+202E are listed too.
  3. Asking again after Don't Allow. A decline isn't remembered, so a plugin can ask again. Only one dialog can be open at a time. A cooldown after a decline would be a reasonable follow-up.

}
/// A bare HTTPS origin: no credentials, path, query or default port, so it
/// equals what a request URL's origin serializes to.
fn valid_origin(origin: &str) -> Result<()> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 P2: Not fixed: valid_origin still accepts https://127.0.0.1, https://[::1], https://169.254.169.254, RFC1918 literals and localhost. The author kept them on purpose for self-hosted servers and lists it under Known limitations. The request path has no address filtering either (the only loopback/private checks are in public_image.rs). With the consent gate this is no longer a P1: the person sees the exact origin and the request has no cookies. It is still worth a stronger dialog warning, such as "this address is on your own machine or network", when the host is an IP literal, loopback, link-local or private, so a plugin cannot pass cloud-metadata or an internal admin port as an ordinary server.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 @joahg Agreed, a plainer warning for these hosts would help. I've kept it out of this PR. The dialog names the exact origin, and as you note, the request carries no cookies. Your suggestion is now under "Loopback and private hosts are allowed" in Known limitations: a note such as "This address is on your own computer or network" when the host is loopback, link-local, private or an IP literal.

@LordMelkor
LordMelkor requested a review from a team November 19, 2026 14:38
@LordMelkor

Copy link
Copy Markdown
Contributor Author

🤖 Closing this. The plugin it was first written for no longer needs it, and no plugin we maintain calls it. Thanks @joahg for the careful review. The branch stays, so anyone who needs runtime-approved origins, such as the self-hosted case raised above, can pick it up from here.

@LordMelkor LordMelkor closed this Nov 19, 2026
kazemek21 added a commit that referenced this pull request Nov 20, 2026
## TL;DR
The Update and reload button can lose its click when the candidate is
stale or an update check is already running. Carry that click through
fresh validation to an explicit update review, or plugin settings when
the candidate is no longer usable.

## What
- Use one pending action for the notice and Profile → Plugins. Disable
competing Update items while preserving Manage plugins.
- Show Preparing update… while a check or another review holds the
request. Later or Dismiss cancels it, including menu requests after
Later hid the notice.
- Keep the pending button keyboard-focusable and return menu reviews to
the surviving Profile button. Ignore late results after cancellation or
unmount.
- Preserve the review lease, freshness and access checks, explicit
confirmation, notification-body navigation, and signed-managed
automatic-update notices. The button never installs an update by itself.

## Testing
Added one browser journey and removed none. It exercises the real
Settings Check again action, a held in-flight check through the
native-IPC fixture, layered keyboard dismissal, one notice click, an
enabled explicit review, and no install before confirmation. Those
app/fixture boundaries supplement the colocated React cases; they do not
establish native Tauri behavior.

The complete affected file passed in Chromium and WebKit: `bin/pnpm
test:browser tests/browser/plugin-import.spec.mjs --project chromium
--project webkit --no-deps --workers=2` (68 cases). The captures below
show the notice, a narrow dark pending state with enlarged text, and the
wide light review. Human confirmation remains outstanding.

### Profile-menu regression scenario
Fixture-only setup: a synthetic Git-sourced Notes plugin has an
available update, and the fixture holds the update-review slot. Holding
and releasing that slot are fixture operations; the menu and notice
actions below use ordinary app controls.

1. Choose **Later**, then **Profile → Plugins → Update Notes** while the
slot is held. Keyboard access uses ArrowDown, ArrowRight, then Enter.
2. Expect **Preparing update…**. Reopen **Profile → Plugins**: competing
Update items are disabled; **Manage plugins** remains available.
3. Close the menus, choose **Later** or **Dismiss** on the notice, then
release the fixture hold. No review or installation follows.
4. Retry **Profile → Plugins → Update Notes**. Exactly one explicit
review opens; **Close** returns focus to Profile. Nothing installs
before confirmation.

This scenario does not record human or native verification. The
[repository readiness
checklist](https://github.com/block/buzz-app/blob/1dacf66356f9c4794bed5ec12a77b0f98efce135/AGENTS.md#before-opening-a-pr)
still applies.

### Synthetic interaction captures

![notification-before](https://d24qwcpro867f5.cloudfront.net/repos/block/buzz-app/prs/3555/notification-menu-005-before.png)

![notification-refresh](https://d24qwcpro867f5.cloudfront.net/repos/block/buzz-app/prs/3555/notification-menu-005-refresh.png)

![notification-review](https://d24qwcpro867f5.cloudfront.net/repos/block/buzz-app/prs/3555/notification-menu-005-review.png)

## Related work
- [#2963](#2963) adds runtime
plugin-origin permissions; its changes do not alter this update-notice
action.
- [#2762](#2762) adds shared
Markdown and panel workspaces; its changes do not alter this
update-notice action.
- [#2983](#2983) adds the
controlled document editor and browser coverage in the shared import
spec; this PR keeps the notification-action journey separate.
- [#2621](#2621) shares plugin
update discovery and results between notifications and Settings; this PR
leaves that shared reconciliation path untouched.

Generated with Codex (gpt-6.1-sol) on behalf of kylez.

---------

Signed-off-by: Kyle Zemek <kylez@squareup.com>
Co-authored-by: Codex (gpt-6.1-sol) <noreply@openai.com>
Co-authored-by: Antigravity (Gemini 4 Neon) <noreply@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants