feat(opencode): allow vscode-webview:// origins in cors allowlist#28806
feat(opencode): allow vscode-webview:// origins in cors allowlist#28806weicheng59 wants to merge 3 commits into
Conversation
VS Code assigns each WebviewPanel a fresh `vscode-webview://<random>` origin. Extensions embedding opencode that pass these origins via `--cors` would otherwise need to restart the opencode process every time the user opens a new panel (since the allowlist is exact-match and the random suffix means no panel-to-panel reuse). Restarting kills any in-flight turn, which is a poor UX. This mirrors the existing tauri allowance — both are local IDE host schemes wrapping the same loopback API, with no real cross-origin security boundary. Adds a regression test alongside the existing tauri/custom-cors coverage.
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: I found a potentially related PR: PR #28743: feat(server): add wildcard CORS origin support This PR appears to be related as it also addresses CORS origin handling in the server. It may be exploring a broader wildcard approach to CORS origins, which could overlap with or complement the vscode-webview specific allowance in PR #28806. You may want to check if #28743 already handles the vscode-webview case or if there's overlap in approach. |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Issue for this PR
None — improves out-of-the-box behavior for VS Code webview integrations.
Type of change
What does this PR do?
Adds
vscode-webview://*toisAllowedCorsOrigin's built-in allowlist inpackages/opencode/src/server/cors.ts, mirroring the existingtauri://localhostallowance.Why this matters in practice. VS Code assigns every
WebviewPanela freshvscode-webview://<random-guid>origin — the suffix is unguessable per-panel by design. An extension that embeds opencode and hosts UI in a webview has to:--corsflags at spawn time, andopts?.cors?.includes(input), no wildcards), and there's no way to extend it without a respawn.That restart kills any in-flight turn. Opening a new editor tab interrupts generation in the existing tab. We're shipping a VS Code extension that wraps opencode and hit this every time. With this patch, our extension stops needing
--corsplumbing at all for the webview case.vscode-webview://is the same shape as the already-allowedtauri://localhost:Relation to #28743. That PR adds explicit
cors: ["*"]wildcard support — opt-in for users who want everything allowed. This PR is complementary: a hardcoded allowance for a specific safe scheme, so the common case of "wrap opencode in a VS Code webview" works without any--corsconfiguration. Both can land independently.How did you verify your code works?
Added a regression test in
packages/opencode/test/server/httpapi-cors.test.tsalongside the existing tauri / custom-cors cases, asserting avscode-webview://<guid>preflight passes without any--corsargument.Built
v1.15.7 + this patchfrom source and verified end-to-end in our VS Code extension: opening multiple webview panels no longer requires restarting opencode, and no longer interrupts in-flight turns in sibling panels.Screenshots / recordings
Not a UI change.
Checklist