Skip to content

fix(core): apply webfetch rules to Code Mode fetch - #59753

Open
rekram1-node wants to merge 1 commit into
devfrom
codemode-fetch-rules
Open

rekram1-node wants to merge 1 commit into
devfrom
codemode-fetch-rules

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Problem

fetch inside Code Mode scripts didn't go through the webfetch rules, so a webfetch deny rule or a Console policy that blocks web access didn't apply to it. Separately, the Code Mode interpreter called extension functions before their extension.before hook ran, so a hook could only hide the result of a call, not stop it.

Change

script calls fetch(url)
  extension.before hook          ← now runs first
    rules deny url?  → throws "Permission denied: webfetch" in the script
    otherwise        → fetch runs
  • 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's fetch hook checks each URL with Permission.assertNotDenied under the webfetch action. It never prompts, so default setups see no change. A refused fetch shows as an error row in the TUI.
  • Tool.node now depends on Permission.node.

Out of scope

Redirects inside Code Mode fetch are still followed by fetch itself.

Verification

  • bun test in packages/codemode: 1461 pass. The updated before-hook test fails without the interpreter change.
  • New test in 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 test in packages/core: everything passes except 8 shell and test-environment tests that fail the same way on dev locally.
  • bun run check from the repo root: passes.

Added by the opencode bot (AI-generated).

Fixes #54595

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

the execute tool should inherit webfetch permissions

1 participant