GeezerVison is showing github.com — fix(server): serve file reads as downloads with explicit content headers by thdxr · Pull Request #62422 · anomalyco/opencode
Conversation
thdxr
commented
Nov 6, 2026
•
edited by opencodejr
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
file reads now always come back as downloads with consistent headers, and API urls only answer navigations from the same origin.
GET/HEAD /api/fs/read/* (200, 206 and 304) send content-disposition: attachment with the filename, x-content-type-options: nosniff and a sandboxed content-security-policy. html, js and xml types (svg included) are sent as text/plain, since every client reads those as bytes and picks the type from the path. images, audio and video keep their type, so <img>/<video>/<audio> and range seeking work the same as before.
/api/experimental/media/:hash sends content-disposition: attachment for inline image types too, and uses the same policy.
- requests to
/api/* with Sec-Fetch-Site: cross-site or same-site get a 403 if they are navigations, or if they carry an Origin that is not an allowed CORS origin. clients without Sec-Fetch-* headers (cli, tui, sdk), same-origin pages, typed urls, app.opencode.ai, the desktop renderer, --cors origins and media elements (which send no origin) all pass. /auth/connect/* and artifact views are not affected.
no flag: this is a fix.
Added by the opencode bot (AI-generated).
Fixes #58914
Public API: fs.read and media responses are now sandboxed attachments (html/js/xml served as text/plain); cross-site browser navigations or disallowed origins to /api/* get 403 (backwards compatible for CLI, TUI, SDK and the app)
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 fix works as described. I checked it against opencode serve from source on the base and on this PR:
- Base: an
.html file came back from /api/fs/read/* inline as text/html, and cross-site navigations or calls from any origin got 200.
- This PR: the same file comes back as a
text/plain attachment with the sandboxed CSP and nosniff. Cross-site navigations and calls from origins that aren't allowed get 403. Requests from app.opencode.ai and no-cors range requests (how <video>/<audio> load) still succeed.
- Tests and types: the server tests pass, and
tsc -b in packages/server is clean.
Public API impact, limited to the server's HTTP behaviour (no SDK, OpenAPI, config or CLI changes):
GET/HEAD /api/fs/read/*: responses now include content-disposition: attachment with the filename, a sandboxed content-security-policy and x-content-type-options: nosniff. The content-type changes from html/js/xml types (including svg) to text/plain; charset=utf-8.
GET /api/experimental/media/:hash: PNG, JPEG, GIF and WebP images now also get content-disposition: attachment, and the CSP allows img-src/media-src 'self'.
/api/* (new): returns 403 ForbiddenError for browser requests marked Sec-Fetch-Site: cross-site/same-site that are navigations, or that carry an Origin outside the allowed CORS list.
This is backwards compatible for the CLI, TUI, SDK and the app, which send no Sec-Fetch-* headers or use allowed origins. Pages on other origins that aren't passed with --cors can no longer call the API, and opening an API URL from another site now gives 403. That is the intent of the change.
No blocking concerns.
Fixes #58914
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 changes a test: it switches to a filename that Windows accepts. The test still checks both the escaped filename= fallback and the percent-encoded filename*= value, and test/fs.test.ts passes. Server behaviour and the public API impact are the same as in my previous review. No new concerns.
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.
autonull
pushed a commit
to autonull/opencode_spacegraph
that referenced
this pull request
Nov 7, 2026
Reviewers
Hona
Awaiting requested review from Hona
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
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.
|