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(security): write session.json owner-only (0600) on POSIX
Ruben Lütke1feabd61d400
diff --git a/jarvis/ui/shell/single_instance.py b/jarvis/ui/shell/single_instance.pyindex 03846dd060..f5ed0293b1 100644--- a/jarvis/ui/shell/single_instance.py+++ b/jarvis/ui/shell/single_instance.py@@ -8,8 +8,8 @@2. **Session file** (`%LOCALAPPDATA%\\Jarvis\\session.json`) — stores the port +token of the running primary instance, so a secondary can ping it on- ``/internal/activate``. Token-protected, roughly 0600- (user ACL).+ ``/internal/activate``. Token-protected: owner-only 0600 on POSIX+ (explicit), per-user profile ACL on Windows.Flow when a secondary starts:@@ -24,6 +24,7 @@ from __future__ import annotationsimport jsonimport loggingimport os+import statfrom dataclasses import dataclassfrom pathlib import Pathfrom typing import Any@@ -126,7 +127,17 @@ class SingleInstance:def write_session(self, *, port: int, token: str) -> None:data = {"port": port, "token": token, "pid": os.getpid()}- self.session_file.write_text(json.dumps(data), encoding="utf-8")+ path = self.session_file+ # The token authorizes the full control API, so the file must be+ # owner-only. O_CREAT's mode keeps a NEW file at 0600 from the first+ # byte; the explicit chmod repairs a pre-existing file from older+ # builds that wrote with the default umask. Windows relies on the+ # per-user profile ACL instead of POSIX bits.+ fd = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)+ with os.fdopen(fd, "w", encoding="utf-8") as fh:+ fh.write(json.dumps(data))+ if os.name != "nt":+ os.chmod(path, stat.S_IRUSR | stat.S_IWUSR)def read_session(self) -> dict[str, Any] | None:try:diff --git a/tests/unit/ui/test_session_file_permissions.py b/tests/unit/ui/test_session_file_permissions.pynew file mode 100644index 0000000000..5d6dae27ac--- /dev/null+++ b/tests/unit/ui/test_session_file_permissions.py@@ -0,0 +1,43 @@+"""Session-file permission contract (single-instance token hardening).++The session file carries the bearer token for the full control API; on POSIX+it must be owner-only (0600) — including when an older build left a+world-readable file behind. Windows relies on the per-user profile ACL, so+the mode-bit assertions are POSIX-only.+"""+from __future__ import annotations++import json+import os+import stat+import sys++import pytest++from jarvis.ui.shell.single_instance import SingleInstance+++def test_write_session_roundtrip(tmp_path):+ si = SingleInstance(app_dir=tmp_path)+ si.write_session(port=1234, token="tok")+ data = json.loads((tmp_path / "session.json").read_text(encoding="utf-8"))+ assert data["port"] == 1234+ assert data["token"] == "tok"+ assert data["pid"] == os.getpid()++[email protected](sys.platform == "win32", reason="POSIX mode bits only")+def test_write_session_is_owner_only_on_posix(tmp_path):+ si = SingleInstance(app_dir=tmp_path)+ si.write_session(port=1234, token="tok")+ mode = stat.S_IMODE((tmp_path / "session.json").stat().st_mode)+ assert mode == 0o600++[email protected](sys.platform == "win32", reason="POSIX mode bits only")+def test_write_session_repairs_preexisting_loose_permissions(tmp_path):+ loose = tmp_path / "session.json"+ loose.write_text("{}", encoding="utf-8")+ os.chmod(loose, 0o644) # what older builds left behind+ SingleInstance(app_dir=tmp_path).write_session(port=1, token="t")+ assert stat.S_IMODE(loose.stat().st_mode) == 0o600