Repository navigation
Fix #2084: no workspace SVG runs script in Tower's origin - #2086
Merged
Merged
Conversation
… loads The import map gave bare values (vendor/three.module.js). Browsers ignore an import map value that is not a URL, so 'three' never resolved and the 3D viewer loaded nothing since three.js was vendored. Each value now starts with ./
- workspaceFileHeaders (tower-utils): every route serving a workspace file with a type from its name sends nosniff and a sandboxing content policy: the file raw route, the annotate media routes and the Decisions image. - The annotation viewer and the Decisions view show an SVG from a data: URL, never an object URL of Tower's origin, which ran the SVG's scripts as Tower when opened as a page. The web host's full-size page takes a data: SVG; the VS Code webview's img-src admits data:. - The vendored 3MF loader types a texture's object URL PNG or JPEG, never the type the file claims.
…surface - Browser (playwright.decisions.config.ts, throwaway Tower and workspaces): the raw address opened by a keyed client, the annotation viewer, the Decisions tab (opened as a page, and full size) and the 3D viewer's 3MF textures: the SVG's script never runs in Tower's origin nor reads the key. - Routes: each route serving workspace bytes sends nosniff and the sandboxing policy for an .svg, .png, .pdf and .txt; a guard fails if a route names a type from a file's name outside workspaceFileHeaders. - The viewer's own loader (cut from open.html), the Decisions view and the web host's full-size page: an SVG is a data: URL, never an object URL.
… data: URL The viewer and the Decisions view compared the blob's type to image/svg+xml exactly, so a producer adding a charset would have put the SVG back on an object URL of Tower's origin. Both now compare the type's essence.
…y the header helper - The viewer and the Decisions view show an 'Image/SVG+XML; charset=utf-8' blob from a data: URL. - spec-761-api-state's tower-utils mock passes through workspaceFileHeaders, which tower-routes now imports. - The guard test says what it guards.
waleedkadous
added a commit
that referenced
this pull request
Dec 5, 2026
waleedkadous
added a commit
that referenced
this pull request
Dec 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #2084
Summary
A workspace SVG holding a
<script>could run it in Tower's origin, which reaches the whole API, every agent's terminal included. There were three ways to get there, not one:GET /api/file/<tab>/rawandGET /api/annotate/<tab>/api/image|video|model|pdfserved the SVG asimage/svg+xmlwith nonosniffand no content policy. Both routes are keyed, so this needs a client that presents the key, such as a reverse proxy that adds it.blob:URL it makes in Tower's origin. Response headers do not reach ablob:URL. The SVG's script ran there and read the key off Tower's landing page.blob:pattern in the web dashboard. The Decisions image route already sent the sandboxing headers; they did not help.A survey of every place the clients turn workspace bytes into a URL in Tower's origin found a fourth:
image/svg+xml.Reproduced in headless Chromium against a scratch Tower (never the live one), then shown closed: see Test Plan. Findings 2 and 3 are on the issue as a comment.
Root Cause
image/svg+xmldocument is scriptable. Nothing sandboxes ablob:URL: the policy that sandboxes the route's response does not travel with the bytes into the blob.Fix
workspaceFileHeaders(filePath, length)intower-utils.tsreturns the type from the file's name, its length,X-Content-Type-Options: nosniffandContent-Security-Policy: default-src 'none'; style-src 'unsafe-inline'; sandbox. All three routes use it for every type they serve (file raw, annotate media, Decisions image). A guard test fails if any source file names a type from a file's name outside it.templates/open.html) shows an SVG from adata:URL instead of an object URL. Every other type keeps its object URL.workspace-viewsDecisionsMarkdown, used by the web dashboard, the Tower page's Site view and the VS Code panel) does the same:data:SVG;img-srcgainsdata:, and nothing else in its policy changes.scripts/copy-three.mjs, so the change is a second rewrite there. That rewrite fails the build if the line is not found exactly once.vendor/three.module.js). Browsers ignore an import map value that is not a URL, sothreenever resolved, ever since three.js was vendored on 2026-08-12. The values now start with./. (Onmainthe 3MF texture path above was unreachable only because of this.)PDF: the sandboxing policy applies to PDF on the routes too, and nothing was relaxed for any type. The viewer loads a PDF as fetched bytes into an object URL, so the response's policy never reaches the embedded PDF viewer. The PDF still displays (screenshot below).
Every place workspace bytes become a URL
The places I looked, in the dashboard, the viewers, the web host and the VS Code webview:
GET /api/file/<tab>/rawworkspaceFileHeadersGET /api/annotate/<tab>/api/{image,video,model,pdf}workspaceFileHeadersGET /api/decisions/imageworkspaceFileHeadersloadMedia(open.html), SVGblob:→ nowdata:blob:getMimeTypeForFile), and a raster image type is rendered as an image; browsers sniff an image type only among image types, never to a scriptable oneblob:blob:(application/pdf)3MFLoader)blob:with the file's claimed typeblob:(text/javascript)DecisionsMarkdown), SVGblob:→ nowdata:blob:apps/webdecisionsHost.ts)blob:(text/html)<img>, itsaltandsrcset as attributes and escaped by the serializer. It holds no workspace bytes and no<script>. It now also accepts adata:SVGdecisions-host.ts) and full-size viewBlob→ the view's URL;<img>vscode-webview://), never Tower'sdata:there too;img-srcgainsdata:FileViewer.tsx)<iframe>of the annotation viewergetFileRawUrl(apps/webapi.ts)<iframe sandbox="allow-scripts" srcdoc>allow-same-origin)GET /file?path=and annotateGET /filetext/plain; charset=utf-8text/plainis sniffed only to text or binary, never to a scriptable typeuploadPasteImage)What "open full size" does for an SVG now
<img src="data:image/svg+xml;base64,…">and no script, and the host revokes it after 60 s, as before. The SVG renders as an image there, so its script cannot run.<img>of thedata:URL.Opening the image's own address:
data:URL as a top-level document:window.openof it opened nothing in the tests.data:SVG's script runs in an opaque (null) origin that cannot read Tower's responses. The tests assert exactly that: it ran innulland its read of the key was refused. It runs no script in Tower's origin; it does still run in its own.data:URL sizedata:URL is about 4/3 of the file (base64). MDN: Chromium and Firefox allow 512 MB, Safari 2048 MB. Firefox allowed 32 MB from version 97 to 135, and 512 MB since 136.MAX_DECISIONS_IMAGE_BYTES), about 13.4 MB as adata:URL, well inside every limit.Test Plan
npm run build)npm testinpackages/codev, the full suite, run once at a 1-minute load under 10; plus the targetedworkspace-views,apps/vscodeandapps/webfiles)Browser, committed (
src/agent-farm/__tests__/e2e/bugfix-2084-workspace-svg.test.ts). It runs throughplaywright.decisions.config.ts: a throwaway Tower on its own port and dirs, withmkdtempworkspaces. The nightly CI step is renamed "Run Decisions tab and workspace SVG tests". Each test shows an SVG whose script, if it runs, marks where it ran and whether it read the key, then opens it as a page:main's sources rebuilt, import-map fix kept)http://localhost:<port>, read the keynosniff+sandboxnull, key refused; PNG still an object URL<script>and shows the imageimage/svg+xmlimage/svg+xmlimage/png; the model loads (1 triangle)The existing Decisions suite passes too. Its one changed expectation: a workspace SVG is now a
data:URL.These browser tests run in the nightly
dashboard-e2e.ymlworkflow, not in PR CI. The 3D viewer's revival (the import-map fix) is covered only there and by the runs above.Unit:
tower-routes.test.ts: each route (raw, and annotateimage|video|model|pdf) serves.svg,.png,.pdfand.txtwithnosniff, the policy and the right type. 20 cases, all failing on the old routes with exactly those two headers missing.bugfix-2084-workspace-file-headers.test.ts: the helper, its policy, and the guard that no route names a type from a file's name outside it.decisions-routes.test.ts: the Decisions image's SVG carries the shared policy.bugfix-2084-viewer-svg.test.tsruns the viewer's ownloadMedia, cut fromopen.html, in jsdom:data:, other types keep object URLs;DecisionsView.images.test.tsx: an SVG becomes adata:URL and goes full size from there. A read failure shows the "Image not loaded" note.createDecisionsHost.test.ts: the full-size page for adata:SVG and for an object URL; nothing opens for any otherdata:URL.workspace-views-panel-template.test.ts:img-src blob: data: http: https:.The new unit and browser tests each failed with the fix removed, and pass with it.
Manual, headless Chromium against a scratch Tower:
Before the fix, an SVG opened by its raw address with the key ran its script in Tower's origin and read the key. After it, checked by a script against that scratch Tower (not committed):
nosniffand the policy for an SVG, a PNG, a WebM and a PDF.blob:(160×120), SVG fromdata:(320×160), WebM fromblob:(160×120), PDF fromblob:(shown in the browser's PDF viewer);data:URL;null, its read of the key refused.image/svg+xmlloads (1 triangle); its texture's object URL isimage/png.data:, PNG fromblob:;null, key refused;<script>, whose<img>shows thedata:SVG (120×80).Screenshots are element crops only, with no header, path or name:
Not checked:
Unrelated, environmental: 97
apps/webtests (terminal, toolbar, Site view) fail in this worktree because jsdom has nocanvas.getContext. They fail the same way withmain's versions of the twoapps/webfiles this PR touches.CMAP
codex APPROVE (HIGH), claude APPROVE (HIGH). Gemini is off in this project's consultation config.
Addressed from claude's comments:
=== 'image/svg+xml'would have put an SVG back on an object URL if a producer ever added a charset. The viewer and the Decisions view now compare the type's essence. Tested withImage/SVG+XML; charset=utf-8.spec-761-api-state.test.tsmockedtower-utilswithoutworkspaceFileHeaders, whichtower-routes.tsnow imports. It passes the real one through.Left as is:
allow-downloadson the raw route's sandbox. The route has no caller, and I have not verified how a sandboxed response behaves as a download, so a comment would be a guess.rewriteOnce's error names3MFLoader.js. Both rewrites are in that file, so the message is accurate.