79580651

Date: 2025-04-18 08:14:04
Score: 0.5
Natty:
Report link

I had the exact same issue. After a deep investigation and debugging I managed to fix it.

The issue is because your object contains some special chars, so also payloads with emojis were failing (unicode). I'm using NestJS and first tried to do all kinds of stuff with Buffer, different stringify packages, even checked byte-by-byte comparison. Everything failed, except normal text messages.

So my solution was (at least in NestJS), to make sure you have the raw body. In my case, I add it to the request via the main.ts:

    import { json } from "body-parser"; // make sure to install this

    app.use(
        json({
            verify: (req, res, buf) => {
                req.rawBody = buf.toString("utf8"); // Store raw body for signature verification
            },
        })
    );

Then you can get the raw body from the request with the @Req decorator in the controller:

@Req() req: Request & { rawBody: string }

In the end, create the expected signature and compare it to the Meta signature:

const expectedSignature = `sha256=${crypto
    .createHmac("sha256", this.metaCfg.metaAppSecret)
    .update(rawBody)
    .digest("hex")}`;

// ...compare with Meta signature
Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @Req
  • Low reputation (1):
Posted by: Kennix