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:
@@ -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
|
||||
|
||||
@@ -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', {
|
||||
|
||||
Reference in New Issue
Block a user