hermes-agent/scripts/whatsapp-bridge
Keira Voss db52ad0f07 fix(whatsapp): gate owner-typed forwards on customer chatId allowlist
The opt-in WHATSAPP_FORWARD_OWNER_MESSAGES path in bot mode marks
fromMe inbound messages as fromOwner: true and forwards them to the
Python adapter so plugins can detect "owner just typed in this chat"
and trigger handover / sliding TTL flows. The previous implementation
bypassed the allowlist for that path: the existing allowlist gate at
the bottom of the dispatch loop is guarded by !msg.key.fromMe, so any
chat the operator happened to reply to was forwarded — even ones not
on WHATSAPP_ALLOWED_USERS.

Concretely, on a deployment with a single allowlisted customer, an
owner reply in any other chat would still wake Hermes and let the
gateway-policy plugin's owner-implicit branch create a stray handover
row keyed by the non-allowlisted chatId.

Fix: extract the bot-mode fromMe gate into a small pure helper
(`owner_message_gate.js`) that returns one of
{drop_echo, drop_disabled, drop_allowlist, forward_owner, pass} so the
new allowlist branch can be unit-tested without spinning up Baileys.
The check runs against the customer chatId (not senderId, which is
the owner's own number/LID and won't be on the allowlist by
construction). matchesAllowedUser already short-circuits true on an
empty allowlist or "*", so deployments without an allowlist see no
behavior change.

Self-chat mode is untouched — its existing isSelfChat pin is the
correct guard there.

Tests: scripts/whatsapp-bridge/owner_message_gate.test.mjs covers
echo drop, disabled drop, the new allowlist drop, the forward path,
the open-allowlist short-circuit, and the precedence of echo/disabled
checks over the allowlist check (so logs stay honest).
2026-06-30 03:41:43 -07:00
..
allowlist.js fix(whatsapp): reject strangers by default, never respond in self-chat (#8389) (#21291) 2026-05-07 06:53:04 -07:00
allowlist.test.mjs fix(whatsapp): reject strangers by default, never respond in self-chat (#8389) (#21291) 2026-05-07 06:53:04 -07:00
bridge.js fix(whatsapp): gate owner-typed forwards on customer chatId allowlist 2026-06-30 03:41:43 -07:00
bridge.sendqueue.test.mjs fix(whatsapp-bridge): serialize sendMessage to prevent cross-chat contamination (#33360) 2026-06-28 01:10:14 -07:00
outbound_ids.js feat(whatsapp): opt-in forwarding of owner-typed messages in bot mode 2026-06-30 03:41:43 -07:00
outbound_ids.test.mjs feat(whatsapp): opt-in forwarding of owner-typed messages in bot mode 2026-06-30 03:41:43 -07:00
owner_message_gate.js fix(whatsapp): gate owner-typed forwards on customer chatId allowlist 2026-06-30 03:41:43 -07:00
owner_message_gate.test.mjs fix(whatsapp): gate owner-typed forwards on customer chatId allowlist 2026-06-30 03:41:43 -07:00
package-lock.json Add Hermes desktop app (#20059) 2026-05-31 17:46:56 -05:00
package.json fix(whatsapp): pin protobufjs >=7.5.5 via npm overrides to clear 3 critical vulns (#19204) 2026-05-03 05:22:30 -07:00