Repository navigation
Conversation
…tach grant Attaching a desktop browser writes browser:* and skill:browser allows into the session's permissions. Session rules are evaluated after agent rules, so the grant overrode a browser deny from config, an agent definition (for example a "*" deny) or the session itself. Browser tools never called the permission check either, so tool.use policies did not apply. The plugin now records each agent's rules before it appends its own default deny. A browser call is refused when those rules, plus the session's rules without the grant, deny the browser, decided the way core's tool filter decides. The call then runs the permission check with the operation as its resource, so permission.evaluate hooks such as tool.use policies apply. Sessions without a deny behave as before: the grant allows the check, so nothing prompts. Refs #54044, #53294, #56869
…rent A child session copies its parent's permissions, so a subagent spawned from an attached session got the browser:* and skill:browser allows but no attachment. It listed the browser tools and the Browser skill, every call failed with [browser.disconnected], and the copied allow outlived the parent's attachment. The plugin now revokes the grant from a child session while the child's prompt is admitted (session prompt hook), before any step of the child can list the tools, so there is no race with its first step. It holds the attachment lock while it checks and writes, and skips a child that has an attachment of its own. A subagent whose agent denies the browser stays denied even when the desktop attaches to it, through the check from the previous commit. Refs #61238
…illed The attach grant is a stored session rule, but its revoke runs only from the plugin's finalizer. After SIGKILL, a crash or a stop timeout, the session kept browser:* and skill:browser allows with no attachment behind them, so the next server listed the browser tools and every call failed with [browser.disconnected]. Each grant is now recorded in plugin storage with the server process that wrote it (host and process ID) and its location, before the grant is written; a successful revoke removes the record. When the plugin starts for a location, and before it registers the browser RPC so no attach can race it, it revokes the grants recorded for that location by a process that no longer runs. Several server processes can share one database (a desktop's server and a manual `opencode serve` both use opencode.db), so a sweep of every session in the location could revoke another server's live grant. The sweep skips records of a running process and of another host, which cannot be checked. Grants written before this change have no record and are left alone; the next attach and detach of their session removes them. The startup sweep before RPC registration, its location scoping and ignoring per-session failures come from #61639. Fixes #61609 Co-authored-by: Chen Yufeiyang <[email protected]>
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
There was a problem hiding this comment.
Whole-browser denies, inherited subagent grants and stale grants after a kill are all handled. I checked with the new browser-permission tests: 6 of the 7 cases I could run on the base fail there (the eighth needs the new export), and all 8 pass with this PR. bun test in plugin-browser passes, and tsc --noEmit there is clean. The package's typecheck script fails here with Script not found "check", so I couldn't type-check core. I couldn't run an end-to-end repro: the serve + attach RPC script from #61609 got RPC is unavailable: experimental.browser on both checkouts, and the desktop app can't run here.
Public API: unchanged. Browser calls now go through permission.assert, so tool.use policies apply. There is a new [browser.denied] tool error and internal plugin storage keys (grant:<sessionID>).
One concern, inline: the pre-check only catches a deny on all of browser. A deny or ask on a single operation is still overridden by the attach grant.
Related: #55795
| ...(configured.get(tool.agent) ?? []), | ||
| ...(session.permissions ?? []).filter((rule) => !BrowserMachine.isGrant(rule)), | ||
| ] | ||
| if (BrowserMachine.deniesBrowser(rules)) |
There was a problem hiding this comment.
deniesBrowser only refuses when the last matching rule is a deny on browser with resource *. Two cases still go through the grant:
- A deny on one operation, e.g.
{ action: "browser", resource: "evaluate", effect: "deny" }, or onfiles.upload. Thepermission.assertbelow adds the session'sbrowser:* allowafter it, and that allow wins. I checked this with a throwaway test: abrowser:tabs.list denyinopencode.jsonstill letbrowser.tabs.listrun with a desktop attached. - A configured
browser: ask. The grant turns it into a silent allow.
These are probably the next denies users will write. Could this match configured plus the non-grant session rules against browser / operation, the same way assert does, and then refuse on deny or ask on ask, instead of only checking the * case?
|
Folded into #63002, which now carries these fixes (a configured deny or ask wins over the attach grant per operation, subagents do not inherit the grant, stale grants are swept at startup) with the rest of the browser work. Closing in its favour. |
A
browserdeny in config or an agent definition now holds when the desktop attaches a browser, subagents stop inheriting the attach grant, and a grant left by a killed server is removed at startup.Fixes #54044, #53294, #56869, #61238, #61609. Builds on #61639 (startup sweep, by @feiiiiii5).
One cause, three bugs
Attaching a browser writes
browser:* allowinto the session's stored permissions. Session rules are evaluated last, are copied to child sessions, and outlive the process; the attachment itself lives in memory under one session ID.browser, desktop attached[browser.denied]tool.usepolicy onbrowserpermission.assert) on every callHow
connection.tsauthorize): the plugin records each agent's own rules before it appends its default deny. Before a browser call it refuses if those rules, or the session's rules without the grant, denybrowser; then it asserts the permission so policies run.prompthook removes the inherited grant from a child that has no attachment of its own, under the attachment lock, before any step runs.Notes for review
plugin-browser. Subagent and stale-grant fixes become unnecessary there; the deny fix needsbrowserrules aliased to the newbrowser_*tool names.packages/core/test/browser-permission.test.tsdrives the real plugin, config files and permission service with a stand-in desktop.Visual
Added by the opencode bot (AI-generated).
Related: #55795