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): treat the shipped placeholder control-API key as unset
Ruben Lütke7b072be6371a
diff --git a/docker-compose.yml b/docker-compose.ymlindex 2b5290a578..7cde30ca9e 100644--- a/docker-compose.yml+++ b/docker-compose.yml@@ -16,9 +16,14 @@ services:ports:- "127.0.0.1:8000:8000"environment:- # The Control-API key authorises the non-loopback (0.0.0.0) bind. Change- # this — it is the only boundary protecting the control surface.- JARVIS_CONTROL_API_KEY: "jctl_local_sandbox_change_me_before_any_real_use"+ # The Control-API key authorises the non-loopback (0.0.0.0) bind — it is+ # the only boundary protecting the control surface. No default is+ # shipped: compose refuses to start until you export a fresh random+ # value (e.g. `export JARVIS_CONTROL_API_KEY=$(openssl rand -hex 32)`),+ # so a copy-pasted deployment can never end up on a world-known key. The+ # app itself also refuses the old shipped literal if it is ever set+ # again, treating it as if no key were configured.+ JARVIS_CONTROL_API_KEY: "${JARVIS_CONTROL_API_KEY:?set a fresh random control key}"# Provider keys — set your OWN keys. At least one brain provider is needed# for a real reply; the server still boots and serves the UI without them.ANTHROPIC_API_KEY: "${ANTHROPIC_API_KEY:-}"diff --git a/jarvis/core/control_key.py b/jarvis/core/control_key.pyindex 79a1c06fc7..32cd7054fd 100644--- a/jarvis/core/control_key.py+++ b/jarvis/core/control_key.py@@ -20,6 +20,7 @@ dedicated key-reveal endpoint."""from __future__ import annotations+import loggingimport osimport secretsimport stat@@ -27,12 +28,43 @@ from pathlib import Pathfrom jarvis.core import config as cfg+logger = logging.getLogger(__name__)+KEY_PREFIX = "jctl_"KEYRING_SLOT = "jarvis_control_api_key"ENV_VAR = "JARVIS_CONTROL_API_KEY"_FILE_NAME = ".control_api_key"_TOKEN_BYTES = 32 # 256-bit+# The literal value shipped as the default in docker-compose.yml. It is+# world-known (public repo, public image) the moment it is ever used+# unmodified, so it must never be accepted as a real key — wherever it is+# found (keyring, file fallback, or the env seed) it is treated exactly as if+# no key were configured at all.+SHIPPED_PLACEHOLDER_KEY = "jctl_local_sandbox_change_me_before_any_real_use"++_warned_shipped_placeholder = False+++def _warn_shipped_placeholder_once() -> None:+ """Log a single, clear warning the first time the placeholder is seen.++ ``get_control_key()`` can be called on every request (via+ ``verify_control_key``); logging on every call would flood the log, so+ this fires once per process.+ """+ global _warned_shipped_placeholder+ if _warned_shipped_placeholder:+ return+ _warned_shipped_placeholder = True+ logger.warning(+ "Jarvis Control API key is set to the shipped placeholder value "+ "from docker-compose.yml — refusing it and treating it as if no key "+ "were configured. Set %s to a fresh random value before exposing the "+ "control surface.",+ ENV_VAR,+ )+def generate_control_key() -> str:"""A fresh 256-bit URL-safe key with a greppable ``jctl_`` prefix."""@@ -108,14 +140,36 @@ def _store(key: str) -> None:def get_control_key() -> str | None:- """The active key. Order: keyring -> 0600 file -> env seed."""+ """The active key. Order: keyring -> 0600 file -> env seed.++ The shipped ``docker-compose.yml`` placeholder (``SHIPPED_PLACEHOLDER_KEY``)+ is never returned as a real key, no matter which layer it was found in —+ it is treated exactly as if that layer held nothing, and resolution keeps+ falling through the chain.+ """+ saw_placeholder = False+value = cfg.get_secret(KEYRING_SLOT) # keyring only (no env fallback here)if value:- return value+ if value != SHIPPED_PLACEHOLDER_KEY:+ return value+ saw_placeholder = True+value = _read_file_key()if value:- return value- return _env_key()+ if value != SHIPPED_PLACEHOLDER_KEY:+ return value+ saw_placeholder = True++ value = _env_key()+ if value:+ if value != SHIPPED_PLACEHOLDER_KEY:+ return value+ saw_placeholder = True++ if saw_placeholder:+ _warn_shipped_placeholder_once()+ return Nonedef ensure_control_key() -> str:diff --git a/tests/unit/core/test_control_key.py b/tests/unit/core/test_control_key.pyindex ae833467f0..1c56439f41 100644--- a/tests/unit/core/test_control_key.py+++ b/tests/unit/core/test_control_key.py@@ -112,3 +112,63 @@ def test_env_seed_used_when_no_keyring_no_file(isolated, monkeypatch) -> None:# ensure must NOT overwrite an operator-provided env seedassert ck.ensure_control_key() == "jctl_envseed0000"assert ck.KEYRING_SLOT not in isolated+++# --- shipped docker-compose.yml placeholder must never be accepted as real ---+++def test_shipped_placeholder_constant_matches_docker_compose() -> None:+ # docker-compose.yml ships this exact literal; keep both in lockstep.+ assert ck.SHIPPED_PLACEHOLDER_KEY == "jctl_local_sandbox_change_me_before_any_real_use"+++def test_get_treats_placeholder_env_seed_as_unset(isolated, monkeypatch) -> None:+ monkeypatch.setenv("JARVIS_CONTROL_API_KEY", ck.SHIPPED_PLACEHOLDER_KEY)+ assert ck.get_control_key() is None+++def test_get_treats_placeholder_keyring_value_as_unset(isolated) -> None:+ isolated[ck.KEYRING_SLOT] = ck.SHIPPED_PLACEHOLDER_KEY+ assert ck.get_control_key() is None+++def test_get_treats_placeholder_file_value_as_unset(monkeypatch, tmp_path) -> None:+ monkeypatch.setattr(cfg, "set_secret", lambda *a, **k: False)+ monkeypatch.setattr(cfg, "get_secret", lambda *a, **k: None)+ monkeypatch.setenv("JARVIS_DATA_DIR", str(tmp_path))+ monkeypatch.delenv("JARVIS_CONTROL_API_KEY", raising=False)+ ck.control_key_file().parent.mkdir(parents=True, exist_ok=True)+ ck.control_key_file().write_text(ck.SHIPPED_PLACEHOLDER_KEY, encoding="utf-8")++ assert ck.get_control_key() is None+++def test_verify_rejects_the_placeholder_itself(isolated, monkeypatch) -> None:+ monkeypatch.setenv("JARVIS_CONTROL_API_KEY", ck.SHIPPED_PLACEHOLDER_KEY)+ # Presenting the exact placeholder must be denied — same as "no key configured".+ assert ck.verify_control_key(ck.SHIPPED_PLACEHOLDER_KEY) is False+++def test_ensure_regenerates_a_real_key_when_placeholder_configured(isolated, monkeypatch) -> None:+ monkeypatch.setenv("JARVIS_CONTROL_API_KEY", ck.SHIPPED_PLACEHOLDER_KEY)+ fresh = ck.ensure_control_key()+ assert fresh != ck.SHIPPED_PLACEHOLDER_KEY+ assert fresh.startswith("jctl_")+ # The freshly generated key is now the active one (stored, not the env seed).+ assert ck.get_control_key() == fresh+ assert isolated.get(ck.KEYRING_SLOT) == fresh+++def test_get_logs_a_warning_naming_the_remedy(isolated, monkeypatch, caplog) -> None:+ # The warning is deliberately logged only once per process (get_control_key+ # is on the hot request path); reset that latch so this test is independent+ # of whatever ran earlier in the same session.+ monkeypatch.setattr(ck, "_warned_shipped_placeholder", False)+ monkeypatch.setenv("JARVIS_CONTROL_API_KEY", ck.SHIPPED_PLACEHOLDER_KEY)+ with caplog.at_level("WARNING", logger="jarvis.core.control_key"):+ assert ck.get_control_key() is None+ assert any(+ "JARVIS_CONTROL_API_KEY" in record.getMessage()+ and "fresh random value" in record.getMessage()+ for record in caplog.records+ )