The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(simplex): read allowlist name-warning profile-scoped, before the probe
kshitijk4poor3a47e65ef3ce
diff --git a/plugins/platforms/simplex/adapter.py b/plugins/platforms/simplex/adapter.pyindex 3a1b458271c..fff5b5d30b6 100644--- a/plugins/platforms/simplex/adapter.py+++ b/plugins/platforms/simplex/adapter.py@@ -118,6 +118,7 @@ class SimplexAdapter(BasePlatformAdapter):self._pending_file_transfers: Dict[int, dict] = {} # awaiting rcvFileComplete, by fileIdself._pending_responses: Dict[str, asyncio.Future] = {} # awaited command repliesself._corr_counter = 0+ self._allowlist_warned = False # name-entry allowlist warning fires once per adapter# SimpleX has no client-side split, so the split delay equals the plain one.self._text_batch_delay_seconds = float(os.getenv("HERMES_SIMPLEX_TEXT_BATCH_DELAY", "0.8"))self._text_batch_split_delay_seconds = self._text_batch_delay_seconds@@ -134,6 +135,15 @@ class SimplexAdapter(BasePlatformAdapter):if not self.ws_url:logger.error("SimpleX: SIMPLEX_WS_URL is required")return False+ # Once per adapter, before the probe so a daemon-down cold boot still warns (later connects+ # arrive as is_reconnect=True). Scoped read matches what authz enforces for this profile.+ if not self._allowlist_warned:+ self._allowlist_warned = True+ names = [u for u in _parse_comma_list(_get_scoped_secret("SIMPLEX_ALLOWED_USERS", "") or "")+ if u != "*" and not u.isdigit()]+ if names:+ logger.warning("SimpleX: SIMPLEX_ALLOWED_USERS entries %s are not numeric contactIds and are ignored "+ "(display names are not trusted; see /contacts for IDs)", names)try: # quick connectivity check — open and immediately closeasync with _wsclient.connect(self.ws_url, open_timeout=10):pass@@ -146,10 +156,6 @@ class SimplexAdapter(BasePlatformAdapter):self._health_task = asyncio.create_task(self._health_monitor())self._mark_connected()logger.info("SimpleX: connected to %s", self.ws_url)- names = [u for u in os.getenv("SIMPLEX_ALLOWED_USERS", "").split(",") if u.strip() not in ("", "*") and not u.strip().isdigit()]- if names and not is_reconnect:- logger.warning("SimpleX: SIMPLEX_ALLOWED_USERS entries %s are not numeric contactIds and are ignored "- "(display names are not trusted; see /contacts for IDs)", names)self._wire_plugin_handlers(None)return Truediff --git a/tests/gateway/test_simplex_plugin.py b/tests/gateway/test_simplex_plugin.pyindex 6c96325dfbe..d8ee90b7eb3 100644--- a/tests/gateway/test_simplex_plugin.py+++ b/tests/gateway/test_simplex_plugin.py@@ -483,3 +483,58 @@ def test_multiplex_scope_reads_profile_own_env_not_default(seeded = _env_enablement()assert seeded == {"ws_url": "ws://profile:5225", "group_allowed": "g1"}assert check_requirements() is True+++async def test_name_allowlist_warning_once_scoped_even_if_first_connect_fails(monkeypatch, caplog):+ """Name entries in SIMPLEX_ALLOWED_USERS are ignored by authz, so connect()+ warns -- exactly once per adapter, from the profile-scoped value authz+ enforces (not the default profile's os.environ), and even when the first+ connect fails (daemon down at cold boot; retries arrive as is_reconnect)."""+ import logging++ import websockets+ from agent.secret_scope import reset_secret_scope, set_multiplex_active, set_secret_scope+ from gateway.config import PlatformConfig++ monkeypatch.setenv("SIMPLEX_ALLOWED_USERS", "bob") # default profile's bridge output++ class DummyWs:+ async def __aenter__(self):+ return self++ async def __aexit__(self, exc_type, exc, tb):+ return None++ attempts = []++ def fake_connect(url, **kwargs):+ attempts.append(url)+ if len(attempts) == 1:+ raise OSError("daemon down")+ return DummyWs()++ async def _idle():+ return None++ monkeypatch.setattr(websockets, "connect", fake_connect)+ adapter = SimplexAdapter(PlatformConfig(enabled=True, extra={"ws_url": "ws://localhost:5225"}))+ monkeypatch.setattr(adapter, "_ws_listener", _idle)+ monkeypatch.setattr(adapter, "_health_monitor", _idle)++ # Scope set inside the test: a sync fixture's ContextVar token can't be reset from here.+ set_multiplex_active(True)+ token = set_secret_scope({"SIMPLEX_ALLOWED_USERS": "4, alice"})+ try:+ with caplog.at_level(logging.WARNING):+ assert await adapter.connect() is False+ assert await adapter.connect(is_reconnect=True) is True+ await adapter.disconnect()+ finally:+ reset_secret_scope(token)+ set_multiplex_active(False)++ warnings = [r.getMessage() for r in caplog.records if "not numeric contactIds" in r.getMessage()]+ assert len(warnings) == 1+ assert "['alice']" in warnings[0]+ assert "bob" not in warnings[0]