GeezerVison is showing github.com — fix(core): check each Code Mode fetch redirect against webfetch rules by rekram1-node · Pull Request #60502 · anomalyco/opencode
Conversation
Problem
Code Mode fetch checked only the first URL against the webfetch rules, then let the runtime follow redirects on its own. Any allowed URL that redirects could reach a denied one:
deny rule: https://evil.com/*
webfetch: safe.com/r → 302 → evil.com → checked, blocked
fetch: safe.com/r → 302 → evil.com → not checked, fetched
Change
fetch now follows redirects itself (redirect: "manual") and checks each new URL with permission.assertNotDenied, the same hop check the webfetch tool uses. A denied hop is never requested, and the promise rejects.
fetch(url)
assert webfetch(url) (unchanged: may ask)
loop: request → 3xx + location?
check deny rules for next URL ← NEW (never asks)
follow, like a browser would
Following by hand keeps the standard fetch behavior programs expect:
- 303, and 301/302 after a POST, become a GET without a body.
authorization, cookie and proxy-authorization are dropped when the redirect changes origin.
- Up to 20 redirects, same as
fetch. Only http(s) targets.
response.url is the final URL and response.redirected is set.
- One 30s timeout covers the whole chain.
Visual
<svg xmlns="http://www.w3.org/2000/svg" width="240" height="72" viewBox="0 0 240 72" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<style>
.dot { animation: hop 3s ease-in-out infinite; }
.x { opacity: .25; animation: deny 3s ease-in-out infinite; }
@keyframes hop { 0% { transform: translate(0,0); opacity: 1 } 35% { transform: translate(70px,0) } 55% { transform: translate(70px,0) } 75% { transform: translate(118px,0); opacity: 1 } 85%, 100% { transform: translate(118px,0); opacity: 0 } }
@keyframes deny { 0%, 70% { opacity: .25 } 78%, 95% { opacity: 1 } 100% { opacity: .25 } }
@media (prefers-reduced-motion: reduce) { .dot, .x { animation: none } .x { opacity: 1 } }
</style>
<rect x="8" y="24" width="52" height="24" rx="6" opacity=".6"/>
<text x="34" y="40" font-family="ui-monospace, monospace" font-size="10" text-anchor="middle" fill="currentColor" stroke="none">fetch</text>
<path d="M62 36 H96" opacity=".35" stroke-dasharray="3 4"/>
<rect x="98" y="24" width="40" height="24" rx="6" opacity=".4"/>
<text x="118" y="40" font-family="ui-monospace, monospace" font-size="10" text-anchor="middle" fill="currentColor" stroke="none">302</text>
<path d="M140 36 H168" opacity=".35" stroke-dasharray="3 4"/>
<circle class="dot" cx="64" cy="36" r="4" fill="currentColor" stroke="none"/>
<path d="M186 18 L202 24 V36 C202 46 194 52 186 55 C178 52 170 46 170 36 V24 Z" opacity=".8"/>
<path class="x" d="M180 31 L192 43 M192 31 L180 43"/>
<circle cx="224" cy="36" r="9" opacity=".25"/>
</svg>
Out of scope
- The check and the request can still disagree on the URL's spelling (case, default port). That's a separate small PR covering both
fetch and webfetch.
Verification
- New test in
packages/core/test/tool-execute.test.ts: a redirect to a URL denied for webfetch is never requested. It fails on dev.
bun test ./test/tool-execute.test.ts in packages/core: 13 pass. bun typecheck is clean.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change looks sound. On the base, the PR's new deny-on-redirect test fails (the redirect to the denied URL is followed unchecked). With the PR it passes, along with the tool-execute, codemode and tool-webfetch tests (127 pass), and typecheck:tsc is clean. I also checked that a redirect with an invalid Location and a redirect loop reject in a way the program can catch.
Public API is unchanged.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new commit only simplifies the tests, and the single redirect test is small and clear. It fails on the base (the redirect to the denied URL is followed) and passes with the PR, along with the rest of tool-execute.test.ts (13 pass). typecheck:tsc is clean. The fetch.ts fix is unchanged since my last review.
Public API is unchanged.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Nov 7, 2026
This was referenced Nov 9, 2026
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|