Skip to content

The agent that grows with you

fix(security): remove mutable display-name from SimpleX allowlist check

liuhao1024467046753420
diff --git a/gateway/authz_mixin.py b/gateway/authz_mixin.py
index 2c97016e57e..55e615b8e7e 100644
--- a/gateway/authz_mixin.py
+++ b/gateway/authz_mixin.py
@@ -169,9 +169,9 @@ def _principal_matches_allowlist(source, user_id: str, allowed_ids: set) -> bool
check_ids.add(normalized_user_id)
platform_value = source.platform.value if source.platform is not None else None
- # SimpleX: user_id is the numeric contactId but the UI only shows display names.
- if platform_value == "simplex" and source.user_name:
- check_ids.add(source.user_name)
+ # SimpleX: SIMPLEX_ALLOWED_USERS matches only the stable numeric contactId (user_id).
+ # The display name (user_name) is attacker-controlled — any contact can adopt another
+ # contact's display name, so matching it would bypass the allowlist (#44729).
# Buzz: allowlist may hold npub or hex; inbound pubkeys are hex.
if platform_value == "buzz":
# Buzz (Nostr-based): BUZZ_ALLOWED_USERS accepts npub or hex, but inbound event pubkeys are always
diff --git a/plugins/platforms/simplex/adapter.py b/plugins/platforms/simplex/adapter.py
index 0dd45bbd176..8dd65f3d53a 100644
--- a/plugins/platforms/simplex/adapter.py
+++ b/plugins/platforms/simplex/adapter.py
@@ -2,7 +2,7 @@
or ``docker run -p 5225:5225 simplexchat/simplex-chat-cli -p 5225``); JSON commands out, events in.
Env: SIMPLEX_WS_URL (required; default ws://127.0.0.1:5225) · SIMPLEX_ALLOWED_USERS (numeric
-contactIds — stable across renames, see ``/contacts`` — or display names) · SIMPLEX_ALLOW_ALL_USERS ·
+contactIds — stable across renames, see ``/contacts``) · SIMPLEX_ALLOW_ALL_USERS ·
SIMPLEX_AUTO_ACCEPT ('false' disables contact-request auto-accept; default true) ·
SIMPLEX_GROUP_ALLOWED (group IDs or '*'; omit to ignore groups) · SIMPLEX_HOME_CHANNEL[_NAME] ·
HERMES_SIMPLEX_TEXT_BATCH_DELAY (quiet seconds, default 0.8, merging rapid-fire inbound text).
@@ -643,7 +643,7 @@ async def _standalone_send(
_SETUP_PROMPTS = (
("SIMPLEX_WS_URL", "Daemon WebSocket URL (default ws://127.0.0.1:5225)"),
- ("SIMPLEX_ALLOWED_USERS", "Allowed contactIds or display names (comma-separated; blank=skip)"),
+ ("SIMPLEX_ALLOWED_USERS", "Allowed contactIds (comma-separated; blank=skip)"),
("SIMPLEX_GROUP_ALLOWED", "Allowed group IDs (comma-separated, or '*' for any; blank=disable groups)"),
("SIMPLEX_AUTO_ACCEPT", "Auto-accept incoming contact requests? (true/false, default true)"),
("SIMPLEX_HOME_CHANNEL", "Home channel contact/group ID (or empty)"))
diff --git a/tests/gateway/test_simplex_plugin.py b/tests/gateway/test_simplex_plugin.py
index 6c96325dfbe..17d0a1ebfc3 100644
--- a/tests/gateway/test_simplex_plugin.py
+++ b/tests/gateway/test_simplex_plugin.py
@@ -483,3 +483,11 @@ 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
+
+
+def test_setup_prompts_no_longer_offer_display_names():
+ """The setup wizard must not suggest display names as SIMPLEX_ALLOWED_USERS
+ values: authorization only matches the stable numeric contactId, and a
+ display-name entry would silently fail closed (#44729)."""
+ prompts = dict(_simplex._SETUP_PROMPTS)
+ assert "display name" not in prompts["SIMPLEX_ALLOWED_USERS"].lower()
diff --git a/tests/gateway/test_unauthorized_dm_behavior.py b/tests/gateway/test_unauthorized_dm_behavior.py
index 1e7d47f5675..dc6754613d4 100644
--- a/tests/gateway/test_unauthorized_dm_behavior.py
+++ b/tests/gateway/test_unauthorized_dm_behavior.py
@@ -120,11 +120,11 @@ def test_whatsapp_lid_user_matches_phone_allowlist_via_modern_session_mapping(
assert runner._is_user_authorized(source) is True
-def test_simplex_allowlist_accepts_display_name(monkeypatch):
- """SIMPLEX_ALLOWED_USERS should match the contact's display name as well
- as the numeric contactId. The SimpleX UI surfaces only display names, so
- operators naturally put those in the env var — and the adapter sets
- user_id=contactId for stability. Both forms must work. (#TBD)"""
+def test_simplex_allowlist_rejects_display_name_only(monkeypatch):
+ """SIMPLEX_ALLOWED_USERS must NOT match the contact's display name — only
+ the stable numeric contactId. A different contact can set their display
+ name to the same value, so matching user_name would bypass the allowlist
+ (security: display-name collision bypass, #44729)."""
_clear_auth_env(monkeypatch)
monkeypatch.delenv("SIMPLEX_ALLOWED_USERS", raising=False)
monkeypatch.setenv("SIMPLEX_ALLOWED_USERS", "hujikuji")
@@ -146,8 +146,9 @@ def test_simplex_allowlist_accepts_display_name(monkeypatch):
GatewayConfig(platforms={simplex: PlatformConfig(enabled=True)}),
)
- # contactId in the allowlist would still work — but the operator chose
- # the display name. Verify the gateway honors it.
+ # The operator put the display name in the allowlist, but user_id is the
+ # stable contactId which differs. Display names are attacker-controlled,
+ # so this must be rejected.
source = SessionSource(
platform=simplex,
user_id="4", # adapter sets this to the numeric contactId
@@ -155,6 +156,75 @@ def test_simplex_allowlist_accepts_display_name(monkeypatch):
user_name="hujikuji", # adapter sets this to displayName
chat_type="dm",
)
+ assert runner._is_user_authorized(source) is False
+
+
+def test_simplex_allowlist_rejects_colliding_display_name(monkeypatch):
+ """Security regression guard: a contact whose contactId is NOT in the
+ allowlist must stay unauthorized even when they adopt the display name of
+ an allowed contact (#44729)."""
+ _clear_auth_env(monkeypatch)
+ monkeypatch.delenv("SIMPLEX_ALLOWED_USERS", raising=False)
+ # Operator allowed contactId "4" (who happens to use display name "hujikuji")
+ monkeypatch.setenv("SIMPLEX_ALLOWED_USERS", "4")
+
+ from gateway.platform_registry import platform_registry, PlatformEntry
+ platform_registry.register(PlatformEntry(
+ name="simplex",
+ label="SimpleX Chat",
+ adapter_factory=lambda cfg: None,
+ check_fn=lambda: True,
+ allowed_users_env="SIMPLEX_ALLOWED_USERS",
+ allow_all_env="SIMPLEX_ALLOW_ALL_USERS",
+ ))
+
+ simplex = Platform("simplex")
+ runner, _adapter = _make_runner(
+ simplex,
+ GatewayConfig(platforms={simplex: PlatformConfig(enabled=True)}),
+ )
+
+ # Attacker: different contactId ("7") but same display name as the allowed user
+ source = SessionSource(
+ platform=simplex,
+ user_id="7", # different contactId — NOT in allowlist
+ chat_id="attacker",
+ user_name="hujikuji", # same display name as allowed user
+ chat_type="dm",
+ )
+ assert runner._is_user_authorized(source) is False
+
+
+def test_simplex_allowlist_accepts_numeric_contact_id(monkeypatch):
+ """SIMPLEX_ALLOWED_USERS continues to match the stable numeric contactId
+ (user_id) — the one identity form a SimpleX contact cannot forge."""
+ _clear_auth_env(monkeypatch)
+ monkeypatch.delenv("SIMPLEX_ALLOWED_USERS", raising=False)
+ monkeypatch.setenv("SIMPLEX_ALLOWED_USERS", "4")
+
+ from gateway.platform_registry import platform_registry, PlatformEntry
+ platform_registry.register(PlatformEntry(
+ name="simplex",
+ label="SimpleX Chat",
+ adapter_factory=lambda cfg: None,
+ check_fn=lambda: True,
+ allowed_users_env="SIMPLEX_ALLOWED_USERS",
+ allow_all_env="SIMPLEX_ALLOW_ALL_USERS",
+ ))
+
+ simplex = Platform("simplex")
+ runner, _adapter = _make_runner(
+ simplex,
+ GatewayConfig(platforms={simplex: PlatformConfig(enabled=True)}),
+ )
+
+ source = SessionSource(
+ platform=simplex,
+ user_id="4", # numeric contactId in the allowlist
+ chat_id="hujikuji",
+ user_name="whatever", # display name is irrelevant to the verdict
+ chat_type="dm",
+ )
assert runner._is_user_authorized(source) is True