Repository navigation
fix(core): save the site, not every URL, when always allowing a web fetch - #66000
Conversation
b0f19cc to
83af22e
Compare
There was a problem hiding this comment.
Looks right: Allow always on a web fetch now saves the URL's site instead of *, for webfetch, Code Mode fetch, and the image and video tools.
How I checked: I ran the updated tool-webfetch.test.ts against the base. It fails there with save: ["*"] and passes with this PR. A small script with Permission.site and Wildcard.match confirmed the saved patterns cover other pages on the same site and the bare origin, and not lookalike hosts or URLs that only mention the site in the query. The core tests nearest the change pass, and tsc is clean. I couldn't get the TUI prompt to appear with the simulated model, so there are no screenshots.
Public API: unchanged. Only the pattern proposed for webfetch saves changes, and existing saved rules keep working.
One gap worth closing: a * in the hostname (see inline).
| * as written, so the site is kept as written too, with and without a path. | ||
| */ | ||
| export function site(url: string) { | ||
| const origin = /^https?:\/\/[^/?#]+/i.exec(url)?.[0] |
There was a problem hiding this comment.
new URL("https://*/x") parses, and webfetch's assertHttpUrl accepts it, so site() returns https://* and https://*/*. Those match every https URL. Likewise https://*.com/x saves a pattern for all .com sites. A fetch target suggested by an injected prompt could still turn one click into an all-sites rule. The prompt does list the patterns, and it's no worse than today's *, but it undoes the narrowing. Could the host be rejected when the origin contains *, e.g. by returning [] so there's no Always option for that URL?
Fixes #64429 for the common case: choosing Allow always on a webfetch prompt saved
webfetch: * → allow, so one click allowed every URL on every site for the project. It now saves the URL's site.This applies everywhere a webfetch approval is saved: the webfetch tool, Code Mode
fetch, and the URLs the image and video tools download or hand to a provider. They all go through a newPermission.site(url).Why the site and not the path (what the issue asks for): other coding tools scope saved web approvals by domain, and a path rule for
/docs/permissionswould prompt again for/docs/agents, which defeats "always". Path- or host-wide choices in the prompt itself are [FEATURE] Let the user choose the saved approval scope in the "Always allow" prompt (e.g. parent directories for external_directory) #64430, which this doesn't touch.Two patterns, not one. Rules match the URL as written, and
https://opencode.ai/*doesn't match a barehttps://opencode.ai. Saving both avoids a second prompt for the same site, which is the trailing-slash question the issue raises.As written. The site is taken from the URL as the agent wrote it, not normalized, for the same reason:
https://OpenCode.ai/xsaveshttps://OpenCode.ai/*, which matches the next fetch written the same way.Redirects are unchanged: each hop is still only checked for deny rules, so a saved site doesn't widen what a redirect can reach.
Unusual URLs save only themselves. A URL with credentials in its site (
https://opencode.ai@evil.com/xgoes to evil.com) or that isn't http(s) saves just that exact URL, never*, so the saved rule can't name a misleading site. The site ends where URL parsers end it, including at\, sohttps://evil.com\@opencode.ai/saveshttps://evil.com/*. Rules treat*and?as wildcards, so a site containing one (https://*/xparses, and would otherwise save a pattern for every site) gets no pattern, and neither does an unusual URL containing one: those prompts offer no "Allow always". The regex is linear (no backtracking), and 200k characters take about 1 ms.Existing saved
webfetch: *rules are left alone.The permissions docs now mention that web fetches propose the URL's site.
No flag: this narrows what a click saves and changes no other behavior.
Checks
tool-webfetch.test.ts,tool-execute.test.ts,tool-image-generate.test.ts,tool-video-generate.test.ts,permission.test.ts,codemode.test.ts,generate.test.ts,session-generate.test.ts(the webfetch and Code Mode tests now expect the site patterns)bun run checkAdded by the opencode bot (AI-generated).
Related: #64430, #55232