fix: normalize LID→PN in handleBadAck, media retry, and PDO recovery

Additional leak points found during final audit:
- handleBadAck: key.remoteJid from ack stanza could be LID
- messages.media-update: media retry key JIDs not normalized
- CTWA PDO recovery: webMessageInfo.key from phone response not normalized

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Renato Alcara
2026-03-01 17:10:57 -03:00
parent ac7bb321d4
commit 0a43ad849d
2 changed files with 10 additions and 1 deletions
+4 -1
View File
@@ -1645,6 +1645,8 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
break
case 'mediaretry':
const event = decodeMediaRetryNode(node)
// Normalize LID→PN in media retry key before emitting
await normalizeKeyLidToPn(event.key, signalRepository.lidMapping, logger)
ev.emit('messages.media-update', [event])
break
case 'encrypt':
@@ -2734,7 +2736,8 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
}
const handleBadAck = async ({ attrs }: BinaryNode) => {
const key: WAMessageKey = { remoteJid: attrs.from, fromMe: true, id: attrs.id }
const resolvedFrom = await resolveLidToPn(attrs.from, signalRepository.lidMapping, logger) || attrs.from
const key: WAMessageKey = { remoteJid: resolvedFrom, fromMe: true, id: attrs.id }
// WARNING: REFRAIN FROM ENABLING THIS FOR NOW. IT WILL CAUSE A LOOP
// // current hypothesis is that if pash is sent in the ack
+6
View File
@@ -589,6 +589,12 @@ const processMessage = async (
'CTWA: Successfully recovered message via placeholder resend'
)
// Normalize LID→PN in PDO-recovered message key before emitting
// eslint-disable-next-line max-depth
if (webMessageInfo.key && signalRepository) {
await normalizeKeyLidToPn(webMessageInfo.key as WAMessageKey, signalRepository.lidMapping, logger)
}
// wait till another upsert event is available, don't want it to be part of the PDO response message
// TODO: parse through proper message handling utilities (to add relevant key fields)
ev.emit('messages.upsert', {