From a37ae16f5173908912b24169030e085706fcaec0 Mon Sep 17 00:00:00 2001 From: Gustavo Gonzaga Date: Mon, 21 Sep 2026 13:30:12 -0300 Subject: [PATCH 1/2] fix: guard undefined request.body in group route validators Under Express 5 a GET request without a "Content-Type: application/json" header reaches the handler with request.body === undefined, because express.json() only populates the body for JSON requests. groupValidate, inviteCodeValidate and getParticipantsValidate then passed that undefined value into Object.assign, which threw "Cannot convert undefined or null to object" and surfaced as an HTTP 500 on /group/findGroup, /group/inviteCode and /group/participants. Default the body to an empty object in the three validators so the request falls through to normal schema validation instead of crashing. --- src/api/abstract/abstract.router.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/api/abstract/abstract.router.ts b/src/api/abstract/abstract.router.ts index 3ff633d58b..cf81d2ae6a 100644 --- a/src/api/abstract/abstract.router.ts +++ b/src/api/abstract/abstract.router.ts @@ -110,7 +110,9 @@ export abstract class RouterBroker { const { request, ClassRef, schema, execute } = args; const instance = request.params as unknown as InstanceDto; - const body = request.body; + // A GET without "Content-Type: application/json" arrives with request.body undefined, + // because express.json() only populates the body on JSON requests. + const body = request.body ?? {}; let groupJid = body?.groupJid; @@ -169,7 +171,8 @@ export abstract class RouterBroker { } const instance = request.params as unknown as InstanceDto; - const body = request.body; + // A GET without "Content-Type: application/json" arrives with request.body undefined. + const body = request.body ?? {}; const ref = new ClassRef(); @@ -208,7 +211,8 @@ export abstract class RouterBroker { } const instance = request.params as unknown as InstanceDto; - const body = request.body; + // A GET without "Content-Type: application/json" arrives with request.body undefined. + const body = request.body ?? {}; const ref = new ClassRef(); From 6b0d3d47e7edecb04253d1bcf6752fa42adfe815 Mon Sep 17 00:00:00 2001 From: Gustavo Gonzaga Date: Mon, 21 Sep 2026 13:30:32 -0300 Subject: [PATCH 2/2] fix: guard undefined participants and group list in findGroup/fetchAllGroups Two paths in the Baileys service assumed objects that can legitimately be undefined at runtime: - group.participants is not always present in the payload returned by Baileys, so group.participants.length threw a TypeError. - groupFetchAllParticipating() can resolve to undefined/null when the Baileys store is not synced yet, typically right after a reconnection. Passing that straight into Object.values() threw "Cannot convert undefined or null to object". Both surfaced as an HTTP 500 on /group/fetchAllGroups and /group/findGroup. Fall back to an empty array/zero for missing participants, only call Object.values() when the group map resolved, and skip empty entries in the iteration. --- .../channel/whatsapp/whatsapp.baileys.service.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index 22839fd451..5a0725ccd0 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -4920,14 +4920,14 @@ export class BaileysStartupService extends ChannelStartupService { subjectOwner: group.subjectOwner, subjectTime: group.subjectTime, pictureUrl: picture.profilePictureUrl, - size: group.participants.length, + size: group.participants?.length ?? 0, creation: group.creation, owner: group.owner, desc: group.desc, descId: group.descId, restrict: group.restrict, announce: group.announce, - participants: group.participants, + participants: group.participants ?? [], isCommunity: group.isCommunity, isCommunityAnnounce: group.isCommunityAnnounce, linkedParent: group.linkedParent, @@ -4941,10 +4941,16 @@ export class BaileysStartupService extends ChannelStartupService { } public async fetchAllGroups(getParticipants: GetParticipant) { - const fetch = Object.values(await this?.client?.groupFetchAllParticipating()); + // groupFetchAllParticipating() can resolve to undefined/null (for example when the Baileys + // store is not synced yet right after a reconnection), which made Object.values throw + // "Cannot convert undefined or null to object". + const allGroups = await this?.client?.groupFetchAllParticipating(); + const fetch = allGroups ? Object.values(allGroups) : []; let groups = []; for (const group of fetch) { + if (!group) continue; + const picture = await this.profilePicture(group.id); const result = { @@ -4953,7 +4959,7 @@ export class BaileysStartupService extends ChannelStartupService { subjectOwner: group.subjectOwner, subjectTime: group.subjectTime, pictureUrl: picture?.profilePictureUrl, - size: group.participants.length, + size: group.participants?.length ?? 0, creation: group.creation, owner: group.owner, desc: group.desc, @@ -4966,7 +4972,7 @@ export class BaileysStartupService extends ChannelStartupService { }; if (getParticipants.getParticipants == 'true') { - result['participants'] = group.participants; + result['participants'] = group.participants ?? []; } groups = [...groups, result];