Version: CodeChat 1.3.6 · Baileys 7.0.0-rc.9, also reproduced on rc13 and rc14
What happens
POST /chat/mediaData/{instance}?binary=true never completes for messages the instance itself sent (keyFromMe: true). The client receives a partial body and then the connection just hangs until it times out on its own — no error, no EOF.
Two separate problems are stacked here:
1. Decryption fails
Error: error:1C800064:Provider routines::bad decrypt
at Decipheriv.final (node:internal/crypto/cipher:193:29)
at Transform.final [as _final] (.../@whiskeysockets/baileys/lib/Utils/messages-media.js:486:31)
reason: 'bad decrypt',
code: 'ERR_OSSL_BAD_DECRYPT'
2. The error handler crashes instead of closing the response
ERROR [uncaughtException]
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at ServerResponse.json (.../express/lib/response.js:252:15)
at Transform.<anonymous> (.../dist/src/whatsapp/routers/chat.router.js:151:79)
Streaming has already begun when decryption fails, so res.json(...) throws and the response is never terminated.
The media itself is fine
Downloading the encrypted file directly from the url in the message payload returns it complete and intact:
HTTP=200 bytes=77402 time=0.14s
That matches exactly what is expected: fileLength 77381 → 77392 (padded to the 16-byte AES block) + 10 byte MAC = 77402. So this is neither a network nor a CDN problem.
Consistent with that, the bytes that do reach the client stop at 77376 — precisely the largest 16-byte boundary below 77381, i.e. everything decrypts except the final block.
Incoming media (keyFromMe: false) on the same instance downloads and decrypts without any issue.
Reproduce
- Send an image through
POST /message/sendMedia/{instance}
- Wait for the
messages.upsert webhook and take the numeric id
POST /chat/mediaData/{instance}?binary=true with that message's keyId
- The request hangs; the log shows both errors above
Suggested fixes
- Terminate the response when it has already started. Guarding on
res.headersSent and destroying/ending the stream instead of calling res.json() would at least turn this into a fast failure rather than a hang, and would stop the uncaught exception. This alone is worth fixing on its own, since any error mid-stream currently leaves the connection open.
- Investigate why the stored
mediaKey for self-sent messages fails to decrypt, while the same instance decrypts received media correctly.
Version: CodeChat 1.3.6 · Baileys
7.0.0-rc.9, also reproduced onrc13andrc14What happens
POST /chat/mediaData/{instance}?binary=truenever completes for messages the instance itself sent (keyFromMe: true). The client receives a partial body and then the connection just hangs until it times out on its own — no error, no EOF.Two separate problems are stacked here:
1. Decryption fails
2. The error handler crashes instead of closing the response
Streaming has already begun when decryption fails, so
res.json(...)throws and the response is never terminated.The media itself is fine
Downloading the encrypted file directly from the
urlin the message payload returns it complete and intact:That matches exactly what is expected:
fileLength77381 → 77392 (padded to the 16-byte AES block) + 10 byte MAC = 77402. So this is neither a network nor a CDN problem.Consistent with that, the bytes that do reach the client stop at 77376 — precisely the largest 16-byte boundary below 77381, i.e. everything decrypts except the final block.
Incoming media (
keyFromMe: false) on the same instance downloads and decrypts without any issue.Reproduce
POST /message/sendMedia/{instance}messages.upsertwebhook and take the numericidPOST /chat/mediaData/{instance}?binary=truewith that message'skeyIdSuggested fixes
res.headersSentand destroying/ending the stream instead of callingres.json()would at least turn this into a fast failure rather than a hang, and would stop the uncaught exception. This alone is worth fixing on its own, since any error mid-stream currently leaves the connection open.mediaKeyfor self-sent messages fails to decrypt, while the same instance decrypts received media correctly.