diff --git a/src/Utils/decode-wa-message.ts b/src/Utils/decode-wa-message.ts index 7a5fa635..2ef0d008 100644 --- a/src/Utils/decode-wa-message.ts +++ b/src/Utils/decode-wa-message.ts @@ -427,13 +427,16 @@ export const decryptMessageNode = ( try { const deletedCount = await cleanupCorruptedSession(decryptionJid, repository, logger) - // Mask JID for privacy (show first 4 and last 4 digits) - const maskedJid = decryptionJid.length > 8 - ? `${decryptionJid.substring(0, 4)}****${decryptionJid.substring(decryptionJid.length - 4)}` - : decryptionJid + // Mask only user portion of JID for privacy (preserve domain info) + const { user, server } = jidDecode(decryptionJid) || {} + const maskedUser = user && user.length > 8 + ? `${user.substring(0, 4)}****${user.substring(user.length - 4)}` + : user + const maskedJid = maskedUser && server ? `${maskedUser}@${server}` : decryptionJid logger.info( - `🔄 Session Reset | JID: ${maskedJid} | Cleared: ${deletedCount} devices | Will recreate on next message` + { jid: decryptionJid, maskedJid, targetedDevices: deletedCount }, + `🔄 Session Reset | JID: ${maskedJid} | Targeted: ${deletedCount} devices | Will recreate on next message` ) } catch (cleanupErr) { logger.error( diff --git a/src/index.ts b/src/index.ts index 644f156a..7449b7ce 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,6 @@ // Format session error logs from libsignal BEFORE any imports // This MUST be at the very top to intercept console before libsignal loads // ============================================ -const _origConsoleLog = console.log const _origConsoleError = console.error // Track errors by type + JID to avoid duplicates (using Map for better performance) @@ -36,7 +35,7 @@ console.error = function(...args: unknown[]) { else if (msg.includes('Failed to decrypt')) errorType = '🔌 Decryption Failed' // Extract JID from stack trace or message - const jidMatch = (msg + String(args[1] ?? '')).match(/(\d{10,}(?:_\d+\.\d+)?)/); + const jidMatch = (msg + String(args[1] ?? '')).match(/(\d{10,}(?:_\d+\.\d+)?)/) const jid = jidMatch ? jidMatch[1] : null const maskedJid = jid && jid.length > 8 ? `${jid.substring(0, 4)}****${jid.substring(jid.length - 4)}` : jid @@ -45,8 +44,8 @@ console.error = function(...args: unknown[]) { ? `${errorType} | JID: ${maskedJid}` : errorType - // Deduplication key: type + JID (prevents duplicate logs for same error type on same contact) - const dedupeKey = `${errorType}:${maskedJid || 'unknown'}` + // Deduplication key: type + ORIGINAL JID (use unmasked to prevent collisions) + const dedupeKey = `${errorType}:${jid || 'unknown'}` const now = Date.now() const lastTime = _errorTimestamps.get(dedupeKey)