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(appshot): keep dragged appshots in a folder only this user can read
rubenluetke10-beep9cbbcb8b1360
diff --git a/jarvis/appshot/dragfile.py b/jarvis/appshot/dragfile.pyindex 69c6748d6f..c4b91d423d 100644--- a/jarvis/appshot/dragfile.py+++ b/jarvis/appshot/dragfile.py@@ -6,11 +6,19 @@ picture here when it is dragged, and the editor's "Drag me" handle writes theedited picture here the moment the user presses it. Nothing is writtenotherwise; files older than an hour are removed on the next write, so thefolder never grows (see ``docs/appshots.md``).++The folder is private to the user. A shared ``/tmp`` on Linux is readable by+every account on the machine, so on POSIX the folder carries the user id, is+created ``0700`` and is used only when this user owns it and nobody else can+read it — a folder someone else created first is refused, never written into.+Windows' temp folder is already per user."""from __future__ import annotationsimport logging+import os+import statimport tempfileimport timefrom contextlib import suppress@@ -23,15 +31,36 @@ MAX_AGE_S = 3600.0def drag_folder() -> Path:- return Path(tempfile.gettempdir()) / "jarvis-appshots"+ """Where drag files go (not created here): per user on every OS."""+ base = Path(tempfile.gettempdir())+ if os.name == "nt":+ return base / "jarvis-appshots"+ return base / f"jarvis-appshots-{os.getuid()}"+++def prepare_drag_folder() -> Path:+ """:func:`drag_folder`, created and private; ``OSError`` when it cannot be."""+ folder = drag_folder()+ if os.name == "nt":+ folder.mkdir(parents=True, exist_ok=True)+ return folder+ try:+ folder.mkdir(mode=0o700, parents=True)+ except FileExistsError:+ pass+ info = os.lstat(folder)+ if not stat.S_ISDIR(info.st_mode) or info.st_uid != os.getuid():+ raise OSError(f"{folder} belongs to someone else; no drag file is written there")+ if info.st_mode & 0o077:+ os.chmod(folder, 0o700)+ return folderdef write_drag_file(png: bytes, *, now: float | None = None) -> Path | None:"""Write ``png`` for one drag and return its path, or None on failure."""- folder = drag_folder()moment = time.time() if now is None else nowtry:- folder.mkdir(parents=True, exist_ok=True)+ folder = prepare_drag_folder()for old in folder.glob("appshot-*.png"):with suppress(OSError): # a file still open elsewhere staysif old.stat().st_mtime < moment - MAX_AGE_S:@@ -49,4 +78,4 @@ def write_drag_file(png: bytes, *, now: float | None = None) -> Path | None:return None-__all__ = ["MAX_AGE_S", "drag_folder", "write_drag_file"]+__all__ = ["MAX_AGE_S", "drag_folder", "prepare_drag_folder", "write_drag_file"]diff --git a/tests/unit/appshot/test_dragfile_private.py b/tests/unit/appshot/test_dragfile_private.pynew file mode 100644index 0000000000..88c4923dd1--- /dev/null+++ b/tests/unit/appshot/test_dragfile_private.py@@ -0,0 +1,47 @@+"""Dragged appshots land in a folder only this user can read (shared /tmp on Linux)."""++from __future__ import annotations++import os+import stat+import sys+from pathlib import Path++import pytest++from jarvis.appshot import dragfile++pytestmark = pytest.mark.skipif(os.name == "nt", reason="Windows %TEMP% is per user already")+++def temp(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:+ monkeypatch.setattr(dragfile.tempfile, "gettempdir", lambda: str(tmp_path))+ return tmp_path+++def test_the_folder_carries_the_user_and_is_private(temp: Path) -> None:+ path = dragfile.write_drag_file(b"\x89PNG\r\n\x1a\n")++ assert path is not None+ assert path.parent == temp / f"jarvis-appshots-{os.getuid()}"+ assert stat.S_IMODE(path.parent.stat().st_mode) == 0o700+++def test_a_world_readable_folder_of_ours_is_tightened(temp: Path) -> None:+ folder = temp / f"jarvis-appshots-{os.getuid()}"+ folder.mkdir(mode=0o755)+ os.chmod(folder, 0o755) # noqa: S103 - the loose folder this test tightens++ assert dragfile.prepare_drag_folder() == folder+ assert stat.S_IMODE(folder.stat().st_mode) == 0o700++[email protected](sys.platform == "win32", reason="symlinks")+def test_a_planted_symlink_is_refused(temp: Path) -> None:+ elsewhere = temp / "attacker"+ elsewhere.mkdir()+ (temp / f"jarvis-appshots-{os.getuid()}").symlink_to(elsewhere)++ assert dragfile.write_drag_file(b"\x89PNG\r\n\x1a\n") is None+ assert list(elsewhere.iterdir()) == []