From 6ca7016fd5f8f38dd956a0d774564d88becd2d4e Mon Sep 17 00:00:00 2001 From: Rafael Silverio Date: Wed, 2 Dec 2026 17:53:09 -0300 Subject: [PATCH 1/2] build: raise Node heap ceiling for Heroku build only The runtime config var NODE_OPTIONS=--max-old-space-size=384 (set to contain R14 on the 512MB dyno) leaks into the Heroku Node buildpack build phase, capping tsc+tsup at 384MB and causing a JS heap OOM. Override NODE_OPTIONS inline in the build script so the build gets 2048MB; start:prod keeps the inherited 384MB ceiling at runtime. Co-Authored-By: Claude Opus 4.8 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index aca237c13b..4a850302fd 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "type": "commonjs", "scripts": { "prebuild": "npm run db:generate", - "build": "tsc --noEmit && tsup", + "build": "NODE_OPTIONS=--max-old-space-size=2048 tsc --noEmit && NODE_OPTIONS=--max-old-space-size=2048 tsup", "start": "tsx ./src/main.ts", "start:prod": "node dist/main", "dev:server": "tsx watch ./src/main.ts", From ec4efc1127017b3abf6bd8359dd27990be73ca55 Mon Sep 17 00:00:00 2001 From: Rafael Silverio Date: Wed, 2 Dec 2026 23:38:09 -0300 Subject: [PATCH 2/2] fix: unwrap disappearing messages, stop empty getMessage retries, mask fetchInstances token Three contained, verified fixes for open upstream issues that affect the Radar de Ingressos (inbound reading) and SafetySwap (outbound delivery), all on the live messages.upsert / fetch path, with src diverging from upstream. - #2773: unwrap ephemeralMessage / viewOnce envelopes before content handling. Baileys delivers disappearing/view-once messages with the real content nested; Evolution never called normalizeMessageContent on the live path, so getContentType() reported `ephemeralMessage`, the text->conversation flattening and isMedia checks never fired, and the message was stored/webhooked with its text buried. Any offer sent in a chat with disappearing messages on was invisible to the radar. - #2705: getMessage() returned { conversation: '' } on a DB miss. Baileys treats any truthy return as "found" and relays the empty envelope to satisfy a retry, burning one attempt and leaving the recipient stuck on "Waiting for this message" forever. Return undefined instead so Baileys falls through to its resend path. (full=true already returned undefined.) - #2677: fetchInstances returned the instance `token` (auth hash) unconditionally; AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES was only ever applied to the webhook apiKey field, never this HTTP response. Mask the token when the flag is false. Real exposure on a shared multi-instance server. Validated with tsc --noEmit, eslint and npm run build. Baileys-coupled paths (#2773, #2705) still want a live smoke test on a real instance. Co-Authored-By: Claude Opus 4.8 --- .../whatsapp/whatsapp.baileys.service.ts | 35 ++++++++++++++++++- src/api/services/monitor.service.ts | 12 ++++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index 267832fb0d..8710811908 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -539,6 +539,17 @@ export class BaileysStartupService extends ChannelStartupService { if (full) { return webMessageInfo[0]; } + + // Row not found: return undefined, never a truthy empty envelope. Baileys' + // getMessage treats ANY truthy return as "message found" and relays it to + // satisfy a retry request — an empty { conversation: '' } burns one of the + // retry attempts and leaves the recipient stuck on "Waiting for this + // message" forever (issue #2705). undefined lets Baileys fall through to + // its placeholder/resend path instead. + if (!webMessageInfo[0]) { + return undefined; + } + if (webMessageInfo[0].message?.pollCreationMessage) { const messageSecretBase64 = webMessageInfo[0].message?.messageContextInfo?.messageSecret; @@ -556,7 +567,8 @@ export class BaileysStartupService extends ChannelStartupService { return webMessageInfo[0].message; } catch { - return { conversation: '' }; + // See above: undefined (not an empty envelope) on any lookup failure. + return undefined; } } @@ -1301,6 +1313,27 @@ export class BaileysStartupService extends ChannelStartupService { continue; } + // Unwrap disappearing-message / view-once envelopes BEFORE any content + // handling (issue #2773). Baileys delivers these messages with the real + // content nested under `ephemeralMessage.message` / `viewOnceMessage.message`; + // it only unwraps on demand via normalizeMessageContent, which Evolution + // never calls on the live path. Left wrapped, getContentType() reports + // `ephemeralMessage`, the extendedTextMessage->conversation flattening and + // the isMedia checks below never fire, and the message reaches webhooks and + // the database with its text/media buried — so every offer sent in a chat + // with disappearing messages on is effectively invisible to consumers. + // Note: `editedMessage` is handled above and already skipped by the guard, + // so it is intentionally NOT unwrapped here. + for (let i = 0; i < 5 && received.message; i++) { + const inner = + received.message.ephemeralMessage || + received.message.viewOnceMessage || + received.message.viewOnceMessageV2 || + received.message.viewOnceMessageV2Extension; + if (!inner?.message) break; + received.message = inner.message; + } + if (Long.isLong(received.messageTimestamp)) { received.messageTimestamp = received.messageTimestamp?.toNumber(); } diff --git a/src/api/services/monitor.service.ts b/src/api/services/monitor.service.ts index 438530b57e..3c96d13d27 100644 --- a/src/api/services/monitor.service.ts +++ b/src/api/services/monitor.service.ts @@ -3,7 +3,7 @@ import { ProviderFiles } from '@api/provider/sessions'; import { PrismaRepository } from '@api/repository/repository.service'; import { channelController } from '@api/server.module'; import { Events, Integration } from '@api/types/wa.types'; -import { CacheConf, Chatwoot, ConfigService, Database, DelInstance, ProviderSession } from '@config/env.config'; +import { Auth, CacheConf, Chatwoot, ConfigService, Database, DelInstance, ProviderSession } from '@config/env.config'; import { Logger } from '@config/logger.config'; import { INSTANCE_DIR, STORE_DIR } from '@config/path.config'; import { NotFoundException } from '@exceptions'; @@ -126,6 +126,16 @@ export class WAMonitoringService { }, }); + // The `token` column holds the instance's auth hash (its apikey). With + // AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES=false it must not leak through + // fetchInstances (issue #2677): the flag was only ever applied to the webhook + // `apiKey` field, never to this HTTP response, so the full token was returned + // unconditionally — a real exposure on a server that hosts several instances. + const expose = this.configService.get('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES; + if (!expose) { + return instances.map((instance) => ({ ...instance, token: null })); + } + return instances; }