The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: WhatsApp group messages dropped when LID sender has no lid-mapping (#72529)
jinlingzi-cmd3926c4209c78
diff --git a/scripts/whatsapp-bridge/allowlist.js b/scripts/whatsapp-bridge/allowlist.jsindex 2cb5c634a84..9b025074207 100644--- a/scripts/whatsapp-bridge/allowlist.js+++ b/scripts/whatsapp-bridge/allowlist.js@@ -63,13 +63,14 @@ export function expandWhatsAppIdentifiers(identifier, sessionDir) {return resolved;}-export function matchesAllowedSender(senderId, senderPn, allowedUsers, sessionDir) {+export function matchesAllowedSender(senderId, senderAltId, allowedUsers, sessionDir) {// WhatsApp Multi-Device can expose a first-contact sender as an opaque LID// before it persists LID mapping files. Baileys supplies the same sender's- // authenticated phone JID separately in msg.key.senderPn, so consult it- // as an additional alias without changing the allowlist itself.+ // phone JID separately (key.remoteJidAlt for DMs, key.participantAlt in+ // groups), so consult it as an additional alias without changing the+ // allowlist itself (#63415, #72529).return matchesAllowedUser(senderId, allowedUsers, sessionDir)- || matchesAllowedUser(senderPn, allowedUsers, sessionDir);+ || matchesAllowedUser(senderAltId, allowedUsers, sessionDir);}export function matchesAllowedUser(senderId, allowedUsers, sessionDir) {diff --git a/scripts/whatsapp-bridge/allowlist.test.mjs b/scripts/whatsapp-bridge/allowlist.test.mjsindex 42fde368040..bac652fedf4 100644--- a/scripts/whatsapp-bridge/allowlist.test.mjs+++ b/scripts/whatsapp-bridge/allowlist.test.mjs@@ -100,3 +100,49 @@ test('matchesAllowedUser rejects everyone when allowlist is empty (#8389)', () =rmSync(sessionDir, { recursive: true, force: true });}});++test('matchesAllowedSender falls back to participantAlt when no lid mapping exists (#72529)', () => {+ // Baileys v7 group messages arrive with key.participant in LID form and+ // the phone number only in key.participantAlt. A fresh bot session has no+ // lid-mapping-*.json files, so the LID alone can never match a phone+ // allowlist — the alt identifier must be consulted as a fallback.+ const sessionDir = mkdtempSync(path.join(os.tmpdir(), 'hermes-wa-allowlist-'));++ try {+ const allowedUsers = parseAllowedUsers('+19175395595');++ // No mapping file: LID by itself is rejected today (the #72529 drop)…+ assert.equal(matchesAllowedUser('267383306489914@lid', allowedUsers, sessionDir), false);+ // …but the alt phone identifier rescues the match.+ assert.equal(+ matchesAllowedSender('267383306489914@lid', '[email protected]', allowedUsers, sessionDir),+ true+ );++ // A stranger's LID with a non-allowlisted alt stays rejected.+ assert.equal(+ matchesAllowedSender('188012763865257@lid', '[email protected]', allowedUsers, sessionDir),+ false+ );++ // Missing / empty alt keeps the existing behaviour.+ assert.equal(matchesAllowedSender('267383306489914@lid', '', allowedUsers, sessionDir), false);+ assert.equal(matchesAllowedSender('267383306489914@lid', undefined, allowedUsers, sessionDir), false);+ } finally {+ rmSync(sessionDir, { recursive: true, force: true });+ }+});++test('matchesAllowedSender still resolves via lid-mapping files without an alt', () => {+ const sessionDir = mkdtempSync(path.join(os.tmpdir(), 'hermes-wa-allowlist-'));++ try {+ writeFileSync(path.join(sessionDir, 'lid-mapping-19175395595.json'), JSON.stringify('267383306489914'));+ writeFileSync(path.join(sessionDir, 'lid-mapping-267383306489914_reverse.json'), JSON.stringify('19175395595'));++ const allowedUsers = parseAllowedUsers('+19175395595');+ assert.equal(matchesAllowedSender('267383306489914@lid', '', allowedUsers, sessionDir), true);+ } finally {+ rmSync(sessionDir, { recursive: true, force: true });+ }+});diff --git a/scripts/whatsapp-bridge/bridge.js b/scripts/whatsapp-bridge/bridge.jsindex 830247f10de..74718afd596 100644--- a/scripts/whatsapp-bridge/bridge.js+++ b/scripts/whatsapp-bridge/bridge.js@@ -525,8 +525,12 @@ async function startSocket() {const chatId = msg.key.remoteJid;const senderId = msg.key.participant || chatId;- const senderPn = msg.key.senderPn || '';- const resolvedSenderId = senderPn || senderId;+ // Baileys v7 carries the other form of the sender here (group: key.participantAlt,+ // DM: key.remoteJidAlt). A LID sender's phone twin makes a phone allowlist match with no+ // lid-mapping file yet (#63415, #72529) and is the identity Python sees, so first+ // contacts key the same session they will once the mapping exists.+ const senderAltId = normalizeWhatsAppId(msg.key.participantAlt || msg.key.remoteJidAlt || '');+ const resolvedSenderId = senderAltId.endsWith('@s.whatsapp.net') ? senderAltId : senderId;const isGroup = chatId.endsWith('@g.us');const senderNumber = resolvedSenderId.replace(/@.*/, '');emitDebugEvent({@@ -629,13 +633,14 @@ async function startSocket() {} catch {}continue;}- if (WHATSAPP_DM_POLICY !== 'pairing' && !matchesAllowedSender(senderId, senderPn, ALLOWED_USERS, SESSION_DIR)) {+ if (WHATSAPP_DM_POLICY !== 'pairing' && !matchesAllowedSender(senderId, senderAltId, ALLOWED_USERS, SESSION_DIR)) {try {console.log(JSON.stringify({event: 'ignored',reason: 'allowlist_mismatch',chatId,senderId,+ senderAltId,}));} catch {}continue;