Allowlist pubkey prefixes only; ignore public and hashtag channels

- is_allowed matches pubkey_prefix only; sender names are never trusted
  (channel senders must be known contacts of the companion for the
  MeshCore integration to include their pubkey_prefix)
- channel messages on channel index 0 (public) and hashtag channels
  ('#name') are ignored unconditionally, before the allowlist check
- config flow validates allowlist entries as 6-64 hex characters
  (invalid_allowlist error) and UI strings/README updated
This commit is contained in:
Dejvino
2026-12-01 19:45:36 +01:00
parent 8eba7fa24c
commit 5d60a91964
8 changed files with 165 additions and 26 deletions
+69 -1
View File
@@ -142,12 +142,14 @@ async def test_allow_all_option():
async def test_channel_message_replies_to_channel():
agent, hass = make_agent(allowlist="groupchat")
agent, hass = make_agent(allowlist="def456abc012")
await deliver(
agent,
{
"message_type": "channel",
"channel_idx": 1,
"channel": "friends",
"pubkey_prefix": "def456abc012",
"sender_name": "groupchat",
"message": "agent todo add From channel",
},
@@ -161,6 +163,8 @@ async def test_channel_message_replies_to_channel():
{
"message_type": "channel",
"channel_idx": 1,
"channel": "friends",
"pubkey_prefix": "def456abc012",
"sender_name": "groupchat",
"message": "remind 1 in 30m",
},
@@ -170,6 +174,70 @@ async def test_channel_message_replies_to_channel():
assert reminder.target == "1"
async def test_public_channel_ignored():
agent, hass = make_agent(allow_all=True)
await deliver(
agent,
{
"message_type": "channel",
"channel_idx": 0,
"channel": "public",
"pubkey_prefix": "def456abc012",
"message": "agent todo add From public",
},
)
assert hass.services.calls == []
assert agent.todo_store.items == []
async def test_hashtag_channel_ignored():
agent, hass = make_agent(allow_all=True)
await deliver(
agent,
{
"message_type": "channel",
"channel_idx": 1,
"channel": "#mychannel",
"pubkey_prefix": "def456abc012",
"message": "agent todo add From hashtag",
},
)
assert hass.services.calls == []
assert agent.todo_store.items == []
async def test_channel_non_contact_ignored():
# Channel messages carry no pubkey_prefix unless the sender is a known
# contact of the companion; names are never matched.
agent, hass = make_agent(allowlist="def456abc012")
await deliver(
agent,
{
"message_type": "channel",
"channel_idx": 1,
"channel": "friends",
"sender_name": "groupchat",
"message": "agent todo add From channel",
},
)
assert hass.services.calls == []
assert agent.todo_store.items == []
async def test_allowlist_never_matches_names():
agent, hass = make_agent(allowlist="groupchat")
await deliver(
agent,
{
"message_type": "direct",
"sender_name": "groupchat",
"pubkey_prefix": "ffff00",
"message": "todo",
},
)
assert hass.services.calls == []
async def test_reminder_firing():
agent, hass = make_agent()
await deliver(