Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix(outputs): sandbox every inline artifact download, not just HTML and SVG (#812)
Ruben Lütke3ff3fb101a67
diff --git a/dodaios/ui/web/outputs_routes.py b/dodaios/ui/web/outputs_routes.pyindex ca3069c36c..e0e604a316 100644--- a/dodaios/ui/web/outputs_routes.py+++ b/dodaios/ui/web/outputs_routes.py@@ -844,6 +844,11 @@ _HTML_TITLE_MAX_CHARS: int = 200# synchronous read or spike memory while rendering. Larger files use /download._VIEW_MAX_BYTES: int = 2 * 1_048_576+# Inline downloads that skip the sandboxing CSP: formats the browser renders+# with a plugin viewer, which a sandboxed document refuses to load. Nothing+# else belongs here (see download_output_artifact).+_INLINE_PLUGIN_TYPES: Final = frozenset({"application/pdf"})+def _is_deliverable_relpath(rel_parts: tuple[str, ...]) -> bool:"""True iff a mission-relative path is a genuine worker deliverable.@@ -1112,11 +1117,13 @@ async def download_output_artifact(target = _resolve_artifact_target(request, slug, path)media_type, _ = mimetypes.guess_type(target.name)headers = {"X-Content-Type-Options": "nosniff"}- # HTML and SVG are active document formats when rendered inline in the app- # origin. Apply the same no-script CSP used by the /view route so a- # worker-authored artifact cannot execute code against the app.- active_document_types = {"text/html", "image/svg+xml"}- if disposition == "inline" and media_type in active_document_types:+ # A worker-written file rendered inline lives in the app origin, so every+ # inline response gets the sandboxing no-script CSP the /view route uses.+ # A list of "active" types is a trap: XHTML, XML with an XHTML namespace+ # and future formats all run script too. The one exception is PDF: the+ # browser's PDF viewer is a plugin, plugins never load in a sandboxed+ # document, and the viewer renders out of the app origin anyway.+ if disposition == "inline" and media_type not in _INLINE_PLUGIN_TYPES:headers["Content-Security-Policy"] = VIEW_HEADER_CSPreturn FileResponse(target,diff --git a/tests/unit/ui/web/test_outputs_routes.py b/tests/unit/ui/web/test_outputs_routes.pyindex 89a43814bc..0ed862f22e 100644--- a/tests/unit/ui/web/test_outputs_routes.py+++ b/tests/unit/ui/web/test_outputs_routes.py@@ -1222,6 +1222,11 @@ async def test_raw_404s_for_scaffolding(app: FastAPI, tmp_path: Path) -> None:# --- /download route (Task 3) -------------------------------------------------+_XHTML_WITH_SCRIPT = (+ '<html xmlns="http://www.w3.org/1999/xhtml"><body><script>bad()</script></body></html>'+)++def _make_deliverable(root: Path, mission_id: str, name: str, content: str) -> str:"""Create tasks/<tid>/artifacts/files/<name> under mission_<id>; return rel path."""files_dir = (@@ -1250,10 +1255,17 @@ def test_download_sets_attachment_disposition(app):("filename", "content"),[("page.html", "<p>x</p>"),+ ("page.htm", "<p>x</p>"),("image.svg", "<svg><script>bad()</script></svg>"),+ ("page.xhtml", _XHTML_WITH_SCRIPT),+ ("page.xht", _XHTML_WITH_SCRIPT),+ ("page.xml", _XHTML_WITH_SCRIPT),+ ("notes.txt", "<script>bad()</script>"),+ ("blob.unknownext", "<script>bad()</script>"),],)def test_download_inline_active_document_has_csp(app, filename, content):+ """Every inline rendering gets the sandboxing CSP, whatever its type."""root = Path(app.state.outputs_root)slug = "mission_019ed2dfd0fab"rel = _make_deliverable(root, "019ed2dfd0fab1234", filename, content)@@ -1261,7 +1273,39 @@ def test_download_inline_active_document_has_csp(app, filename, content):r = client.get(f"/api/outputs/{slug}/files/{rel}/download?disposition=inline")assert r.status_code == 200assert r.headers["content-disposition"].startswith("inline")- assert "default-src 'none'" in r.headers["content-security-policy"]+ assert r.headers["x-content-type-options"] == "nosniff"+ csp = r.headers["content-security-policy"]+ assert "default-src 'none'" in csp+ assert "sandbox" in csp+ assert "script-src" not in csp+++def test_download_inline_pdf_skips_the_sandbox_its_viewer_cannot_load_in(app):+ """The PDF viewer is a plugin and never loads in a sandboxed document."""+ root = Path(app.state.outputs_root)+ slug = "mission_019ed2dfd0fab"+ rel = _make_deliverable(root, "019ed2dfd0fab1234", "report.pdf", "%PDF-1.4")+ client = TestClient(app)+ r = client.get(f"/api/outputs/{slug}/files/{rel}/download?disposition=inline")+ assert r.status_code == 200+ assert r.headers["content-type"] == "application/pdf"+ assert r.headers["x-content-type-options"] == "nosniff"+ assert "content-security-policy" not in r.headers++[email protected]("filename", ["page.html", "page.xhtml", "page.xml", "image.svg"])+def test_download_attachment_keeps_its_headers(app, filename):+ """A saved file never renders, so the attachment path stays as it was."""+ root = Path(app.state.outputs_root)+ slug = "mission_019ed2dfd0fab"+ rel = _make_deliverable(root, "019ed2dfd0fab1234", filename, _XHTML_WITH_SCRIPT)+ client = TestClient(app)+ r = client.get(f"/api/outputs/{slug}/files/{rel}/download")+ assert r.status_code == 200+ assert r.headers["content-disposition"].startswith("attachment")+ assert r.headers["x-content-type-options"] == "nosniff"+ assert "content-security-policy" not in r.headers+ assert r.text == _XHTML_WITH_SCRIPTdef test_download_blocks_non_deliverable(app):