Skip to content

[BUG] "Bad MAC" Error When Receiving Private Message #1734

Description

@vllre

Describe the bug
When receiving a private message, a Bad MAC error occurs and the message cannot be decrypted.
The issue happens consistently across multiple attempts, even after resetting the session.

Error Logs:

Failed to decrypt message with any known session...
Session error: Error: Bad MAC
    at Object.verifyMAC (/root/wa/node_modules/libsignal/src/crypto.js:87:15)
    at SessionCipher.doDecryptWhisperMessage (/root/wa/node_modules/libsignal/src/session_cipher.js:250:16)
    at async SessionCipher.decryptWithSessions (/root/wa/node_modules/libsignal/src/session_cipher.js:147:29)
    at async 6957863858248.0 [as awaitable] (/root/wa/node_modules/libsignal/src/session_cipher.js:171:28)
    at async _asyncQueueExecutor (/root/wa/node_modules/libsignal/src/queue_job.js:20:29)
Closing open session in favor of incoming prekey bundle

Session Details (Closed Sessions)

SessionEntry {
  _chains: {
    'Bb1tY0m5e2qpgJLbbts+wRP2dU+kE5MdUQXEA1Cgmhs0': { chainKey: [Object], chainType: 2, messageKeys: {} },
    'BQ90/dMFGWtPZ4tCsQHRBTFfgLSNmZ0U/XQxXgKFYk9r': { chainKey: [Object], chainType: 1, messageKeys: {} }
  },
  registrationId: 1241753327,
  currentRatchet: {
    ephemeralKeyPair: { pubKey: <Buffer ...>, privKey: <Buffer ...> },
    lastRemoteEphemeralKey: <Buffer ...>,
    previousCounter: 0,
    rootKey: <Buffer ...>
  },
  indexInfo: {
    baseKey: <Buffer ...>,
    baseKeyType: 2,
    closed: -1,
    used: 1756892690842,
    created: 1756892690842,
    remoteIdentityKey: <Buffer ...>
  }
}

To Reproduce
Steps to reproduce the behavior:

  1. Receive a private message from another user.
  2. Let the session attempt to decrypt the incoming message.
  3. The Bad MAC error appears in the logs.
  4. Reset the session (delete old session state and reinitialize).
  5. Try again — the error still occurs.

Expected behavior
Incoming messages should be decrypted successfully without throwing a Bad MAC error.

Environment:

  • "@whiskeysockets/baileys": "^6.7.19",

Additional context

  • The error often occurs when the local session state is not synchronized with the sender’s prekey bundle.
  • Possible cause: the prekey bundle does not match the remote identity key, even after resetting the session.
  • Already tried resetting the session, but the error still persists.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions