Skip to content

Serve the file builtin:code opens as text on its raw route, not as HTML or SVG - #1609

Open
dormouse-bot wants to merge 1 commit into
mainfrom
nightly/code-editor-raw-grant-inert
Open

dormouse-bot wants to merge 1 commit into
mainfrom
nightly/code-editor-raw-grant-inert

Conversation

@dormouse-bot

Copy link
Copy Markdown
Collaborator

When builtin:code opens an HTML or SVG file, the viewer serves its source on the editor page's JSON source route. It also keeps a raw grant on the file at file/<name>. That raw route took its MIME type from fileViewerFormat rather than from the handler, so the raw grant sent the file as text/html or image/svg+xml under EDITOR_CSP, which allows inline scripts and same-origin connect-src. This PR makes the opened file take the handler's format (text/plain for builtin:code). The raw grant stays, but it can no longer serve markup that runs. This brings the code in line with S151, which says "source text is JSON data, never executable markup".

Trigger. The editor page never loads file/<name>: Monaco reads source. So reaching the bad response takes a navigation to that URL inside the Tool's frame. A user editing the URL would do it; nothing in the shipped UI does. If that file's script ran, it would share the editor's origin, so its save POSTs would pass the Origin check. builtin:file is unchanged, because its handler format is fileViewerFormat itself.

Fix. register uses the handler's format for the opened file. Referenced assets still use fileViewerFormat.

Verification. The builtin:code opens Markdown, HTML, and SVG as source test now asserts that the raw route answers text/plain. It fails on main and passes with the fix. pnpm test in dor-tools-builtin and lib/src/host/file-viewer-proxy.test.ts pass.

…ML or SVG

Under builtin:code the opened file's retained raw grant (file/<name>) took
fileViewerFormat's MIME, so an HTML or SVG source streamed as text/html or
image/svg+xml under EDITOR_CSP, which allows inline scripts and same-origin
requests. It now takes the handler's format (text/plain), matching
security-local.md S151: source text is never executable markup.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying mouseterm with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6fe1d10
Status: ✅  Deploy successful!
Preview URL: https://ee556f3e.mouseterm.pages.dev
Branch Preview URL: https://nightly-code-editor-raw-gran.mouseterm.pages.dev

View logs

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant