GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — fix(core): match webfetch rules against the URL as written by rekram1-node · Pull Request #62373 · anomalyco/opencode Conversation
|
| Rule | Request | v2.2.5 | Before this PR |
|---|---|---|---|
*: allow, deny https://example.com |
https://example.com |
deny | allow |
*: ask, allow https://Example.org/* |
https://Example.org/x |
allow | ask |
*: ask, allow https://example.net:443/* |
https://example.net:443/x |
allow | ask |
This matches webfetch and Code Mode fetch rules against the URL as written again. It keeps rejecting URLs with credentials, drops the fragment from the URL as written before matching, and keeps the per-redirect checks from #60502. None of those change how an existing rule matches. Rule normalization (#62260) is no longer needed.
bun test test/tool-webfetch.test.ts test/tool-execute.test.ts test/permission.test.ts test/codemode test/tool-image-generate.test.ts test/config/agent.test.ts (packages/core): 302 passbun typecheck (packages/core): cleandev.<svg xmlns="http://www.w3.org/2000/svg" width="240" height="72" viewBox="0 0 240 72" fill="none" stroke="currentColor" font-family="ui-monospace,monospace" font-size="9"> <style> .u{animation:u 3s ease-in-out infinite} .c{animation:c 3s ease-in-out infinite} @keyframes u{0%,20%{transform:translateY(0)}50%,100%{transform:translateY(-20px)}} @keyframes c{0%,45%{opacity:.15}60%,100%{opacity:1}} @media (prefers-reduced-motion:reduce){.u,.c{animation:none}.u{transform:translateY(-20px)}} </style> <rect x="8" y="8" width="150" height="20" rx="4" opacity=".4"/> <text x="16" y="21" fill="currentColor" stroke="none" opacity=".8">rule https://example.com</text> <g class="u"> <rect x="8" y="42" width="150" height="20" rx="4"/> <text x="16" y="55" fill="currentColor" stroke="none">url https://example.com</text> </g> <path class="c" d="M190 40l8 8 16-18" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/> </svg>
Added by the opencode bot (AI-generated).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Existing rules such as https://example.com, uppercase hosts and explicit ports are compared to the URL the model requested again, as in v2.2.5. Undoes the URL parsing from #60505 and #61701; keeps the Code Mode redirect checks from #60502.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This fixes the rule-compatibility regression, but by reopening the deny-rule bypasses that #60505 and #61701 closed. I'd rather not trade one for the other.
I ran the permission matcher (Permission.evaluate) on the URL as written and on the parsed URL. Every row of your table now matches as in v2.2.5. But with *: allow and a deny rule for https://evil.com/*, these are allowed again and the request goes to evil.com:
HTTPS://EVIL.COM/xhttps://evil.com:443/xhttps://[email protected]/xThe same goes for https://evil.com/x#a against a deny rule for exactly https://evil.com/x. Normalizing the rules as well (the open #62260) fixes the same table and keeps these protections. Could you say why that approach is no longer wanted? The description just calls it unneeded.
Also, rejecting credentials and dropping the fragment don't cause the regression, so they can stay whichever way the URL question goes (inline comments).
The tests you listed pass (300), and typecheck:tsc is clean in packages/core.
Public API is unchanged: same config keys, only how webfetch rules match changes.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| yield* permission.assert({ | ||
| action: name, | ||
| resources: [url], | ||
| resources: [input.url], |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Checking input.url as written lets a different spelling of a denied URL through. With deny https://evil.com/*, HTTPS://EVIL.COM/x and https://evil.com:443/x no longer match but are still fetched from evil.com; this is what #60505 fixed. Normalizing the scheme and host of the rules when they are loaded (#62260) fixes the rules in your table without reopening this.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| const request = (url: string, format: Format, userAgent = openCodeUserAgent) => | ||
| HttpClientRequest.get(url).pipe(HttpClientRequest.setHeaders(headers(format, userAgent))) | ||
|
|
||
| const assertHttpUrl = (url: URL) => { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Dropping the credentials check isn't needed for compatibility: no existing rule matches a URL with credentials in it differently because of this check. Without it, https://[email protected]/x gets past a deny rule for https://evil.com/* again. The same goes for removing hash = "" (it only matters for rules that contain #). Could both stay?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| // The fragment is never sent, and would keep a rule for the exact URL from matching. | ||
| parsed.hash = "" | ||
| const url = parsed.href | ||
| const url = String(input) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Same problem in Code Mode fetch: the program can now write HTTPS://EVIL.COM/, https://evil.com:443/ or https://[email protected]/ to get past a deny rule for https://evil.com/*. Rejecting credentials and dropping the fragment can stay here as well, since they don't cause the regression.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Kept the credential rejection and the fragment handling (applied to the URL as written) in both webfetch and Code Mode On matching the URL as written: this is deliberate for now.
The proper fix is rules that match the parsed host, plus "always allow" saving the domain. I'll do that separately under #55232. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Rejecting credentials and dropping the fragment are back in both tools, thanks. The case and default-port bypass (HTTPS://EVIL.COM/x, https://evil.com:443/x against deny https://evil.com/*) is still open in both webfetch and Code Mode fetch.
One new gap: the credential check misses an empty userinfo. https://@evil.com/x and https://:@evil.com/x parse with an empty username and password, so the check passes them, and as written they don't match a deny rule for https://evil.com/* (inline).
The suggested tests pass (302) and typecheck:tsc is clean in packages/core. Public API is unchanged.
packages/core/src/tool/plugin/webfetch.ts:74: An empty userinfo gets past this check. new URL("https://@evil.com/x") (or https://:@evil.com/x) has username === "" and password === "", so it isn't rejected. The rule is then matched against the string as written, so a deny rule for https://evil.com/* doesn't match, and the request goes to evil.com. Since rules now match the written URL, rejecting any @ in the written URL's authority would close this. The same applies to Code Mode fetch (codemode/fetch.ts line 25).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
…#62373) Co-authored-by: exe.dev user <[email protected]>
…#62373) Co-authored-by: exe.dev user <[email protected]>
Adapt anomalyco/opencode 17837a2 (anomalyco#59748), 125655e (anomalyco#61701), and e803323 (anomalyco#62373). Use this fork's existing permission assertions per redirect; reject URL credentials, ignore fragments, and bound redirects. Prove denied destinations receive no HTTP request.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.