Repository navigation
fix(core): apply webfetch rules to Code Mode fetch - #59753
rekram1-node wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Looks correct. I ran the PR's updated before-hook test on the base and it fails there (the host function runs before a refusing extension.before hook). With this change it passes, along with the codemode suite (1461 pass) and the core tool tests, including the new registry test (52 pass). The Code Mode fetch check sends the same resource (request.url) under the same webfetch action as the webfetch tool, and adding Permission.node to Tool.node's dependencies creates no cycle. I could not drive this end to end in the TUI with the simulated model, so the end-to-end evidence is the registry test.
Public API is unchanged. CodeModeTool.create gains a required checkFetch argument, but it is internal to packages/core. The ordering change for extension.before is internal to packages/codemode.
No blocking concerns.
Fixes #54595
Problem
fetchinside Code Mode scripts didn't go through thewebfetchrules, so awebfetchdeny rule or a Console policy that blocks web access didn't apply to it. Separately, the Code Mode interpreter called extension functions before theirextension.beforehook ran, so a hook could only hide the result of a call, not stop it.Change
packages/codemode: the before hook now runs before the host function is called. A refused async function rejects its promise, a refused sync function throws.packages/core: Code Mode'sfetchhook checks each URL withPermission.assertNotDeniedunder thewebfetchaction. It never prompts, so default setups see no change. A refused fetch shows as an error row in the TUI.Tool.nodenow depends onPermission.node.Out of scope
Redirects inside Code Mode
fetchare still followed by fetch itself.Verification
bun testinpackages/codemode: 1461 pass. The updated before-hook test fails without the interpreter change.packages/core/test/tool-execute.test.ts: through the real tool registry, an allowed fetch reaches the server and a denied one throws and never reaches it.bun testinpackages/core: everything passes except 8 shell and test-environment tests that fail the same way ondevlocally.bun run checkfrom the repo root: passes.Added by the opencode bot (AI-generated).
Fixes #54595