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(keychain): write the vault via argv so large payloads keep the -A ACL (#1182)
Jakub Pilař013063ded721
diff --git a/dodaios/core/keychain_bundle.py b/dodaios/core/keychain_bundle.pyindex c861a2166d..150ed1d949 100644--- a/dodaios/core/keychain_bundle.py+++ b/dodaios/core/keychain_bundle.py@@ -32,8 +32,8 @@ file-store fallback), while remaining Keychain-encrypted at rest and lockedwith the keychain. The alternative was an unfixable per-process dialogstorm, because an unsigned interpreter can never hold a durable grant.-Secrets never appear on a command line: writes stream the payload to-``security -i`` via stdin, reads receive it on stdout. The payload is the+Writes pass the payload in argv (``security -i`` stdin truncates lines at+~4 KB, which a grown vault exceeds); reads receive it on stdout. The payload is thebase64-encoded JSON bundle — base64 doubles as the format marker that theitem was already rewritten with the ``-A`` ACL (plain JSON means akeyring-written legacy vault that still needs the one-time upgrade).@@ -155,7 +155,12 @@ class SecurityCliVault:Delete-then-add: updating an item in place would need the OLD item'sACL consent, while deleting never decrypts (always silent) and thefresh ``-A`` item admits every later CLI access without a dialog.- The payload streams through stdin (``security -i``), never argv.+ The payload goes in argv, not ``security -i`` stdin: interactive mode+ truncates input lines at ~4 KB, so a grown vault failed every CLI+ write, fell back to the per-app-ACL inner write and re-armed the+ Keychain prompt. argv is visible to same-user processes for the+ call's duration only, and the ``-A`` item is readable by any local+ process anyway (see module docstring), so no new exposure."""self._check_tokens(service, account)if not _SAFE_CLI_VALUE.match(value):@@ -168,20 +173,22 @@ class SecurityCliVault:# may then need the OLD item's ACL consent (one dialog) or fail# cleanly into the inner-backend fallback — both beat a hard# duplicate-item error.- command = (- f"add-generic-password -U -A -s {service} -a {account} -w {value}\n"- )try:proc = subprocess.run( # noqa: S603 -- fixed Apple-signed binary- [self._binary, "-i"],- input=command,+ [self._binary, "add-generic-password", "-U", "-A", "-s", service,+ "-a", account, "-w", value],capture_output=True,text=True,timeout=self._WRITE_TIMEOUT_S,creationflags=self._creationflags(),)except (OSError, subprocess.SubprocessError) as exc:- raise SecurityCliVaultError(f"security CLI write failed: {exc}") from exc+ # ``TimeoutExpired.__str__`` embeds the argv (= the payload), and a+ # chained cause would be printed by ``exc_info=True``: name the+ # type only and drop the chain.+ raise SecurityCliVaultError(+ f"security CLI write failed: {type(exc).__name__}"+ ) from Noneif proc.returncode != 0:raise SecurityCliVaultError(f"security CLI write exited {proc.returncode}: "diff --git a/tests/unit/core/test_keychain_bundle.py b/tests/unit/core/test_keychain_bundle.pyindex 61de07061f..8081e69e62 100644--- a/tests/unit/core/test_keychain_bundle.py+++ b/tests/unit/core/test_keychain_bundle.py@@ -12,6 +12,8 @@ from __future__ import annotationsimport base64import json+import os+import sysimport pytestfrom keyring.errors import PasswordDeleteError@@ -541,3 +543,44 @@ def test_wrapper_is_accepted_by_keyring_set_keyring(}, "the write must land in the single vault item, not a per-key item"finally:keyring.set_keyring(original)+++ sys.platform != "darwin" or not os.path.exists("/usr/bin/security"),+ reason="needs the real macOS security CLI",+)+def test_security_cli_write_roundtrips_payload_longer_than_interactive_line_limit() -> None:+ """``security -i`` truncates input lines at ~4 KB, so a grown vault failed+ every CLI write, fell back to the per-app-ACL inner write and re-armed the+ Keychain prompt. Uses a throwaway item, never the real vault."""+ vault = SecurityCliVault()+ service, account = "dodaios-test-long-payload", "t"+ payload = base64.b64encode(b"x" * 6000).decode("ascii") # 8000 chars+ try:+ vault.write(service, account, payload)+ assert vault.read(service, account) == payload+ finally:+ vault.delete(service, account)+++def test_security_cli_write_timeout_never_leaks_payload(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """The payload rides in argv, and ``TimeoutExpired.__str__`` embeds the+ full command, so neither the message nor the chained cause may carry it+ into a log line written with ``exc_info=True``."""+ import subprocess++ payload = base64.b64encode(b'{"anthropic_api_key": "sk-ant-tops3cret"}').decode()+ vault = SecurityCliVault()+ monkeypatch.setattr(vault, "delete", lambda service, account: None)++ def fake_run(cmd: list[str], **kwargs: object) -> None:+ raise subprocess.TimeoutExpired(cmd, 10)++ monkeypatch.setattr(subprocess, "run", fake_run)+ with pytest.raises(SecurityCliVaultError) as excinfo:+ vault.write(SERVICE, VAULT_ACCOUNT, payload)+ assert payload not in str(excinfo.value)+ assert excinfo.value.__cause__ is None+ assert excinfo.value.__suppress_context__