Repository navigation
Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
The fs.read endpoint serves repository (and other on-disk) content from the same origin as the HTTP API. A paired browser holds a SameSite=Lax session cookie, so a top-level navigation to /api/fs/read/page.html sends the cookie and a browser renders the response as an HTML document in the API origin. Any script in that file can then call the authenticated API, including credential.list, shell, and fs.write. Mark file responses as inert content: sandbox gives the document an opaque origin and blocks scripts, and nosniff prevents MIME reinterpretation. The bytes and content type are unchanged, so image and media loading keeps working. Test: assert both headers on a real .html response; the test fails on the previous handler.
5d7d692 to
8b57360
Compare
There was a problem hiding this comment.
Looks correct. I ran opencode serve from source on the base and on this branch and requested an .html file through /api/fs/read/*. The base returns it as text/html with no CSP or nosniff. With this change it also sends Content-Security-Policy: sandbox and X-Content-Type-Options: nosniff, and body, validators and range handling are unchanged. A 304 still sends only the validators; that's fine because browsers keep the stored 200's headers. test/fs.test.ts passes, the new assertion fails on the base, and tsc -b is clean. I couldn't run a browser here, so the script blocking itself wasn't observed.
The web app only loads fs.read files as images and markdown <img> tags, or through fetch. I found no iframe, embed or object use, so sandbox and nosniff shouldn't break anything there.
Public API: two response headers are added on GET /api/fs/read/*. Status codes, body and schema are unchanged, so it's backwards compatible.
No blocking concerns.
There was a problem hiding this comment.
The new commit is fine. The 304 revalidation response now carries Content-Security-Policy: sandbox and X-Content-Type-Options: nosniff, the same as the 200/206 responses. I checked with curl against opencode serve run from source. test/fs.test.ts passes and tsc -b is clean.
Public API: the 304 response for GET /api/fs/read/* now also has the two headers. This is backwards compatible.
No new concerns.
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Issue for this PR
Closes #58914
Type of change
What does this PR do?
GET /api/fs/read/*served files with their inferred MIME type and no hardening headers. Because the app and API share an origin and the session cookie isSameSite=Lax, navigating to an.htmlor script-bearing.svgfile in a workspace ran its script in the app's origin, where it could call the authenticated API.This adds two headers to every response from that endpoint, including 304 revalidations:
Content-Security-Policy: sandboxandX-Content-Type-Options: nosniff. The body, content type, range handling and cache validators are unchanged, so image and media loading through the same endpoint is unaffected.How did you verify your code works?
Added a test in
packages/server/test/fs.test.tsthat writes a realpage.html, requests it through the endpoint, and assertstext/htmlplus both headers. It fails on the unpatched handler and passes with this change.cd packages/server && bun test— 98 pass, 1 skip, 0 fail.cd packages/server && bun run typecheck— clean.Screenshots / recordings
Not a UI change.
Checklist